Logging to separate file

logging
Tags: #<Tag:0x00007f6ce99d0960>

(autoit) #1

I’m trying to get the example from the docs to work, but failing so far. At the end of /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg I have

# Logger - Demo.log
log4j.logger.org.eclipse.smarthome.model.script.Demo = DEBUG, Demo

# File appender - Demo.log
log4j.appender.Demo=org.apache.log4j.RollingFileAppender
log4j.appender.Demo.layout=org.apache.log4j.PatternLayout
log4j.appender.Demo.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j.appender.Demo.file=${openhab.logdir}/Demo.log
log4j.appender.Demo.append=true
log4j.appender.Demo.maxFileSize=10MB
log4j.appender.Demo.maxBackupIndex=10

On a rule I have

logDebug("Demo", "demo")

No Demo.log is created at all. I know the rule is working since if I replace Debug with Info, I can see the log entry on /var/log/openhab2/openhab.log. I’m running Openhabian 2.2.0-1 on Pi 3. What am I doing wrong?


(Angelos) #2

If I am not wrong, you need to use log4j2 since you are on OH2.2
see example here: Log4j2 Sample Config

Ps: I think that the docs are not up to speed with log4j2 (that’s also my fault :stuck_out_tongue:)


(autoit) #3

Tried to do that, but then I’m getting this in the log as soon as I save the file :confused:

2018-02-14 18:37:47.834 [ERROR] [org.apache.felix.configadmin        ] - [org.osgi.service.log.LogService, org.knopflerfish.service.log.LogService, org.ops4j.pax.logging.PaxLoggingService, org.osgi.service.cm.ManagedService, id=33, bundle=6/mvn:org.ops4j.pax.logging/pax-logging-log4j2/1.10.1]: Unexpected problem updating configuration org.ops4j.pax.logging

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

	at java.lang.String.substring(String.java:1967) [?:?]

	at org.apache.logging.log4j.util.PropertiesUtil.partitionOnCommonPrefixes(PropertiesUtil.java:293) [5:org.ops4j.pax.logging.pax-logging-api:1.10.1]

	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:155) [6:org.ops4j.pax.logging.pax-logging-log4j2:1.10.1]

	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56) [6:org.ops4j.pax.logging.pax-logging-log4j2:1.10.1]

	at org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.doUpdate(PaxLoggingServiceImpl.java:206) [6:org.ops4j.pax.logging.pax-logging-log4j2:1.10.1]

	at org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:158) [6:org.ops4j.pax.logging.pax-logging-log4j2:1.10.1]

	at org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl$1ManagedPaxLoggingService.updated(PaxLoggingServiceImpl.java:426) [6:org.ops4j.pax.logging.pax-logging-log4j2:1.10.1]

	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189) [7:org.apache.felix.configadmin:1.8.16]

	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152) [7:org.apache.felix.configadmin:1.8.16]

	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85) [7:org.apache.felix.configadmin:1.8.16]

	at org.apache.felix.cm.impl.ConfigurationManager$UpdateConfiguration.run(ConfigurationManager.java:1792) [7:org.apache.felix.configadmin:1.8.16]

	at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141) [7:org.apache.felix.configadmin:1.8.16]

	at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109) [7:org.apache.felix.configadmin:1.8.16]

	at java.lang.Thread.run(Thread.java:748) [?:?]