<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<dsn>http://6ec4f6d60e5b4....................</dsn>
<tags>Env:${LOG_STAGE},AppName:${APP_NAME}</tags>
<minLevel>ERROR</minLevel>
</appender>
<root level="warn">
<appender-ref ref="Sentry" />
</root>
I used "minLevel" in the above configuration and it is not able to control the logging level. In this case it is ERROR. The idea is that I want to log only ERROR's to sentry and avoid any other levels to save space.
@muddasani are you using the snapshot (git) version?
Thanks for the response.
I am using:
<dependency>
<groupId>net.kencochrane.raven</groupId>
<artifactId>raven-logback</artifactId>
<version>6.0.0</version>
</dependency>
I just used filter and it seems to work fine:
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
I did it using TresholdFilter:
appender 'SENTRY', net.kencochrane.raven.logback.SentryAppender, {
dsn = System.getProperty('SENTRY_DSN')
filter ThresholdFilter, {
level = 'ERROR'
}
}
Confirmed that minLevel doesn't work as documented.
Here is an example:
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<minLevel>ERROR</minLevel>
</appender>
<root level="debug">
<appender-ref ref="Sentry"/>
<appender-ref ref="console" />
</root>
</configuration>
Here are the debug logs:
16:37:41,240 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:37:41,240 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:37:41,240 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Users/ted/workspaces/raven-java-examples/raven-java-logback-example/target/classes/logback.xml]
16:37:41,293 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:37:41,299 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:37:41,304 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console]
16:37:41,315 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
16:37:41,336 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [net.kencochrane.raven.logback.SentryAppender]
16:37:41,338 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [Sentry]
16:37:41,340 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:15 - no applicable action for [minLevel], current ElementPath is [[configuration][appender][minLevel]]
16:37:41,340 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
16:37:41,340 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [Sentry] to Logger[ROOT]
16:37:41,341 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT]
16:37:41,341 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:37:41,341 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@6ecfc645 - Registering current configuration as safe fallback point
Specifically:
16:37:41,340 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:15 - no applicable action for [minLevel], current ElementPath is [[configuration][appender][minLevel]]
I removed this from the documentation.
This behavior is supported by logback itself with Filters -- we shouldn't need to implement it independently. I'm a little confused why this was implemented in the first place, when it seems like this can be implemented on a per-appender basis using a ThresholdFilter (see @jirutka's example, or the logback documentation), and at a quick glance I can't really find any other appenders that short-circuit the rest of the logging infrastructure like this. (If you're reading this and have contrary examples, please correct me if I'm wrong!)
Barring any reasonable arguments otherwise, using setMinLevel should be considered deprecated and will probably be removed outright (or at least defaulted back to null) in the near future, since this behavior doesn't seem to be consistent with other appenders.
Most helpful comment
I did it using
TresholdFilter: