Here is my setup for the new log4j2 logging package that is included in the latest upgrade of openHAB2 snapshot (2.2.0 Build >#1009)
All changes happen in the $OPENHAB_USERDATA/etc/org.ops4j.pax.logging.cfg
file
(full path in Linux with apt installation: /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg
)
Notes
- My OH2 installation is very stable and I don’t add many new stuff so I want my logs to show me only Warnings+.
- I am running the following addons (in addons.cfg):
Plus 3 manually deployed addons:binding = knx1, zwave, mqtt1, weather1, samsungtv, astro, ntp, wol1 ui = basic, paper, habpanel, habmin persistence = mapdb, influxdb action = mail transformation = map, regex, jsonpath misc = restdocs, homekit
unifi, mpower, climacons
- If you are deploying a new OH2 system and changing your configs very often, you may want to increase logging levels (This thread is about how to decrease them)
- More info on overall log management here: [Link 1] & [Link 2]
Default Configuration
# Common pattern layout for appenders
#log4j2.pattern = %d{ISO8601} | %-5p | %-16t | %-32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
# Root logger
log4j2.rootLogger.level = WARN
log4j2.rootLogger.appenderRefs = out, osgi
log4j2.rootLogger.appenderRef.out.ref = LOGFILE
log4j2.rootLogger.appenderRef.osgi.ref = OSGI
# Karaf Shell logger
log4j2.logger.shell.name = org.apache.karaf.shell.support
log4j2.logger.shell.level = OFF
log4j2.logger.shell.appenderRefs = stdout
log4j2.logger.shell.appenderRef.stdout.ref = STDOUT
# Security audit logger
log4j2.logger.audit.name = org.apache.karaf.jaas.modules.audit
log4j2.logger.audit.level = INFO
log4j2.logger.audit.additivity = false
log4j2.logger.audit.appenderRefs = audit
log4j2.logger.audit.appenderRef.audit.ref = AUDIT
# openHAB specific logger configuration
log4j2.logger.openhab.name = org.openhab
log4j2.logger.openhab.level = INFO
log4j2.logger.smarthome.name = org.eclipse.smarthome
log4j2.logger.smarthome.level = INFO
log4j2.logger.smarthomeItemStateEvent.name = smarthome.event.ItemStateEvent
log4j2.logger.smarthomeItemStateEvent.level = ERROR
log4j2.logger.smarthomeItemAddedEvent.name = smarthome.event.ItemAddedEvent
log4j2.logger.smarthomeItemAddedEvent.level = ERROR
log4j2.logger.smarthomeItemRemovedEvent.name = smarthome.event.ItemRemovedEvent
log4j2.logger.smarthomeItemRemovedEvent.level = ERROR
log4j2.logger.smarthomeThingStatusInfoEvent.name = smarthome.event.ThingStatusInfoEvent
log4j2.logger.smarthomeThingStatusInfoEvent.level = ERROR
log4j2.logger.smarthomeThingAddedEvent.name = smarthome.event.ThingAddedEvent
log4j2.logger.smarthomeThingAddedEvent.level = ERROR
log4j2.logger.smarthomeThingRemovedEvent.name = smarthome.event.ThingRemovedEvent
log4j2.logger.smarthomeThingRemovedEvent.level = ERROR
log4j2.logger.smarthomeInboxUpdatedEvent.name = smarthome.event.InboxUpdatedEvent
log4j2.logger.smarthomeInboxUpdatedEvent.level = ERROR
log4j2.logger.events.name = smarthome.event
log4j2.logger.events.level = INFO
log4j2.logger.events.additivity = false
log4j2.logger.events.appenderRefs = event
log4j2.logger.events.appenderRef.event.ref = EVENT
log4j2.logger.events.appenderRef.osgi.ref = OSGI
log4j2.logger.jupnp.name = org.jupnp
log4j2.logger.jupnp.level = ERROR
log4j2.logger.jmdns.name = javax.jmdns
log4j2.logger.jmdns.level = ERROR
#log4j2.logger.org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper = ERROR
#log4j2.logger.org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper = ERROR
#log4j2.logger.org.apache.karaf.kar.internal.KarServiceImpl = ERROR
# Appenders configuration
# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = STDOUT
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
# Rolling file appender
log4j2.appender.out.type = RollingRandomAccessFile
log4j2.appender.out.name = LOGFILE
log4j2.appender.out.fileName = /var/log/openhab2/openhab.log
log4j2.appender.out.filePattern = /var/log/openhab2/openhab.log.%i
log4j2.appender.out.immediateFlush = true
log4j2.appender.out.append = true
log4j2.appender.out.layout.type = PatternLayout
log4j2.appender.out.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j2.appender.out.policies.type = Policies
log4j2.appender.out.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.out.policies.size.size = 16MB
# Event log appender
log4j2.appender.event.type = RollingRandomAccessFile
log4j2.appender.event.name = EVENT
log4j2.appender.event.fileName = /var/log/openhab2/events.log
log4j2.appender.event.filePattern = /var/log/openhab2/events.log.%i
log4j2.appender.event.immediateFlush = true
log4j2.appender.event.append = true
log4j2.appender.event.layout.type = PatternLayout
log4j2.appender.event.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-26.26c] - %m%n
log4j2.appender.event.policies.type = Policies
log4j2.appender.event.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.event.policies.size.size = 16MB
log4j2.appender.out.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.out.policies.size.size = 16MB
# Event log appender
log4j2.appender.event.type = RollingRandomAccessFile
log4j2.appender.event.name = EVENT
log4j2.appender.event.fileName = /var/log/openhab2/events.log
log4j2.appender.event.filePattern = /var/log/openhab2/events.log.%i
log4j2.appender.event.immediateFlush = true
log4j2.appender.event.append = true
log4j2.appender.event.layout.type = PatternLayout
log4j2.appender.event.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-26.26c] - %m%n
log4j2.appender.event.policies.type = Policies
log4j2.appender.event.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.event.policies.size.size = 16MB
# Audit file appender
log4j2.appender.audit.type = RollingRandomAccessFile
log4j2.appender.audit.name = AUDIT
log4j2.appender.audit.fileName = /var/log/openhab2/audit.log
log4j2.appender.audit.filePattern = /var/log/openhab2/audit.log.%i
log4j2.appender.audit.append = true
log4j2.appender.audit.layout.type = PatternLayout
log4j2.appender.audit.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j2.appender.audit.policies.type = Policies
log4j2.appender.audit.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.audit.policies.size.size = 8MB
# OSGi appender
log4j2.appender.osgi.type = PaxOsgi
log4j2.appender.osgi.name = OSGI
log4j2.appender.osgi.filter = *
Custom Config
This example includes the following changes:
- Silence the majority of smarthome.events (keep only ItemCommandEvent at INFO level)
- Define 2 new loggers and 2 file appenders for 2 selected bindings (Z-Wave & KNX)
- Set for each new custom appender a max size of 10MB per log file and a max of 10 old log files to keep
- Change the layout.pattern for all 3 log files: audit.log, events.log and openhab.log to show more text (50 chars) for the category .
Here it is:
# Common pattern layout for appenders
#log4j2.pattern = %d{ISO8601} | %-5p | %-16t | %-32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
# Root logger
log4j2.rootLogger.level = WARN
log4j2.rootLogger.appenderRefs = out, osgi
log4j2.rootLogger.appenderRef.out.ref = LOGFILE
log4j2.rootLogger.appenderRef.osgi.ref = OSGI
# Karaf Shell logger
log4j2.logger.shell.name = org.apache.karaf.shell.support
log4j2.logger.shell.level = OFF
log4j2.logger.shell.appenderRefs = stdout
log4j2.logger.shell.appenderRef.stdout.ref = STDOUT
#log4j2.logger.org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper = ERROR
#log4j2.logger.org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper = ERROR
#log4j2.logger.org.apache.karaf.kar.internal.KarServiceImpl = ERROR
# Security audit logger
log4j2.logger.audit.name = org.apache.karaf.jaas.modules.audit
log4j2.logger.audit.level = INFO
log4j2.logger.audit.additivity = false
log4j2.logger.audit.appenderRefs = audit
log4j2.logger.audit.appenderRef.audit.ref = AUDIT
# openHAB specific logger configuration
log4j2.logger.openhab.name = org.openhab
log4j2.logger.openhab.level = INFO
log4j2.logger.smarthome.name = org.eclipse.smarthome
log4j2.logger.smarthome.level = INFO
log4j2.logger.smarthome_events.name = smarthome.event
log4j2.logger.smarthome_events.level = INFO
log4j2.logger.smarthome_events.additivity = false
log4j2.logger.smarthome_events.appenderRefs = event
log4j2.logger.smarthome_events.appenderRef.event.ref = EVENT
log4j2.logger.smarthome_events.appenderRef.osgi.ref = OSGI
log4j2.logger.jupnp.name = org.jupnp
log4j2.logger.jupnp.level = ERROR
log4j2.logger.jmdns.name = javax.jmdns
log4j2.logger.jmdns.level = ERROR
# Custom Log Levels
log4j2.logger.smarthome_event_ChannelTriggeredEvent.name = smarthome.event.ChannelTriggeredEvent
log4j2.logger.smarthome_event_ChannelTriggeredEvent.level = WARN
log4j2.logger.smarthome_event_ConfigStatusInfoEvent.name = smarthome.event.ConfigStatusInfoEvent
log4j2.logger.smarthome_event_ConfigStatusInfoEvent.level = WARN
log4j2.logger.smarthome_event_ExtensionEvent.name = smarthome.event.ExtensionEvent
log4j2.logger.smarthome_event_ExtensionEvent.level = WARN
log4j2.logger.smarthome_event_GroupItemStateChangedEvent.name = smarthome.event.GroupItemStateChangedEvent
log4j2.logger.smarthome_event_GroupItemStateChangedEvent.level = WARN
log4j2.logger.smarthome_event_InboxAddedEvent.name = smarthome.event.InboxAddedEvent
log4j2.logger.smarthome_event_InboxAddedEvent.level = WARN
log4j2.logger.smarthome_event_InboxRemovedEvent.name = smarthome.event.InboxRemovedEvent
log4j2.logger.smarthome_event_InboxRemovedEvent.level = WARN
log4j2.logger.smarthome_event_InboxUpdatedEvent.name = smarthome.event.InboxUpdatedEvent
log4j2.logger.smarthome_event_InboxUpdatedEvent.level = WARN
log4j2.logger.smarthome_event_ItemAddedEvent.name = smarthome.event.ItemAddedEvent
log4j2.logger.smarthome_event_ItemAddedEvent.level = WARN
log4j2.logger.smarthome_event_ItemChannelLinkAddedEvent.name = smarthome.event.ItemChannelLinkAddedEvent
log4j2.logger.smarthome_event_ItemChannelLinkAddedEvent.level = WARN
log4j2.logger.smarthome_event_ItemChannelLinkRemovedEvent.name = smarthome.event.ItemChannelLinkRemovedEvent
log4j2.logger.smarthome_event_ItemChannelLinkRemovedEvent.level = WARN
log4j2.logger.smarthome_event_ItemCommandEvent.name = smarthome.event.ItemCommandEvent
log4j2.logger.smarthome_event_ItemCommandEvent.level = INFO
log4j2.logger.smarthome_event_ItemRemovedEvent.name = smarthome.event.ItemRemovedEvent
log4j2.logger.smarthome_event_ItemRemovedEvent.level = WARN
log4j2.logger.smarthome_event_ItemStateChangedEvent.name = smarthome.event.ItemStateChangedEvent
log4j2.logger.smarthome_event_ItemStateChangedEvent.level = WARN
log4j2.logger.smarthome_event_ItemStateEvent.name = smarthome.event.ItemStateEvent
log4j2.logger.smarthome_event_ItemStateEvent.level = WARN
log4j2.logger.smarthome_event_ThingAddedEvent.name = smarthome.event.ThingAddedEvent
log4j2.logger.smarthome_event_ThingAddedEvent.level = WARN
log4j2.logger.smarthome_event_ThingRemovedEvent.name = smarthome.event.ThingRemovedEvent
log4j2.logger.smarthome_event_ThingRemovedEvent.level = WARN
log4j2.logger.smarthome_event_ThingStatusInfoChangedEvent.name = smarthome.event.ThingStatusInfoChangedEvent
log4j2.logger.smarthome_event_ThingStatusInfoChangedEvent.level = WARN
log4j2.logger.smarthome_event_ThingStatusInfoEvent.name = smarthome.event.ThingStatusInfoEvent
log4j2.logger.smarthome_event_ThingStatusInfoEvent.level = WARN
log4j2.logger.smarthome_event_ThingUpdatedEvent.name = smarthome.event.ThingUpdatedEvent
log4j2.logger.smarthome_event_ThingUpdatedEvent.level = WARN
log4j2.logger.org_openhab_action_mail.name = org.openhab.action.mail
log4j2.logger.org_openhab_action_mail.level = WARN
log4j2.logger.org_openhab_binding_mpower.name = org.openhab.binding.mpower
log4j2.logger.org_openhab_binding_mpower.level = WARN
log4j2.logger.org_openhab_binding_mqtt.name = org.openhab.binding.mqtt
log4j2.logger.org_openhab_binding_mqtt.level = WARN
log4j2.logger.org_openhab_binding_ntp.name = org.openhab.binding.ntp
log4j2.logger.org_openhab_binding_ntp.level = WARN
log4j2.logger.org_openhab_binding_unifi.name = org.openhab.binding.unifi
log4j2.logger.org_openhab_binding_unifi.level = WARN
log4j2.logger.org_openhab_binding_weather.name = org.openhab.binding.weather
log4j2.logger.org_openhab_binding_weather.level = WARN
log4j2.logger.org_openhab_binding_wol.name = org.openhab.binding.wol
log4j2.logger.org_openhab_binding_wol.level = INFO
log4j2.logger.org_openhab_persistence_mapdb.name = org.openhab.persistence.mapdb
log4j2.logger.org_openhab_persistence_mapdb.level = WARN
log4j2.logger.org_openhab_persistence_influxdb.name = org.openhab.persistence.influxdb
log4j2.logger.org_openhab_persistence_influxdb.level = WARN
log4j2.logger.org_openhab_binding_samsungtv.name = org.openhab.binding.samsungtv
log4j2.logger.org_openhab_binding_samsungtv.level = WARN
log4j2.logger.org_openhab_io_homekit.name = org.openhab.io.homekit
log4j2.logger.org_openhab_io_homekit.level = WARN
log4j2.logger.org_openhab_io_transport_mqtt.name = org.openhab.io.transport.mqtt
log4j2.logger.org_openhab_io_transport_mqtt.level = WARN
log4j2.logger.org_openhab_ui_paperui.name = org.openhab.ui.paperui
log4j2.logger.org_openhab_ui_paperui.level = WARN
log4j2.logger.org_openhab_ui_basicui.name = org.openhab.ui.basicui
log4j2.logger.org_openhab_ui_basicui.level = WARN
log4j2.logger.org_openhab_ui_habmin.name = org.openhab.ui.habmin
log4j2.logger.org_openhab_ui_habmin.level = WARN
log4j2.logger.org_openhab_ui_habpanel.name = org.openhab.ui.habpanel
log4j2.logger.org_openhab_ui_habpanel.level = WARN
log4j2.logger.org_openhab_io_rest_docs.name = org.openhab.io.rest.docs
log4j2.logger.org_openhab_io_rest_docs.level = WARN
log4j2.logger.smarthome_ui_paper.name = smarthome.ui.paper
log4j2.logger.smarthome_ui_paper.level = WARN
log4j2.logger.smarthome_ui_basic.name = smarthome.ui.basic
log4j2.logger.smarthome_ui_basic.level = WARN
log4j2.logger.smarthome_transform_jsonpath.name = smarthome.transform.jsonpath
log4j2.logger.smarthome_transform_jsonpath.level = WARN
log4j2.logger.smarthome_transform_map.name = smarthome.transform.map
log4j2.logger.smarthome_transform_map.level = WARN
log4j2.logger.smarthome_transform_regex.name = smarthome.transform.regex
log4j2.logger.smarthome_transform_regex.level = WARN
### Custom Loggers ###
# ZWave
log4j2.logger.ZWave.name = org.openhab.binding.zwave
log4j2.logger.ZWave.level = INFO
log4j2.logger.ZWave.additivity = false
log4j2.logger.ZWave.appenderRefs = ZWave
log4j2.logger.ZWave.appenderRef.ZWave.ref = ZWAVE
# KNX
log4j2.logger.KNX.name = org.openhab.binding.knx
log4j2.logger.KNX.level = INFO
log4j2.logger.KNX.additivity = false
log4j2.logger.KNX.appenderRefs = KNX
log4j2.logger.KNX.appenderRef.KNX.ref = KNX
# Appenders configuration
### Custom Appenders ###
# ZWave
log4j2.appender.ZWave.name = ZWAVE
log4j2.appender.ZWave.type = RollingRandomAccessFile
log4j2.appender.ZWave.fileName = /var/log/openhab2/ZWave.log
log4j2.appender.ZWave.filePattern = /var/log/openhab2/ZWave.log.%i
log4j2.appender.ZWave.immediateFlush = true
log4j2.appender.ZWave.append = true
log4j2.appender.ZWave.layout.type = PatternLayout
log4j2.appender.ZWave.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.ZWave.policies.type = Policies
log4j2.appender.ZWave.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.ZWave.policies.size.size = 10MB
log4j2.appender.ZWave.strategy.type = DefaultRolloverStrategy
log4j2.appender.ZWave.strategy.max = 10
# KNX
log4j2.appender.KNX.name = KNX
log4j2.appender.KNX.type = RollingRandomAccessFile
log4j2.appender.KNX.fileName = /var/log/openhab2/KNX.log
log4j2.appender.KNX.filePattern = /var/log/openhab2/KNX.log.%i
log4j2.appender.KNX.immediateFlush = true
log4j2.appender.KNX.append = true
log4j2.appender.KNX.layout.type = PatternLayout
log4j2.appender.KNX.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.KNX.policies.type = Policies
log4j2.appender.KNX.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.KNX.policies.size.size = 10MB
log4j2.appender.KNX.strategy.type = DefaultRolloverStrategy
log4j2.appender.KNX.strategy.max = 10
# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = STDOUT
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
# Rolling file appender
log4j2.appender.out.type = RollingRandomAccessFile
log4j2.appender.out.name = LOGFILE
log4j2.appender.out.fileName = /var/log/openhab2/openhab.log
log4j2.appender.out.filePattern = /var/log/openhab2/openhab.log.%i
log4j2.appender.out.immediateFlush = true
log4j2.appender.out.append = true
log4j2.appender.out.layout.type = PatternLayout
log4j2.appender.out.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.out.policies.type = Policies
log4j2.appender.out.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.out.policies.size.size = 16MB
# Event log appender
log4j2.appender.event.type = RollingRandomAccessFile
log4j2.appender.event.name = EVENT
log4j2.appender.event.fileName = /var/log/openhab2/events.log
log4j2.appender.event.filePattern = /var/log/openhab2/events.log.%i
log4j2.appender.event.immediateFlush = true
log4j2.appender.event.append = true
log4j2.appender.event.layout.type = PatternLayout
log4j2.appender.event.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-50.50c] - %m%n
log4j2.appender.event.policies.type = Policies
log4j2.appender.event.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.event.policies.size.size = 16MB
# Audit file appender
log4j2.appender.audit.type = RollingRandomAccessFile
log4j2.appender.audit.name = AUDIT
log4j2.appender.audit.fileName = /var/log/openhab2/audit.log
log4j2.appender.audit.filePattern = /var/log/openhab2/audit.log.%i
log4j2.appender.audit.append = true
log4j2.appender.audit.layout.type = PatternLayout
log4j2.appender.audit.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.audit.policies.type = Policies
log4j2.appender.audit.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.audit.policies.size.size = 8MB
# OSGi appender
log4j2.appender.osgi.type = PaxOsgi
log4j2.appender.osgi.name = OSGI
log4j2.appender.osgi.filter = *