namraccr
(namraccr)
March 10, 2017, 5:10am
1
When trying to debug problems in OH2, how does one enable line numbers in the log file?
I currently get this:
2017-03-09 23:38:18.162 [INFO ] [assic.internal.servlet.WebAppServlet] - Stopped Classic UI
I found a “log.cfg” file, but editing it didn’t help as apparently it’s overwritten by OH during startup…
TiA
rlkoshak
(Rich Koshak)
March 10, 2017, 4:43pm
2
This post is OBE. See Log4j2 Sample Config
**NOTE: With the build from November 10 #579 the location of all the files in runtime/karaf/etc have moved to userdata/etc. The instructions below have been updated accordingly. If you are running an older verison of openHAB (anything older than build #579), the location of the file is runtime/karaf/etc.
As almost everyone is aware, openHAB 2 uses a completely different logging library and approach to logging than openHAB 1.x does, replacing logback w…
The file you want to change is userdata/etc/org.ops4j.pax.logging.cfg (where userdata is /var/lib/openhab2 for apt-get installs).
1 Like
namraccr
(namraccr)
March 10, 2017, 5:36pm
3
Thanks!
Would have never EVER found that.
rlkoshak
(Rich Koshak)
March 10, 2017, 5:38pm
4
redeye86
(Florian Schulte)
March 17, 2017, 8:39pm
5
I am not sure if i missed something, but does this answer how to actually turn on line numbers the log files, especially for errors in rules?
namraccr
(namraccr)
March 18, 2017, 12:33pm
6
Yes, it does – sort of. But you still won’t get line numbers from inside your rules files.
The comments say which file you have to edit:
The config file for logging is org.ops4j.pax.logging.cfg located in the userdata/etc folder (manual setup) or in /var/lib/openhab2/etc (apt/deb-based setup).
And the documentation link Rich provided , has a section near the bottom labelled “Logging into [a] Separate File”.
This block in that file tells you how the logging to the openhab.cfg file is configured:
# File appender - openhab.log
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j.appender.out.file=${openhab.logdir}/openhab.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=10MB
log4j.appender.out.maxBackupIndex=10
And this line is the one you need to change:
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
The pattern is described in the Log4j docs , but to be succinct, what you need to add is a line number conversion like “%L” somewhere. Mine looks like this:
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c:%5.5L] - %m%n
Note that upper-case L and lower-case L give different results. The former is for line number, the latter location.