Logging in openHAB 3

I’m not seeing this in my custom logger configurations.

Here’s an example of mine.

In the Appenders section:

                <!-- ECOBEE -->
                <RollingRandomAccessFile append="true" fileName="${sys:openhab.logdir}/ecobee.log" filePattern="${sys:openhab.logdir}/ecobee.log.%i" immediateFlush="true" name="ECOBEE">
                        <PatternLayout>
                                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n</Pattern>
                        </PatternLayout>
                        <Policies>
                                <SizeBasedTriggeringPolicy size="10 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="4"/>
                </RollingRandomAccessFile>

In the Loggers section:

                <!-- ECOBEE -->
                <Logger additivity="false" level="DEBUG" name="org.openhab.binding.ecobee">
                        <AppenderRef ref="ECOBEE"/>
                </Logger>
2 Likes

I was missing immediateFlush=“true”. That fixed it. Thanks!

1 Like

Does anybody know how to add regex filter to this new XML file?

Same question here. Did you already find out @Kamil_Matuszczak?

Yes, but now I’m not at computer.
Remind me tomorrow:)

See:

1 Like

Do we still have te reboot to apply the changes in the XML file? It’s very unconvenient for me, because in OH3 that breaks the LogTail and the GoogleTTS voice, so with every change I have to reinstall (unable to do that for GoogleTTS) them…

Hope this will be fixed :slight_smile:

Did anyone try to set monitorInterval in log4j2.xml:

<Configuration monitorInterval="30">

This should check the file every 30 seconds for changes and apply them.
Maybe there is one restart necessary after you added it initially.

2 Likes

Will try it when my OH3 is up and running again. Having some SATA > USB3.0 convertor troubles at the moment… waiting for shipment :wink:

I can confirm that this is working for me. :clap: :clap:

Awesome. I think this would be worthwhile to submit for inclusion in the core, but maybe backing off the interval a little bit. Seems to me that one minute or even five minutes would be sufficient for seeing your changes relatively quickly.

I agree. I asked @wborn here if he considered it when doing the conversion to the new xml file format.

1 Like

PR was submitted so should be in a SNAPSHOT build soon.

Thanks @Rodelkoenig for pointing this out!

2 Likes

For the benefit of anyone who comes along and wants to do this, the modification is in the first line.

This:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><Configuration>

Becomes this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><Configuration monitorInterval="30">

Also, I now understand why 30 seconds is reasonable, given this statement:

the configuration file will be checked for changes only after at least 30 seconds have elapsed

I missed seeing that earlier.

For slow copy-paste people like me :wink: , here is a working example for z-wave.
I also found out the hard way that it is important to add each section at the end (Appenders and Loggers).

/var/lib/openhab/etc/log4j2.xml (Debian systems)
Appender part

 <!-- Z-wave appender -->
                <RollingRandomAccessFile append="true" fileName="${sys:openhab.logdir}/zwave.log" filePattern="${sys:openhab.logdir}/zwave.log.%i" immediateFlush="true" name="ZWAVE">
                        <PatternLayout>
                                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n</Pattern>
                        </PatternLayout>
                        <Policies>
                                <SizeBasedTriggeringPolicy size="16 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="8"/>
                </RollingRandomAccessFile>
<!-- Z-wave -->

Logger part

<!-- Z-wave Logger -->
                <Logger additivity="false" level="DEBUG" name="org.openhab.binding.zwave">
                        <AppenderRef ref="ZWAVE"/>
                </Logger>
<!-- Z-wave -->
4 Likes

Hi All,
First of all i want to say thanks to all for the input and @rockit4 for the “Copy/paste” Template and (for me) the most important hint to add the lines at the and of each section. I first added the lines in my well structed way (not at the end of each section) and it didn’t work. I tried many combinations, openhab.service restarts and even reboots of the whole environment. Nothing worked. So i read the last post carefully and there it was.

I also found out the hard way that it is important to add each section at the end (Appenders and Loggers).

Thanks for such a great community!

1 Like

Glad i could be of help :slight_smile:
Personally I love when someone has taken the time to write an example ready to go.
Copy/paste and you are up and running without the need to read the book how to do it.
You could argue that being lazy is the driving force of home automation :parasol_on_ground:

1 Like

I think it needs one reboot after adding that in the file. I added it but it doesn’t filter any of my events. Is there a possibility to restart the logging service (apache i think?).

Sorry to revive an old post. I tried to adapt @rockit4 ZWAVE code for RFXCOM binding, I’m no longer able to find its logs since update to OH3 (very useful to identify protocols). This is what I added in Appenders section :

                 <!-- RFXCOM appender -->
                <RollingRandomAccessFile append="true" fileName="${sys:openhab.logdir}/rfxcom.log" filePattern="${sys:openhab.logdir}/rfxcom.log.%i" immediateFlush="true" name="RFXCOM">
                        <PatternLayout>
                                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n</Pattern>
                        </PatternLayout>
                        <Policies>
                                <SizeBasedTriggeringPolicy size="16 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="8"/>
                </RollingRandomAccessFile>
                <!-- RFXCOM -->
        </Appenders>

And in loggers :

                <!-- RFXCOM Logger -->
                <Logger additivity="false" level="DEBUG" name="org.openhab.binding.rfxcom">
                        <AppenderRef ref="RFXCOM"/>
                </Logger>
                <!-- RFXCOM -->
        </Loggers>

Is anyone having the same issue ? I’d gladly appreciate some help, some chinese unknown 433.92 Mhz things are still on the shelves.

I also battled with logging etc. Edited my /userdata/etc/org.ops4j.pax.logging.cfg to be as follows:

org.ops4j.pax.logging.log4j2.config.file=${karaf.etc}/log4j2.xml

This seemed to resolve the issues I had setting logging via log4j2.xml

I am running on Windows 10.

Not sure if the upgrade fails to correctly update the file?