Log4j2 Sample Config

Yes, of course I’m using debug mode just for some trails at the moment. And I also wanted to just set the log level to debug for the rules, not for the whole system.

Yes

Finally,

I got it working :champagne:

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

That makes much more sense then.

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

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.

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)

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

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.

You didn’t let it update your config file during the update to the new format. You need to replace /userdata/etc/org.ops4j.pax.logging.cfg

With the contents of https://github.com/openhab/openhab-distro/blob/3b1bbf413f6c4b849891708609dcfa8c2ea609e4/distributions/openhab/src/main/resources/userdata/etc/org.ops4j.pax.logging.cfg

2 Likes

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?

Here you go https://community.openhab.org/t/karaf-upgrade/33208/5?u=rgerrans

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?

Sorry, I saw the two cp lines and didn’t read the full actions. Maybe @kai can identify the other file that changed.

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.

The question was, if there was a second changed config file at all. Not only for logging.

use the info that Benjy gave you to find the answer yourself :slight_smile:

cd /var/lib/openhab2/
find . -name *dpkg*

Cannot make it work with log4j2, could you please post your full setup (logger and appender)? Thx.

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.

Ahh, okay, thanks. I thought you are logging into a separate file. Then I have to dig into the docs …

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

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.