Log4j2 Sample Config

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

  1. My OH2 installation is very stable and I don’t add many new stuff so I want my logs to show me only Warnings+.
  2. I am running the following addons (in addons.cfg):
    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
    
    Plus 3 manually deployed addons: unifi, mpower, climacons
  3. 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)
  4. 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 = *
26 Likes

Nicely done, thank you! :slightly_smiling_face:

1 Like

This is excellent. Would you consider wiring this up as a PR so it gets included in the Docs? In particular how you created the new loggers will be very useful.

2 Likes

join the discussion :slight_smile:

1 Like

Hi @Dim,

Would you be able to offer any tips for configuring log4j2 to log to the console? I’m using docker and (for most containers) the GELF driver over to Graylog. Spitting everything out to the console and then parsing in Graylog would be a much better option for me but so far I’ve had no luck. :[

J

Hi @joshua_dunham,

I haven’t configured yet my system to use Graylog, so I can’t offer any help.

There is a GELF Appender for log4j2: https://github.com/graylog-labs/log4j2-gelf but I don’t know if it works properly.
In theory, you could use this to channel your logs directly from log4j2 to Graylog.

Thank you for yours example @Dim

Do you also use custom log entries from rules?
I use this in my rules as mentioned in the docs

logDebug("RULES", "Log message from rule xyz")

I tried to add this message to the standard openhab.log by modifying ...logging.cfg as follows

log4j2.logger.rules.name = smarthome.model.script.RULES
log4j2.logger.rules.level = INFO
log4j2.logger.rules.additivity = false
log4j2.logger.rules.appenderRefs = out
log4j2.logger.rules.appenderRef.out.ref = LOGFILE

Unfortunately without success. I think I have not really understood the log4j2 syntax :wink:
Any idea how to get rule logs working again?

Thanks.
Sebastian

I’ve setup custom logging of Zwave and my configuration looks the same as yours so I think you have the syntax right (other then not knowing if the smarthome.model.scripts.RULES is valid, so would look into that piece). Also, have you edited the file appender section at all and are you seeing any other logs go through (I had a type in the filter I put in the appender and it was blocking any logging from happening).

I have not edited the file appender section and all other logs work properly

I use the default destination (openhab.log)

with the above sample config I get the following:
In my rule:

logInfo("FE01","FE01 Timer rescheduled for " + FE01_TimeOut + " minutes")

In openhab.log

18-Aug-2017 20:33:02.532 [INFO ] [org.eclipse.smarthome.model.script.FE01           ] - FE01 Timer rescheduled for 5 minutes

I haven’t tried to redirect the log from my scripts to a custom logger and appender but this shouldn’t be so hard.
Your logger config looks good. You are using the default “LOGFILE” appender (which is the openhab.log RollingRandomAccessFile).

As per @Dim, the correct rules syntax I’ve used is also logInfo(), not logDebug() With that you shouldn’t have to edit your .cfg file at all unless I’m missing what you are trying to accomplish?

Edit: Now that I glanced at the docs, ‘logDebug()’ would only show up if you set your overall log level to DEBUG, whereas ‘logInfo()’ shows up in the default INFO log level

Ok, that is exactly what I’m trying.
And this FE01 doesn’t need to be defined anywhere in the logging configuration?

No, it’s just the identifier that appears on the log file line. Just switch to ‘logInfo()’ and it should work.

what? :slight_smile: to create a new custom logger and appender to keep your rule log entries?
Then, you shouldn’t use the existing appender (LOGFILE) but rather create a new one.

Define a new logger form smarthome.model.script (that will cover all underneath it, including script.RULES and other names)
Define a new appender as in the example above for the ZWAVE and/or KNX bindings

Correct. I just saw this.
The logger is capturing level = INFO but your rule uses logDebug

Ahhhhh :scream:

Thanks for the hint. That was the original reason to create a custom logger. I want to use logDebug but of course set the wrong log level in the config file.

Unfortunately this seems not to be the solution for my problem :weary:

I tried it with logInfo in the rules and absolutely no modification to the log config just as in your example … but still no rule logs appear …

You will end up with huge log files. I’d only recommend running in Debug mode when something particular is giving you issues.

To confirm, you deleted the changes you had made here to the cfg file:

https://community.openhab.org/t/log4j2-sample-config/33284/7?u=rgerrans

Yes, of course I’m using debug mode just for some trails at the moment. And I also wanted to just set the log level to debug for the rules, not for the whole system.

Yes

Finally,

I got it working :champagne:

What works now is the following

  logDebug("RULES", "--- Rule xyz")
  log4j2.logger.rules.name = org.eclipse.smarthome.model.script.RULES
  log4j2.logger.rules.level = DEBUG

No idea what the real problem was.
Thank you for pushing me to the right direction!

2 Likes

That makes much more sense then.

Congrats. I think the issue earlier was that you were setting your logger to INFO level not DEBUG, so now you got them both operating at the same level.

1 Like