Thx for this post, sometimes it’s easier to find a certain chapter in the docs by searching in the forum ![]()
And while the logging chapter explains how to customize logging via console and where to find the logging configuration file log4j2.xml, it’s a bit sparse on how to actually customize the config file.
I would like to add some examples on how to filter events similar to this post for openhab2:
############ CUSTOM FILTERS START HERE #################
log4j2.appender.out.filter.jettyWarn.type = RegexFilter
log4j2.appender.out.filter.jettyWarn.regex = .*(URI is too large >8192|while writing a response message entity to the container output stream|Unable to connect Netatmo API).*
log4j2.appender.out.filter.jettyWarn.onMatch = DENY
log4j2.appender.out.filter.jettyWarn.onMisMatch = NEUTRAL
log4j2.appender.event.filter.declutter.type = RegexFilter
log4j2.appender.event.filter.declutter.regex = .* changed .*
log4j2.appender.event.filter.declutter.onMatch = DENY
log4j2.appender.event.filter.declutter.onMismatch = NEUTRAL
################# END OF CUSTOM FILTERS ################
I already managed to suppress Item changed log entries (lower than ERROR) by adding the following in log4j2.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Configuration monitorInterval="10">
[...]
<Loggers>
[...]
<!-- CUSTOM LOGGERS START HERE -->
<!-- -->
<!-- Suppress *Item changed* entries -->
<Logger level="ERROR" name="openhab.event.ItemStateChangedEvent"/>
<Logger level="ERROR" name="openhab.event.GroupItemStateChangedEvent"/>
<!-- -->
<!-- CUSTOM LOGGERS END HERE -->
</Loggers>
</Configuration>
But how would I filter for custom strings? How would I suppress, for example, entries containing Unable to connect Netatmo API?
Pretty sure it would be by appending a filter to the correct logger (ThingStatusInfoChangedEvent?), but how is the syntax for that?
And since we are talking syntax / examples - the documentations also mentions Redirect the log to a text file - how is the syntax for that? Would the following write all events related to BindingX into a file called bindingX.log?
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Configuration monitorInterval="10">
<Appenders>
[...]
<!-- Rolling file appender -->
<RollingFile fileName="${sys:openhab.logdir}/bindingX.log" filePattern="${sys:openhab.logdir}/bindingX.log.%i" name="BINDINGX">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
<Policies>
<OnStartupTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="8 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
[...]
<Logger additivity="false" level="INFO" name="org.openhab.binding.x">
<AppenderRef ref="BINDINGX"/>
<AppenderRef ref="OSGI"/>
</Logger>
</Loggers>
</Configuration>
@rlkoshak do you know the correct syntax / do you know where to find more information?