Logback's DBAppender logs all properties in its context and MDC to the database. I would like to control which properties are logged, specifically filtering out certain values, but I can't find any options to do so. The documentation is terse:
The logging_event_property is used to store the keys and values contained in the MDC or the Context
Is it possible to exclude certain properties from being logged?
Here is an example:
Logback is configured with a DBAppender
that loads its properties from vct.properties
:
<configuration>
<property resource="vct.properties" />
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClass>com.mysql.jdbc.Driver</driverClass>
<jdbcUrl>jdbc:mysql://${log.db.host}:${log.db.port}/${log.db.schema}</jdbcUrl>
<user>${log.db.username}</user>
<password>${log.db.password}</password>
</dataSource>
</connectionSource>
</appender>
<root level="DEBUG">
<appender-ref ref="DB" />
</root>
</configuration>
vct.properties
has the connection settings:
log.db.host=localhost
log.db.port=3306
log.db.schema=logs_development
log.db.username=loguser
log.db.password=logpass
When an event is logged, all of the connection settings are logged:
mysql> select * from logging_event_property where event_id=1;
+----------+---------------------+-------------------------------------------+
| event_id | mapped_key | mapped_value |
+----------+---------------------+-------------------------------------------+
| 1 | log.db.host | localhost |
| 1 | log.db.password | logpass |
| 1 | log.db.port | 3306 |
| 1 | log.db.schema | logs_development |
| 1 | log.db.username | loguser |
+----------+---------------------+-------------------------------------------+
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.
Logback is a logging framework for Java applications, created as a successor to the popular log4j project. In fact, both of these frameworks were created by the same developer.
Appenders are named entities. This ensures that they can be referenced by name, a quality confirmed to be instrumental in configuration scripts. The Appender interface extends the FilterAttachable interface. It follows that one or more filters can be attached to an appender instance.
Logback does not currently support this feature. If you haven't already please enter a bug report requesting this feature.
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