Can I disable an appender in logback on the xml config? I have my configuration and I want to put two appenders, one for database and other for text logs, but only one must be activated. thanks!
The Logback architecture is comprised of three classes: Logger, Appender, and Layout. A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations. A Logger can have more than one Appender.
Logback does not allow logging to be disabled from the command line. However, if the configuration file allows it, you can set the level of loggers on the command line via a Java system property.
AsyncAppender. Logs the log events asynchronously. It acts solely as an event dispatcher and must reference another appender. AsyncAppender acts as a dispatcher to another appender.
Note that logback-classic transitively includes the slf4j-api and logback-core , so only having the logback-classic is enough to setup logback with slf4j. When using Logback with SLF4j, a console appender with DEBUG log level is configured automatically.
Not sure why you want to deactivate an appender, what are you trying to achieve by disabling.
There are some ways to achieve it
<configuration>
<appender name="stdoutappender" />
<appender name="dbappender" />
<logger name="stdoutlogger" level="DEBUG">
<appender-ref ref="stdoutappender" />
</logger>
<logger name="dblogger" level="OFF">
<appender-ref ref="dbappender" />
</logger>
</configuration>
In this case also you have to reload the configuration when you modify logback configuration (logback.xml)
On top of above 3 options you can create logback configurations progamatically
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With