Logging

How to exclude items from Logging

You might want to exclude items, like for smart metering devices, from flooding your log.

In this example I address multiple items with just one regex. All items are named like:

  • ITEM1_CURRENTWATTS
  • ITEM2_CURRENTWATTS
  • ITEM1_TOTALKWH
  • ITEM2_TOTALKWH

In OpenHAB 3.x edit the file /var/lib/openhab/etc/log4j2.xml and add the following line:

<!-- Event log appender -->
<RollingRandomAccessFile fileName="${sys:openhab.logdir}/events.log" filePattern="${sys:openhab.logdir}/events.log.%i.gz" name="EVENT">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
        <RegexFilter regex=".*(CURRENTWATTS|TOTALKWH).*" onMatch="DENY" onMismatch="NEUTRAL"/>
        <Policies>
                <OnStartupTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="16 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="7"/>
</RollingRandomAccessFile>