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"
when
	Item Foyer_Motion changed 	
then
	var String msg = "Foyer Motion "
    msg = msg.concat(String::valueOf(Foyer_Motion.state))
    logInfo("motion", msg)
end

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"/>
                        <Policies>
                                <OnStartupTriggeringPolicy/>
                                <SizeBasedTriggeringPolicy size="16 MB"/>
                        </Policies>
                </RollingRandomAccessFile>
<!-- motion -->
<!-- motion Logger -->
                <Logger additivity="false" level="INFO" name="org.eclipse.smarthome.model.script.motion">
                        <AppenderRef ref="MOTION"/>
                </Logger>
<!-- motion -->
</Configuration>

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?

Thanks

There is an example in the zwave binding:

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

to
name="org.openhab.core.model.script.motion"

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.

Chris

1 Like