Can I prevent DBAppender from registering certain properties?

Logback DBAppender registers all properties in its context and MDC in the database. I would like to control which properties are registered, in particular, filter out certain values, but I can not find any options for this. Documentation short:

The logging_event_property function is used to store keys and values ​​contained in an MDC or Context.

Is it possible to exclude certain properties from the log?

Here is an example:

The reservation is configured using DBAppenderwhich 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 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 connection parameters 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                                   | 
+----------+---------------------+-------------------------------------------+
+3
3

. , .

+2
0

.

<springProperty ...> 

definition. When the SpringProperty scope is set to "context", it will be automatically added to the "logging_event_property" table. When you delete the scope (by default locally) SpringProperties are no longer added :-)

0
source

Source: https://habr.com/ru/post/1741335/


All Articles