openHAB - Filtering event logs

Sure it is… if you have your logging levels set do that you can see it :wink:

2019-03-15 17:10:21.681 [INFO ] [org.apache.felix.fileinstall] - Updating configuration from org.ops4j.pax.logging.cfg
1 Like

Ok, it’s unfortunately not per default, but: mea culpa! :blush:

Hi All,

I too am strugglign with these using the examples here.

Trying to filter the console log with:


log4j2.appender.event.filter.floodstop.type = RegexFilter
log4j2.appender.event.filter.floodstop.regex = .*(OpenHAB|UPS|yamahareceiver).*
log4j2.appender.event.filter.floodstop.onMatch = DENY
log4j2.appender.event.filter.floodstop.onMisMatch = ACCEPT

Trying to remove this:

08:25:05.705 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Memory_Used_Percent changed from 16.1 to 16.2
08:25:05.711 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Cpu_SystemUptime changed from 2156.5 to 2157.5
08:25:05.713 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Sensors_CpuTemperature changed from 39.0 to 38.0
08:25:05.715 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Cpu_Load changed from 1.4 to 1.2
08:25:05.717 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Memory_Available changed from 13405 to 13402
08:25:05.718 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Memory_Available_Percent changed from 83.9 to 83.8
08:25:14.808 [INFO ] [smarthome.event.ItemStateChangedEvent] - UPS_Battery_Runtime changed from 1068 to 1109

Are you putting your filters right after the “# Event log appender” section, or are they at the very end of the file?

I think I had to locate the Regex filters right after that section to get it to work. Similarly, I think I didn’t get openhab.log filters to work until I put them right after the “# Rolling file appender” section.

2 Likes

for me this is working .
Added following entry EOF
pi@homepi:~ $ nano /var/lib/openhab2/etc/org.ops4j.pax.logging.cfgusing


log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .(Astro(Sun|Moon|Civil|Nautic|Astro|Noon|Morning|Evening)|Wx_OWM_|weather|forecast|uvindex|localforecast|System_openHAB|Swap_|CPU_Load|Network_PacketsSent|CPU_Uptime changed|System_CPU_Uptime|CPU_Threads|Network_Packets|Sun_Elevation|Moon_Elevation|Storage_Used).
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

using the following setup:

log4j2.appender.event.filter.trackProgress.type = RegexFilter
log4j2.appender.event.filter.trackProgress.regex = .trackProgress.
log4j2.appender.event.filter.trackProgress.onMatch = DENY
log4j2.appender.event.filter.trackProgress.onMisMatch = ACCEPT

I have been able to filter out the spotify trackprogress events from the events.log file but these events still appear in the log:tail output.

How could I filter out the trackprogress events from the log:tail?

1 Like

I posted this already some time ago, but now I tried once again to filter out of events.log all ItemStateChangeEvent messages that contain the text CurrentCost. For this, I tried with the following text:

log4j2.appender.event.filter.CurrentCost.type = RegexFilter
log4j2.appender.event.filter.CurrentCost.regex = .*CurrentCost_xml.*
log4j2.appender.event.filter.CurrentCost.onMatch = DENY
log4j2.appender.event.filter.CurrentCost.onMisMatch = ACCEPT

I also tried with small case (currentcost instead of CurrentCost) but same non-effect.
I added this after the event log appender section of org.ops4j.pax.logging.cfg, as @rpwong suggested, but without success. Any more ideas?

Can you post an example of the message you’re trying to filter out?

This is the text I am trying to filter out this:
2019-05-22 22:04:19.621 [vent.ItemStateChangedEvent] - CurrentCost_xml changed from <msg><src>CC128-v1.48</src><dsb>01917</dsb><time>20:17:58</time><tmpr>23.9</tmpr><sensor>0</sensor><id>00079</id><type>1</type><ch1><watts>00399</watts></ch1></msg> to <msg><src>CC128-v1.48</src><dsb>01917</dsb><time>20:18:04</time><tmpr>23.9</tmpr><sensor>0</sensor><id>00079</id><type>1</type><ch1><watts>00399</watts></ch1></msg>
It is the item measuring energy consumption (besides temperature), and since it is updated every 5 seconds, I don’t like to fill up my logs with this.

Hmm, I’m not sure. For reference, here’s what mine looks like:

# custom filters for events.log
log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .*(string 1|string 2|etc).*
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

Nothing jumps out to me as being significantly different, aside from me using brackets to contain multiple strings.

The only other thing I can think of is to clean your cache and restart, but I’m just guessing.

You need a capturing group…

log4j2.appender.event.filter.CurrentCost.regex = .*(CurrentCost_xml).*
1 Like

I wondered about that, but other examples in this thread only use brackets when there are multiple strings.

Thank you @5iver and @rpwong for your efforts. However, having brackets showed no effect…
Any idea how I can trace the logging mechanism? :slight_smile:

@Aurelio, I am having the same issue, what openHAB version are you on? I am on 2.3.
In my case, I can filter out only 1 thing from the event log. Any other in the list are just ignored.

1 Like

@sl92656, I am using 2.4.0 Release Build.

Unfortunately, not even the main documentation site of log4j2 (https://logging.apache.org/log4j/2.x/manual/configuration.html) explains how such filters are configured in the configuration file. But maybe someone finds out how to log the logger’s activity (without a recursion :slight_smile:

The only other thing I can think of is to go through your cfg file and make sure there aren’t any other lines that are interfering with this. I don’t know how or why that would be the case, though.

1 Like

I used this example for many weeks, but at some point it stopped working from one day to another.
What did I do wrong? Here´s the code:

[ome.event.ItemCommandEvent] - Item ‘wecker_switch’ received command ON
[vent.ItemStateChangedEvent] - temperatur_niko changed from 23.20 to 23.30

.# Custom
log4j2.appender.event.filter.schiss_entfernung_events.type = RegexFilter
log4j2.appender.event.filter.schiss_entfernung_events.regex = .*(received command|temperatur_niko changed from|)
log4j2.appender.event.filter.schiss_entfernung_events.onMatch = DENY
log4j2.appender.event.filter.schiss_entfernung_events.onMisMatch = ACCEPT

To help others to avoid a similar mistake: these filters help you to match against the log message text - and not with other sections of the log line.

Example:

2019-10-06 17:52:07.131 [vent.ItemStateChangedEvent] - Consumption_BR_Computer changed from 52.920 to 43.120

To filter this line you can match any part of the string ‘Consumption_BR_Computer changed from 52.920 to 43.120’ but if you try to match anything from ‘2019-10-06 17:52:07.131 [vent.ItemStateChangedEvent]’ your filter will not work.

I tried to match against ‘ItemStateChangedEvent’ and it took me a while to find my mistake…

For me, the filter shows a strange behavior: It works for some of the keywords (TGraph, OpenhabSystem_), but not for “RFLinkRaw”.

My config:
log4j2.appender.event.filter.uselessjunk.type = RegexFilter log4j2.appender.event.filter.uselessjunk.regex = .*(RFLinkRaw|TGraph|OpenhabSystem_).* log4j2.appender.event.filter.uselessjunk.onMatch = DENY log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

Example log messages which are not being filtered:

2019-10-12 12:00:00.170 [vent.ItemStateChangedEvent] - RFLinkRaw changed from 20;0E;Debug;RTS P1;aaf0f0333f3fcc5566aa;
20;0F;RTS;ID=23f3fcc;SWITCH=01;CMD=STOP;
to 20;10;PONG;

2019-10-12 12:00:23.356 [vent.ItemStateChangedEvent] - RFLinkRaw changed from 20;11;Debug;RTS P1;aaf0f0333f3fcc5566aa;
20;12;RTS;ID=23f3fcc;SWITCH=01;CMD=STOP;
to 20;13;Alecto V5;ID=00d0;TEMP=00d2;RAIN=0000;BAT=OK;

Maybe this is due to the regex filter not working correctly with the new line (“\n”) in the log message?
Can anybody help me?

Edit: Solved by adding a regex filter to the serial binding item RFLinkRaw (to filer out carriage return and new lines).