logslack


License

License

GroupId

GroupId

io.methvin
ArtifactId

ArtifactId

logslack_2.12
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

logslack
logslack
Project URL

Project URL

https://github.com/gmethvin/logslack
Project Organization

Project Organization

Greg Methvin
Source Code Management

Source Code Management

https://github.com/gmethvin/logslack

Download logslack_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.methvin/logslack_2.12/ -->
<dependency>
    <groupId>io.methvin</groupId>
    <artifactId>logslack_2.12</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.methvin/logslack_2.12/
implementation 'io.methvin:logslack_2.12:0.0.3'
// https://jarcasting.com/artifacts/io.methvin/logslack_2.12/
implementation ("io.methvin:logslack_2.12:0.0.3")
'io.methvin:logslack_2.12:jar:0.0.3'
<dependency org="io.methvin" name="logslack_2.12" rev="0.0.3">
  <artifact name="logslack_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.methvin', module='logslack_2.12', version='0.0.3')
)
libraryDependencies += "io.methvin" % "logslack_2.12" % "0.0.3"
[io.methvin/logslack_2.12 "0.0.3"]

Dependencies

compile (7)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.6
com.typesafe.akka : akka-http-core_2.12 jar 10.1.3
com.typesafe.akka : akka-http-spray-json_2.12 jar 10.1.3
com.typesafe.akka : akka-actor_2.12 jar 2.5.13
com.typesafe.akka : akka-stream_2.12 jar 2.5.13
io.spray : spray-json_2.12 jar 1.3.3
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

Logslack: Logback appender for Slack

Travis CI Maven

Logslack is a Logback appender that posts log messages to Slack. Since you generally don't want to send all logs to Slack, it allows selectively directing log messages to Slack channels by passing a Marker.

The library is written in Scala, using an Akka HTTP client to make requests asynchronously to the Slack API.

Dependency

In sbt:

libraryDependencies += "io.methvin" %% "logslack" % logslackVersion

In maven:

<dependency>
    <groupId>io.methvin</groupId>
    <artifactId>logslack_2.12</artifactId>
    <version>${logslackVersion}</version>
</dependency>

Replace the logslackVersion with the version (Maven).

Configuration

To enable, add the appender to your logback.xml, providing at least a token:

<configuration>
  <appender name="SLACK" class="io.methvin.logback.SlackAppender">
    <!-- The app's slack API token. This must have at least the "chat.write.bot" permission. -->
    <token>YOUR_SLACK_TOKEN</token>

    <!-- If you set the channel option, ALL logs will go to this channel. -->
    <!-- <channel>#application-logs</channel> -->

    <!-- The emoji to use as the icon for this message (must start and end in a colon) -->
    <!-- <iconEmoji>:shrug:</iconEmoji> -->

    <!-- The bot's username. -->
    <!-- <username>logger</username> -->

    <!-- Whether Slack should use markdown to process the log messages. Defaults to true. -->
    <!-- <useMarkdown>false</useMarkdown> -->

    <!-- Only log above a certain threshold to slack -->
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
       <level>WARN</level>
    </filter>

    <!-- Formatting -->
    <layout class="ch.qos.logback.classic.PatternLayout">
      <pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
    </layout>
  </appender>

  <root level="INFO">
    <appender-ref ref="SLACK" />
  </root>
</configuration>

Usage

With the above configuration, logslack will not post to any slack channels by default. You can create a SLF4J Marker to tag a log message for a specific channel. For example:

object SlackMarkers {
  final val GeneralAlerts = MarkerFactory.getMarker("#general-alerts")
}

The name of the marker should be the same as the channel you wish to post to.

Then specify the marker when logging:

// for a standard SLF4J logger:
logger.info(SlackMarkers.GeneralAlerts, "Something happened!")

// for Play logger:
logger.info("Something happened!")(SlackMarkers.GeneralAlerts)

To log all messages in some channel, set the channel option in the configuration, described in the configuration section above.

Versions

Version
0.0.3
0.0.2
0.0.1