OH3: Logging to seperate files

Hi, I am trying to upgrade to OH3 and I see the logging changed. I read the documentation over on next.openhab and I see that it is pretty straightforward to use karaf to set the loglevels now… What I did in OH2 was to set up logging for different bindings in seperate files, so that my openhab.log doesn’t get cluttered up. For example:

# Set Wemo binding to TRACE tp see return msgs from switches, and put in its own file
log4j2.logger.Wemo.name = org.openhab.binding.wemo
log4j2.logger.Wemo.level = WARN
log4j2.logger.Wemo.additivity = false
log4j2.logger.Wemo.appenderRefs = Wemo
log4j2.logger.Wemo.appenderRef.Wemo.ref = WEMO

log4j2.appender.Wemo.name = WEMO
log4j2.appender.Wemo.type = RollingRandomAccessFile
log4j2.appender.Wemo.fileName = /var/log/openhab2/wemo.log
log4j2.appender.Wemo.filePattern = /var/log/openhab2/wemo.log.%i
log4j2.appender.Wemo.immediateFlush = true
log4j2.appender.Wemo.append = true
log4j2.appender.Wemo.layout.type = PatternLayout
log4j2.appender.Wemo.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.Wemo.policies.type = Policies
log4j2.appender.Wemo.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.Wemo.policies.size.size = 10MB
log4j2.appender.Wemo.strategy.type = DefaultRolloverStrategy
log4j2.appender.Wemo.strategy.max = 10

In looking at log4j2.xml, it seems that the format is different enough, that I’ll have to spend some time figuring out how to do this translation, so before doing that I wanted to ask if anyone has a simple minimal example to set up separate logging to a separate file for a binding.


1 Like