Log4j2 Sample Config

My logfile show me this:

2019-03-28 09:03:46.822 [vent.ItemStateChangedEvent] - systeminfo_computer_openHABianPi_cpu_load changed from 5.5 to 5.7
2019-03-28 09:03:46.831 [vent.ItemStateChangedEvent] - Raspberry_CpuLoad changed from 5.5 to 5.7
2019-03-28 09:03:46.858 [vent.ItemStateChangedEvent] - systeminfo_computer_openHABianPi_sensors_cpuTemp changed from 60.1 to 59.6
2019-03-28 09:03:46.862 [vent.ItemStateChangedEvent] - Raspberry_SensorsCpuTemp changed from 60.1 to 59.6
2019-03-28 09:03:47.888 [vent.ItemStateChangedEvent] - systeminfo_computer_openHABianPi_cpu_load changed from 5.7 to 5.2
2019-03-28 09:03:47.892 [vent.ItemStateChangedEvent] - Raspberry_CpuLoad changed from 5.7 to 5.2
2019-03-28 09:03:47.934 [vent.ItemStateChangedEvent] - systeminfo_computer_openHABianPi_sensors_cpuTemp changed from 59.6 to 59.1
2019-03-28 09:03:47.937 [vent.ItemStateChangedEvent] - Raspberry_SensorsCpuTemp changed from 59.6 to 59.1

and ervery sceond ther is a new entry. But I donĀ“t want them.

Have you tried this?

log:set warn smarthome.event

The source of the logs are not directly from org.openhab.binding.systeminfo. If you want to keep the state of the systeminfo_computer_openHABianPi_cpu_load Item changing every second, but donā€™t want the event.log logging for it, you can do what Peter suggested, or check out this postā€¦

Gents, i dont see content for Zwave debug using this:

any thoughts?


### Custom Appenders ###
# ZWave
log4j2.logger.zwave.name = org.openhab.binding.zwave
log4j2.logger.zwave.level = TRACE
log4j2.logger.zwave.additivity = false
log4j2.logger.zwave.appenderRefs = zwave
log4j2.logger.zwave.appenderRef.zwave.ref = zwave
log4j2.appender.ZWave.name = ZWAVE
log4j2.appender.ZWave.type = RollingRandomAccessFile
log4j2.appender.ZWave.fileName = /var/log/openhab2/ZWave.log
log4j2.appender.ZWave.filePattern = /var/log/openhab2/ZWave.log.%i
log4j2.appender.ZWave.immediateFlush = true
log4j2.appender.ZWave.append = true
log4j2.appender.ZWave.layout.type = PatternLayout
log4j2.appender.ZWave.layout.pattern = %d{dd-MMM-yyyy HH:mm:ss.SSS} [%-5.5p] [%-50.50c] - %m%n
log4j2.appender.ZWave.policies.type = Policies
log4j2.appender.ZWave.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.ZWave.policies.size.size = 10MB
log4j2.appender.ZWave.strategy.type = DefaultRolloverStrategy
log4j2.appender.ZWave.strategy.max = 10

Check your capitalization as compared with the one in the toubleshooting doc,

log4j2.logger.Zwave.name = org.openhab.binding.zwave
log4j2.logger.Zwave.level = DEBUG
log4j2.logger.Zwave.additivity = false
log4j2.logger.Zwave.appenderRefs = Zwave
log4j2.logger.Zwave.appenderRef.Zwave.ref = ZWAVE
1 Like

thanks mark!! I used an example from this thread, which was wrong

Thank you all my logging files are now reduced from a wild torrent into a static lake.
Even understand how to re-open the flow or add missing statement; to be honest just an ordinary TECP
Thinks this method might be even mentioned at this point of the documentation (but in this case leave this discusion to the experts).

Can now concentrate on a error which was lost in the waves:

[ERROR] [org.eclipse.lsp4j.jsonrpc.RemoteEndpoint          ] - Internal error: java.lang.IllegalArgumentException: URI has an authority component

But this is off topic so not asking to investigate this error, but sharing a know solution is off course very much welcome.

Solved: My URI ERROR was caused by settings of VSCode + Openhab extension see further post. Hope this is helpfull.

Hi all,

Iā€™ve installed the Spotify Connect binding and it logs the song progress every second, so I would like to set the binding to WARN level.

So I updated the org.ops4j.pax.logging.cfg with these lines at the bottom:

# Custom Log Levels
log4j2.logger.org_openhab_binding_spotify.name = org.openhab.binding.spotify
log4j2.logger.org_openhab_binding_spotify.level = WARN

The binding however still logs the output every second (frontail)

Is there something Iā€™m missing?

My Pi is running headless so I donā€™t think I can run Karaf to set the log levels there.

Thanks in advance

The binding isnā€™t logging that every second. You are looking at events.log. events.log is the EventBusā€™s log. It logs all events that get put on the EventBus (except for updates). The song progress Item is changing every second so that getā€™s logged to events.log. There is a way to filter out those lines from the events.log using openHAB - Filtering event logs. However, IMHO, you may as well just turn off events.log before neutering it by selectively filtering out events. Either itā€™s a log of the events or itā€™s not.

Once again a quality answer, thank you Rich.

openHAB - Filtering event logs looks like it will do the trick.

Is it possible to use something from the openhab.log in a rule to send me a message one this particular event occurs?
ItĀ“s a WARN message and not a item change in the events.log

kind regards
Michael

Take a look at the logreader binding.

1 Like

Thanks Mark!
I searched anywhere but not for a binding :smiley:

Hey there =)

I am having issues with setting up the configuration file so that only some bindings show their log entries. Currently my log looks something like this

2020-03-29 19:06:50.556 [vent.ItemStateChangedEvent] - NanoleafBrightness changed from 0 to 100
2020-03-29 19:06:51.391 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 23.0 to 24.0
2020-03-29 19:06:52.448 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 24.0 to 22.0
2020-03-29 19:06:53.517 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 22.0 to 23.0
2020-03-29 19:06:54.593 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 23.0 to 34.0
2020-03-29 19:06:55.649 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 34.0 to 22.0
2020-03-29 19:06:56.760 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 22.0 to 67.0
2020-03-29 19:06:57.801 [vent.ItemStateChangedEvent] - LatencyAsterix changed from 67.0 to 18.0
2020-03-29 19:06:58.808 [vent.ItemStateChangedEvent] - RasperryMemoryUsed changed from 747 to 746

In this example you can see that the network binding produces many entries. So I want to mute it. I tried to copy the configuration of the first entry but it didnt seem to work.

If i enter

log4j2.logger.smarthome_event_ItemStateChangedEvent.name = smarthome.event.ItemStateChangedEvent
log4j2.logger.smarthome_event_ItemStateChangedEvent.level = WARN

in the config file all ItemStateChangedEvents dont show up. However I didnt manage to muti only some bindings. I tried

log4j2.logger.org_openhab_binding_network.level = WARN
log4j2.logger.org_openhab_binding_network.name = org.openhab.binding.network

However this didnt change anything.

I want to mute the Spotify and the network binding. Can someone please show me how the configuration has to look like.

Thanks!

The example is showing ItemStateChangedEvent , I think these are logged by openHAB core (the event bus) not the binding, rule, or UI that caused the event.

Tinkering with binding logging therefore will not affect that.

What problems does this cause you?

Yes youā€™re right.
My question is if I can deactivate those ItemStateChangedEvent entries for some bindings. So for example I want to get the ItemStateChangedEvent entries from my weather binding and want to not get the ItemStateChangedEvent for the network or the spotify binding.

By now I understand why this didnt help me.

Do you understand my question and what I am trying to accomplish?

No, because they are events on the event bus, whatever source put them there. The binding is not involved in this logging.

Yes, but Iā€™ve no idea why you want to do it. What terrible pain does it cause you?

You could maybe look at this post above for suppression by keyword, perhaps you missed it

This was exacly was I looking for :heart_eyes:

For creating the regex you can use a site like this https://www.regextester.com/

log4j2.appender.event.filter.regex.type = RegexFilter
log4j2.appender.event.filter.regex.regex = .* (Latency|TrackProgress|Liedfortschritt).*
log4j2.appender.event.filter.regex.onMatch = DENY
log4j2.appender.event.filter.regex.onMisMatch = ACCEPT

Hi, very helpful discussion here.

Continuing the same topic with a specific twist.

I have a openhab with rules on jython. And I find it a bit frustrating, that I need to actively look for errors in several logs files I have.

Can we come up with some appender configuration, which would filter only failure and error related messages? I would like to have this appender create a file per day, so then it would be very easy to see if my system was producing any errors that day.

So basically selecting parts of texts which were originated by errors, exceptions, failures etc. And it would be great not only to select only the line, but all the relevant text, like this:

13:01:27.902 [ERROR] [sr223.jython.Heating NORMAL schedule] - Traceback (most recent call last):
File ā€œ/etc/openhab2/automation/lib/python/core/log.pyā€, line 51, in wrapper
return fn(*args, **kwargs)
File ā€œā€, line 169, in heating_load_new_targets
File ā€œā€, line 58, in orchestrate
File ā€œā€, line 108, in load_d_variables
KeyError: ā€˜varsā€™

Well, the first question is why do you have multiple files to look through? If having them in multiple files is a problem, put them into one file. By default you would only have two log files, openhab.log and events.log and errors and warnings never appear in events.log.

For one, thatā€™s not how log4j works. It doesnā€™t save up stuff and produce a file at the end of the day. When a log statement occurs, it gets written out.

Secondly, log4j works by giving each part of the code, libraries, your Rules, bindings, stuff in the core, itā€™s own log name. Then you can configure what gets actually written out where based on log level. It is possible to create a filter for a given logger to suppress certain log statements.

Therefore, to achieve what you are after and to preserve the logs as they exist now you basically need to do a copy/paste/edit of the entire log4j config and create a separate appender and set them up to additionally log out to this new appender just errors and warnings.

But in order to understand a given error you often need the context that is logged out at the INFO or DEBUG level immediately before the error. I donā€™t see how this could do anything but make it harder to debug a problem.

If all you want is to know whether or not errors occurred: grep 'ERROR\|WARN' openhab.log will give you a list of all the errors. You could create a cron job that runs grep 'ERROR\|WARN' | count and curls that to an OH Item every night. Thatā€™s the ā€œnumber of errors previous dayā€ count. When itā€™s not zero you know you have a problem to debug, open openhab.log and search for the ERROR. Then you get to see the error in context and from there solve it.

Your proposal would result in just yet another file you will need to look at and search through in order to find errors.