Skip to content

Slack Logger is a custom log4j appender which logs directly to a Slack channel

License

Notifications You must be signed in to change notification settings

TheConnMan/SlackLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slack Logger

Download

Slack Logger is a custom log4j appender which logs directly to a Slack channel.

Slack Logger

Requirements

  • Slack account with Incoming WebHooks integration

Setup

Slack

  • Create an Incoming WebHooks integration
  • Select a channel to post messages to
    • NOTE: This can be overwritten in the config. This is helpful if multiple projects use the same webhook.
  • Add the WebHook url to the config as shown below

Dependency managment

Add this into your build.gradle:

repositories {
	maven { url "http://dl.bintray.com/theconnman/plugins" }
}
dependencies {
	compile "org.grails.plugins:slacklogger:2.0.2"
}

Config

All config items contain the prefix grails.plugin.slacklogger.

NOTE: Config items with * after them are secret information. It is highly reccommended to put this information in secret files and pull it into the Grails project at runtime.

  • webhook - The WebHook URL provided by Slack*
  • channel - The channel to post to [Optional]
  • botName - The name of the bot which the message will be posted as [Optional]
  • colors - Map of colors which log attachments will be posted with [Optional]
    • Default
       [
           INFO: '#5f9ea0',
           TRACE: '#6f6d6d',
           DEBUG: '#b5dae9',
           WARN: '#ff9122',
           ERROR: '#ff4444',
           FATAL: '#b03e3c'
       ]
      

Use

Slack Logger creates a new Logback appender which can be used like a normal appender in logback.groovy. Below is an example configuration of a new appender:

import com.theconnman.slacklogger.SlackAppender
...
appender('SLACK', SlackAppender) {
	encoder(PatternLayoutEncoder) {
		pattern = "%logger - %msg%n"
	}
}

The appender pattern above will produce messages which look like the image at the top of the readme. Removing the time and the level from the log pattern is recommended because the time and level will appear on the Slack message by default.

Development

To run the project in development clone the repository and run the following:

grails -Dgrails.SLACK_WEBHOOK=[your Slack webhook] run-app

Then go to http:/localhost:8080/test to receive a test message.

About

Slack Logger is a custom log4j appender which logs directly to a Slack channel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages