All Projects → dwango → slack-webhook-appender

dwango / slack-webhook-appender

Licence: MIT license
Logback appender which posts logs to slack via incoming webhook.

Programming Languages

java
68154 projects - #9 most used programming language
scala
5932 projects

Projects that are alternatives of or similar to slack-webhook-appender

herald
Log annotation for logging frameworks
Stars: ✭ 71 (+343.75%)
Mutual labels:  slf4j, logback
Terse Logback
Structured Logging, Tracing, and Observability with Logback
Stars: ✭ 146 (+812.5%)
Mutual labels:  slf4j, logback
Logstash Logback Encoder
Logback JSON encoder and appenders
Stars: ✭ 1,987 (+12318.75%)
Mutual labels:  logback, logback-appender
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (+1050%)
Mutual labels:  slf4j, logback
echopraxia
Java Logging API with clean and simple structured logging and conditional & contextual features. JSON implementations in Logback and Log4J.
Stars: ✭ 37 (+131.25%)
Mutual labels:  slf4j, logback
logunit
A Java library for unit-testing logging.
Stars: ✭ 40 (+150%)
Mutual labels:  slf4j, logback
liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (+162.5%)
Mutual labels:  slf4j, logback
Scala Logging
Convenient and performant logging library for Scala wrapping SLF4J.
Stars: ✭ 804 (+4925%)
Mutual labels:  slf4j, logback
Sofa Common Tools
sofa-common-tools is a library that provide some utility functions to other SOFA libraries.
Stars: ✭ 141 (+781.25%)
Mutual labels:  slf4j, logback
jlib-awslambda-logback
jlib AWS Lambda SLF4J/Logback Appender
Stars: ✭ 16 (+0%)
Mutual labels:  slf4j, logback-appender
Scribe
The fastest logging library in the world. Built from scratch in Scala and programmatically configurable.
Stars: ✭ 304 (+1800%)
Mutual labels:  slf4j, logback
logback-gelf-appender
Logback appender that sends GELF messages
Stars: ✭ 38 (+137.5%)
Mutual labels:  logback, logback-appender
Timbre
Pure Clojure/Script logging library
Stars: ✭ 1,253 (+7731.25%)
Mutual labels:  slf4j
slf4j-timber
SLF4J binding for Timber - a logger with a small, extensible API which provides utility on top of Android's normal Log class.
Stars: ✭ 20 (+25%)
Mutual labels:  slf4j
Kotlin Inline Logger
A logger facilitating lazily-evaluated log calls via Kotlin's inline classes & functions.
Stars: ✭ 77 (+381.25%)
Mutual labels:  slf4j
logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+856.25%)
Mutual labels:  logback
Slf4j Timbre
SLF4J binding for Clojure's Timbre
Stars: ✭ 64 (+300%)
Mutual labels:  slf4j
Slogging
A Typesafe-logging (and slf4j) compatible logging library based on macros for Scala/JVM, Scala.js, and Scala Native
Stars: ✭ 44 (+175%)
Mutual labels:  slf4j
springboot-tutorials
codehome出品SpringBoot2.x基础教程
Stars: ✭ 77 (+381.25%)
Mutual labels:  logback
Testlogcollectors
A framework for capturing log statements during tests. Compatible with most popular logging frameworks. Works with JUnit and TestNG
Stars: ✭ 31 (+93.75%)
Mutual labels:  slf4j

slack-webhook-appender

Logback appender which posts logs to slack via incoming webhook.

Build Status

Usage

pom.xml

    <repositories>
        <repository>
            <id>slack-webhook-appender</id>
            <url>https://raw.github.com/dwango/slack-webhook-appender/mvn-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>jp.co.dwango</groupId>
            <artifactId>slack-webhook-appender</artifactId>
            <version>0.2.0</version> <!-- replace with the latest version -->
        </dependency>
    </dependencies>

logback.xml

<configuration>

    <appender name="SLACK" class="jp.co.dwango.logback.SlackWebhookAppender">
        <webhookUrl>...</webhookUrl>
        <timeout>50000</timeout>
        <payload>
            {
              "channel": "#_channel",
              "username": "username",
              "icon_emoji": emoji,
              "link_names": 1,
              "attachments": [{
                "title": level + " (" + hostname + ")",
                "fallback": level + " (" + hostname + ")",
                "color": color,
                "fields": [{
                  "title": "Hostname",
                  "value": hostname,
                  "short": true
                }, {
                  "title": "Time",
                  "value": timestamp,
                  "short": true
                }, {
                  "title": "Level",
                  "value": level,
                  "short": true
                }, {
                  "title": "Trigger",
                  "value": message,
                  "short": false
                }]
              }]
            }
        </payload>
    </appender>

    <appender name="ASYNC_SLACK" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="SLACK" />
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
    </appender>

    <root level="INFO">
        <appender-ref ref="ASYNC_SLACK" />
    </root>

</configuration>

Appender options

Key Required Detail
webhookUrl Y URL of incoming webhook.
timeout N Timeout of posting to Slack in milliseconds. (Default 50,000 milliseconds)
payload Y Payload written in JavaScript to send to Slack.

Payload specification

  • Written in JavaScript
  • Available Buildin variables
Variable Name Type Description
event ILoggingEvent The representation of logging events. see API
property(name) function A function to get a property in which only context properties or system properties are accessible. For a key passed as argument, the property() methods return the String value of the property.
hostname string Hostname where the event occurred
level string Log level. eg. FATAL, ERROR, WARN, INFO, DEBUG, TRACE.
timestamp string Time when the event occurred. eg. 2018-02-21T19:00:25.827+09:00
message string The message of logging events.
color string Color according to log level.
emoji string Emoji according to log level.
Payload sample - Simple
{
  "channel": "#_channel",
  "username": "username",
  "icon_emoji": emoji,
  "link_names": 1,
  "attachments": [{
    "title": level + " (" + hostname + ")",
    "fallback": level + " (" + hostname + ")",
    "color": color,
    "fields": [{
      "title": "Hostname",
      "value": hostname,
      "short": true
    }, {
      "title": "Time",
      "value": timestamp,
      "short": true
    }, {
      "title": "Level",
      "value": level,
      "short": true
    }, {
      "title": "Trigger",
      "value": message,
      "short": false
    }]
  }]
}
Payload sample - Complex
var env = 'dev', mention = '';
if(hostname.indexOf('dev') == -1) {
  env = 'production'; mention = '@channel';
}

return {
  "channel": "#_channel",
  "username": "username",
  "icon_emoji": emoji,
  "link_names": 1,
  "attachments": [{
    "title": level + " ( " + env + " ) " + mention,
    "fallback": level + " ( " + hostname + " )",
    "color": color,
    "fields": [{
      "title": "Hostname",
      "value": hostname,
      "short": true
    }, {
      "title": "Time",
      "value": timestamp,
      "short": true
    }, {
      "title": "Level",
      "value": level,
      "short": true
    }, {
      "title": "Trigger",
      "value": message,
      "short": false
    }]
  }]
};

logback.xml (Legacy Style)

<configuration>

    <appender name="SLACK" class="jp.co.dwango.logback.SlackWebhookAppender">
        <webhookUrl>...</webhookUrl>
        <channel>...</channel>
        <username>...</username>
        <layout>
            <pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
        </layout>
    </appender>

    <appender name="ASYNC_SLACK" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="SLACK" />
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
    </appender>

    <root level="INFO">
        <appender-ref ref="ASYNC_SLACK" />
    </root>

</configuration>

Appender options

Key Required Detail
webhookUrl Y URL of incoming webhook
channel Y channel to post logs to
username Y username which post logs as
iconEmoji N icon of the user; you probably want colons like :smiley:
iconUrl N icon of the user
linkNames N (true / false) If false, you will not be notified by posing message which includes @channel, @{username} and so forth (true by default)

release

sbt release

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].