Logging to seperate log file OpenHab 3

I have recently migrated from 2.5 to 3.1. Previously I had logging to separate log files. With the changes in ver 3, it stopped working. My OS is Ubuntu 18.04.
For example, in my rules I want to log motion events in to a log file motion.log.

rule "Foyer Motion"
	Item Foyer_Motion changed 	
	var String msg = "Foyer Motion "
    msg = msg.concat(String::valueOf(Foyer_Motion.state))
    logInfo("motion", msg)

I have modified my /var/lib/openhab/etc/log4j2.xml file to append this to the end:

 <!-- motion appender -->
                <RollingRandomAccessFile fileName="${sys:openhab.logdir}/motion.log" filePattern="${sys:openhab.logdir}/motion.log.%i" name="MOTION">
                        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
                                <SizeBasedTriggeringPolicy size="16 MB"/>
<!-- motion -->
<!-- motion Logger -->
                <Logger additivity="false" level="INFO" name="org.eclipse.smarthome.model.script.motion">
                        <AppenderRef ref="MOTION"/>
<!-- motion -->

I should add, the motion.log file is created, but the logs are writing into openhab.log. The motion.log is empty.

I don’t know what I am doing wrong. Any ideas?


There is an example in the zwave binding:

That is one of the ‘breaking’ changes in OH3.
The name changed from


1 Like

There was one more step after correcting the name as Wolfgang suggests. I also had to move my custom appenders and loggers into the appropriate and areas. Not sure what the technical name for the <> </> brackets are called.

Anyway, thanks for the replies. It is working now.


1 Like

Sorry for crashing into this thread, I used your logging script to do something similar but can´t get it to write anything. Putting the parts to the correct sections, Appenders section within and the logging part to

Of course I used name=“org.openhab.core.model.script.motion” . Then I just a simple “script” for testing purposes with just one row, executing it in the editor.

logInfo("motion", "test")

but nothing gets written.

What am I doing wrong?

Did you restart OH ?
Post your complete logging configuration file.