maricn / logback-slack-appender Goto Github PK
View Code? Open in Web Editor NEWLogback appender for Slack messenger
License: Other
Logback appender for Slack messenger
License: Other
Slack allows easy integration via webhooks, it would be convenient if logback-slack-appender
could be configured by simply providing a webhook URL rather than generating tokens and providing explicit username and channel configuration.
Hi,
I'm trying to get the appender to work without success. Any help would be greatly appreciated.
I'm currently running version 1.3.0.
This is my logback.xml
:
<configuration debug="true">
<appender name="SLACK" class="com.github.maricn.logback.SlackAppender">
<!-- Slack API token -->
<token>REMOVED</token>
<!-- Channel that you want to post - default is #general -->
<channel>#general</channel>
<!-- Formatting (you can use Slack formatting - URL links, code formatting, etc.) -->
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
</layout>
<!-- Username of the messages sender -->
<username>bot</username>
<!-- Emoji to be used for messages -->
<iconEmoji>:stuck_out_tongue_winking_eye:</iconEmoji>
</appender>
<!-- Currently recommended way of using Slack appender -->
<appender name="ASYNC_SLACK" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="SLACK" />
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ASYNC_SLACK" />
</root>
</configuration>
When I run I see:
11:13:35,228 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
11:13:35,228 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
11:13:35,229 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/ubuntu/logback/logback.xml]
11:13:35,441 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.github.maricn.logback.SlackAppender]
11:13:35,444 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [SLACK]
11:13:35,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
11:13:35,569 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ASYNC_SLACK]
11:13:35,569 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [SLACK] to ch.qos.logback.classic.AsyncAppender[ASYNC_SLACK]
11:13:35,569 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC_SLACK] - Attaching appender named [SLACK] to AsyncAppender.
11:13:35,587 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC_SLACK] - Setting discardingThreshold to 51
11:13:35,588 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to ALL
11:13:35,588 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ASYNC_SLACK] to Logger[ROOT]
11:13:35,588 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:13:35,592 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@38cccef - Registering current configuration as safe fallback point
However, I don't see anything in slack. I have verified there's output by changing to a different appender type.
Any help would be greatly appreciated :)
Following the example given, everything works but I get an error on colorCoding in Logback's setup:
-ERROR in ch.qos.logback.core.joran.spi.Interpreter@46:18 - no applicable action for [colorCoding], current ElementPath is [[configuration][appender][colorCoding]]
This makes colorCoding stay set to false and I don't get that red color for errors.
if using JDK 16 or JDK 17, the release will fail with the current nexus-staging-maven-plugin
.. known bug: https://issues.sonatype.org/browse/OSSRH-66257
workaround (from https://stackoverflow.com/questions/70153962/nexus-staging-maven-plugin-maven-deploy-failed-an-api-incompatibility-was-enco):
export MAVEN_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED"
the other workaround to force the plugin to use the xtream
dependency causes problems because there are vulnerabilities in the old versions, and the newer versions fail on another error..
export MAVEN_OPTS
)Dependabot upgraded the jackson-databind version several times in this project due to high / critical CVE issues in de-serialization.
Even when this appender does not use the unmarshaller methods scoped by the CVEs, it might be possible that applications using this appender will automatically pick up Jackson for marshalling.
Therefore I think it is a good idea to release a new version of the appender with the upgraded Jackson dependencies.
I am using the log4j logger in my Java application. Will this package works with that in 2023?
The webhook functionality incorporated in recent commits is very useful, and I have several production apps I'm eager to use it in. Can you please publish the newest release to Maven Central?
Thanks!
It seems that the messages I'm logging some times show up in Slack out of order. Is this a problem you've seen before?
My logback config looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="slackAppender" class="com.github.maricn.logback.SlackAppender">
<token>xxxx-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx</token>
<channel>#xxxxxxxx</channel>
<username>${HOSTNAME}</username>
</appender>
<appender name="asyncSlackAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="slackAppender" />
</appender>
<logger name="slackLogger">
<appender-ref ref="asyncSlackAppender" />
</logger>
<root>
<level value="ALL" />
<appender-ref ref="slackLogger" />
</root>
</configuration>
When you post messages to the Slack by webhook URL, channel name is not needed. Webhook URL is created for specific channel, so there is no need for channel name.
If you set correct channel name, it will work, but if you set different channel, it won't work.
There is no need to set channel name in this case, so use channel name only when token is used.
I am getting this issue, however the dependency is present in pom.xml.
Caused by: java.lang.ClassNotFoundException: com.github.maricn.logback.SlackAppender
Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@8:15 - no applicable action for [webhookUri], current ElementPath is [[configuration][appender][webhookUri]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:152)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:195)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:289)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:262)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:231)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:207)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:335)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
at employee.EmployeeBoot.main(EmployeeBoot.java:26)
It would be great if proxy settings could be provided to the appender.
e.g. an complete Proxy object which would be used in the openConnection
method
Slack allows only 1 msg. per second per channel (Rate-Limits).
The Appender should buffer messages and send them by a max rate of 1 per second.
If the buffer grows over a defined limit, it may discard messages until the buffer size is below the threshold.
Slack sends HTTP status 429 when rate-limiting occurs. This includes a time when the next call can be made. This should also been taken into account.
There is a risk to get permanently banned. "Continuing to send messages after exceeding a rate limit runs the risk of your app being permanently disabled."
Hi @maricn
We have built our own Slack Appender for Logback. It has reasonable test coverage and definitely works in 2023 and 2024.
As we use it for our projects, we are going to maintain it for the foreseeable future.
Perhaps you may put a link to our project as an alternative to yours.
https://github.com/cyfrania/logback-slack-appender
Thank you.
Hello @maricn,
Thank you for this repository.
What is the license of this repository? I'd like to you the SlackAppender class ( only that class ).
Could you specify a license?
Thank you,
Kiru
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.