Finally,
I got it working
What works now is the following
logDebug("RULES", "--- Rule xyz")
log4j2.logger.rules.name = org.eclipse.smarthome.model.script.RULES
log4j2.logger.rules.level = DEBUG
No idea what the real problem was.
Thank you for pushing me to the right direction!
2 Likes
rgerrans
(Rgerrans)
August 18, 2017, 7:06pm
20
That makes much more sense then.
hannibal29:
I got it working
Congrats. I think the issue earlier was that you were setting your logger to INFO level not DEBUG, so now you got them both operating at the same level.
1 Like
rgerrans
(Rgerrans)
August 21, 2017, 1:25pm
21
Does anyone know if it’s possible to setup a single binding to log to two different files with different log levels? So far my tests haven’t worked.
Dim
(Angelos)
August 21, 2017, 4:12pm
22
to control the appender rolling, add the following 2 lines at the end of your custom appender:
log4j2.appender.ZWave.strategy.type = DefaultRolloverStrategy
log4j2.appender.ZWave.strategy.max = 10
(I updated the first post also)
rgerrans
(Rgerrans)
August 24, 2017, 11:02pm
23
So I finally figured out how to get the logger configuration right to do this. I have a filtered debug log I use to pull certain zwave information out for rule triggers but wanted to keep normal info level logging information going to the default log file. Here is my logger configuration, where lockid is my appender information to filter out the zwave alarm codes to a separate file.:
# Logger - Zwave
log4j2.logger.zwave.name = org.openhab.binding.zwave
log4j2.logger.zwave.level = DEBUG
log4j2.logger.zwave.additivity = false
log4j2.logger.zwave.appenderRefs = lockid, out
log4j2.logger.zwave.appenderRef.lockid.ref = LOCKID
log4j2.logger.zwave.appenderRef.out.ref = LOGFILE
log4j2.logger.zwave.appenderRef.out.level = INFO
Appender configuration in case anyone else wants to apply filters:
# File appender - lockid.log
log4j2.appender.lockid.name = LOCKID
log4j2.appender.lockid.type = RollingRandomAccessFile
log4j2.appender.lockid.fileName = /var/log/openhab2/lockid.log
log4j2.appender.lockid.filePattern = /var/log/openhab2/lockid.log.%i
log4j2.appender.lockid.filter.regex.type = RegexFilter
log4j2.appender.lockid.filter.regex.regex = .*ALARM report - 19.*
log4j2.appender.lockid.filter.regex.onMatch = ACCEPT
log4j2.appender.lockid.filter.regex.onMisMatch = DENY
log4j2.appender.lockid.immediateFlush = true
log4j2.appender.lockid.append = true
log4j2.appender.lockid.layout.type = PatternLayout
log4j2.appender.lockid.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.lockid.policies.type = Policies
log4j2.appender.lockid.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.lockid.policies.size.size = 10MB
log4j2.appender.lockid.strategy.type = DefaultRolloverStrategy
log4j2.appender.lockid.strategy.max = 5
6 Likes
halloween
(Hallo Ween)
August 28, 2017, 11:17am
24
Please can someone tell me in a dummy-friendly way how i can get the old logging-behavior back? I made a snapshot update a few days agp and since this time i don´t get any new log entries into the events.log and the openhab.log.
rgerrans
(Rgerrans)
August 28, 2017, 11:24am
25
2 Likes
halloween
(Hallo Ween)
August 28, 2017, 12:00pm
26
Thanks a lot, that was it…
But i think there was another file which i made a deny to update. Can you tell me, which config file this was?
rgerrans
(Rgerrans)
August 28, 2017, 12:38pm
27
halloween
(Hallo Ween)
August 28, 2017, 12:57pm
28
Yes, but i thought there were 2 files which will be overwritten and i typed “N” (no).
So was this config-file for logging the only config-file which was changed inside this snapshot-update?
rgerrans
(Rgerrans)
August 28, 2017, 1:08pm
29
Sorry, I saw the two cp lines and didn’t read the full actions. Maybe @kai can identify the other file that changed.
Benjy
(Ben Clark)
August 29, 2017, 10:20am
30
Yes there was only one config file responsible for logging.
For future reference if you tell apt that you don’t want to use the new config, it will still be placed in the folder, it will just have dpkg*
appended to it. If you choose to overwrite with the new config, your old configuration will be renamed to the same name with dpkg-old
appended to it.
halloween
(Hallo Ween)
August 29, 2017, 11:47am
31
The question was, if there was a second changed config file at all. Not only for logging.
Dim
(Angelos)
August 29, 2017, 11:52am
32
use the info that Benjy gave you to find the answer yourself
cd /var/lib/openhab2/
find . -name *dpkg*
sihui
(SiHui)
September 1, 2017, 4:51pm
33
Cannot make it work with log4j2, could you please post your full setup (logger and appender)? Thx.
hannibal29
(Sebastian)
September 1, 2017, 6:43pm
34
Hey @sihui
the logger for my rules looks exactly like I mentioned above
log4j2.logger.rules.name = org.eclipse.smarthome.model.script.RULES
log4j2.logger.rules.level = DEBUG
It’s more or less the same like @Dim describes in his 1st post (# Custom Log Levels)
I have not configured a custom appender yet.
The RULES logs go the openhab.log and OSGI only.
sihui
(SiHui)
September 3, 2017, 1:31pm
35
Ahh, okay, thanks. I thought you are logging into a separate file. Then I have to dig into the docs …
mas
(Markus)
December 11, 2017, 11:14pm
37
Is it possible to change the log level of the ItemStateChangedEvent only for a specific item?
I want the following logs to be suppressed:
2017-12-12 00:02:52.207 [vent.ItemStateChangedEvent] - Temperature changed from 5.1 to 4.8
rlkoshak
(Rich Koshak)
December 12, 2017, 3:38pm
38
I don’t think so. The events.log is set up to log all the activity on the event bus and that include State changes.
See How to watch and look through logging for some ways to filter on a log file to focus on just that information you want.
Here’s an example that I implemented today.
Objectives:
-Specify a default log level for all rules.
-(Temporarily) overrule the log level for individual log files.
-Use a dedicated log file for any logging created by my rules.
I have edited the /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg file and added the following three sections:
# Rules files logger (default)
log4j2.logger.rules.name = org.eclipse.smarthome.model.script.rules
log4j2.logger.rules.level = INFO
log4j2.logger.rules.additivity = false
log4j2.logger.rules.appenderRefs = rules
log4j2.logger.rules.appenderRef.stdout.ref = RULES
# Log level for individual rules files
#log4j2.logger.rulesExperiment.name = org.eclipse.smarthome.model.script.rules.experiment
#log4j2.logger.rulesExperiment.level = DEBUG
#log4j2.logger.rulesNetwork.name = org.eclipse.smarthome.model.script.rules.network
#log4j2.logger.rulesNetwork.level = DEBUG
#log4j2.logger.rulesPresence.name = org.eclipse.smarthome.model.script.rules.presence
#log4j2.logger.rulesPresence.level = DEBUG
#log4j2.logger.rulesRfxtrx.name = org.eclipse.smarthome.model.script.rules.rfxtrx
#log4j2.logger.rulesRfxtrx.level = DEBUG
#log4j2.logger.rulesSun.name = org.eclipse.smarthome.model.script.rules.sun
#log4j2.logger.rulesSun.level = DEBUG
#log4j2.logger.rulesTimers.name = org.eclipse.smarthome.model.script.rules.timers
#log4j2.logger.rulesTimers.level = DEBUG
# Rules file appender
log4j2.appender.rules.type = RollingRandomAccessFile
log4j2.appender.rules.name = RULES
log4j2.appender.rules.fileName = ${openhab.logdir}/rules.log
log4j2.appender.rules.filePattern = ${openhab.logdir}/rules.log.%i
log4j2.appender.rules.immediateFlush = true
log4j2.appender.rules.append = true
log4j2.appender.rules.layout.type = PatternLayout
log4j2.appender.rules.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j2.appender.rules.policies.type = Policies
log4j2.appender.rules.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rules.policies.size.size = 8MB
I hope this can help anyone who is struggling with the new log4j2 configuration.
edit
In the rules files I call the log methods as follows:
logDebug("rules.experiment","blah blah");
logInfo("rules.timers","blah blah");
logError("rules.network","blah blah");
Cheers,
Robert.
2 Likes