openHAB - Filtering event logs

configuration
openhab2
logging
Tags: #<Tag:0x00007f212aa6f1b0> #<Tag:0x00007f212aa6f070> #<Tag:0x00007f212aa6ef08>

(Jp Wise) #1

Simple string filtering on the event log. Useful for filtering out high change items that don’t need constant log visibility.

Re-posting this as it’s own thread on the recommendation of other members. I also recommend reading Taming openHAB 2 Logging and Log4j2 Sample Config which this was based on.

Log configuration data using openhabian-pi is stored in the following file. Location may vary under other installation methods.

/srv/openhab2-userdata/etc/org.ops4j.pax.logging.cfg

openHAB using log4j edit the file to add filter rules using the following methodology.

# Filtering Rules
log4j.appender.event.filter.<your-filter-name>=org.apache.log4j.varia.StringMatchFilter
log4j.appender.event.filter.<your-filter-name>.StringToMatch=<your_filter_string>
log4j.appender.event.filter.<your-filter-name>.AcceptOnMatch=false

openHAB 2.2 uses log4j2 with a different syntax.

# Filtering Rules
log4j2.appender.event.filter.<your-filter-name>.type = RegexFilter
log4j2.appender.event.filter.<your-filter-name>.regex = .*(<your_filter_string1>|<string2>|<string3>|<etc>).*
log4j2.appender.event.filter.<your-filter-name>.onMatch = DENY
log4j2.appender.event.filter.<your-filter-name>.onMisMatch = ACCEPT

Replacing <your-filter-name> with a suitable filter name, and similarly <your_filter_string> with the string you want to filter out. In my case I have a Smappee power meter which updates household power consumption on a second by second basis via an MQTT feed. The event data for this just fills the log up, so since upgrading to OH 2.2 have now updated my filter rule to the following.
Shout out to @kintrupf for the regex (OR) example shown in the posts further down and now edited into the example above.

# Jp - filter out stuff
log4j2.appender.event.filter.smappee.type = RegexFilter
log4j2.appender.event.filter.smappee.regex = .*power_smappee.*
log4j2.appender.event.filter.smappee.onMatch = DENY
log4j2.appender.event.filter.smappee.onMisMatch = ACCEPT

power_smappee being the name of my item in my set up. I haven’t tried it yet, but I don’t believe there should be any reason you can’t create multiple filters to filter out different sets of data, similar to the sun, moon astro examples in the linked pages.

DISCLAIMER: I don’t profess to be an expert on regex or log4j, this is just based on my own research, and once set up works well for me. :slight_smile: If it helps you, excellent!, if it doesn’t work, I probably can’t tell you why it didn’t, sorry.

Jp.


Taming openHAB 2 Logging
executeCommandLine() questions
Disable log events
Hide Harmony log message
Howto reduce logging of systeminfo binding?
Implementing Roomba 871 RooWifi solution - how to manage temporarily unreachable
Log specific items into a separate logfile
E3DC with the new modbus binding
Rules logging
How to bind discovery process to one network
SystemInfo Binding: Logging
Exclude broken gcal logging
Another disable logging question. Filter / disable logs
How to set a item log level to warn or error only?
Jointspace Binding filling log
Taming openHAB 2 Logging
Is it possible to remove pointless log warnings
Annoying "Thing ... has been updated" log
[SOLVED] Logging: Change Loglevel for only 1 item
Logging zWave updates
TCP Binding and Transformation (looking for best practice)
Z-Wave & event log = too much information
Enable/disable some infodata in log - Customize Log
(Tony De La Rosa) #2

Can someone provide an example of how I can hide the Astro events in the logs? Not all the Astro log entries contain the phrase “astro.” I thought I needed to provide the module name in order to filter out those events. Currently, I have them filtered out by creating three filter entries; one for astro, Sun, and Moon.

Update: I spoke too soon. it did not work


(scott dee) #4

from my testing you only get one filter, and if you have two, the last one in the file is the one that works.


(Frank Kintrup) #5

I’m no expert, but it seems you can use a more elaborate regular expression to filter on more than one event :slight_smile:
This works for me to filter out all regular events from the ntp, astro and WeatherUnderground bindings.
The ntp bindung defines the item “CurrentDate” and all my WeatherUnderground items start with “Weather”.

# custom filter 
log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .*(CurrentDate|astro|Weather).*
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT


(scott dee) #6

that seems to have done it. thank you!


(Jp Wise) #7

Yeah, regex isn’t my forte. ;p Hadn’t even thought to look into using or clauses in the syntax.


(Marvin Autonomous) #8

Fantastic, this was exactly what I was looking for!!
The structure for the filter expression.
.(anything|anything2|anything3|anything4).
Now I can filter all astro junk like this:
.(Elevation changed from|Azimuth changed from|Diffuse_Radiation changed from|Total_Radiation changed from).
While still not filtering any other things that might have astro in their expression.
Thank you! :smiley:


(Jeff Haskel) #9

I was trying to stop the logreader binding flooding the eventlog also the network binding with

# chod - less flood on the logging - network
log4j2.appender.event.filter.network.type = RegexFilter
log4j2.appender.event.filter.network.regex = .*network.*
log4j2.appender.event.filter.network.onMatch = DENY
log4j2.appender.event.filter.network.onMisMatch = ACCEPT

# chod - less flood on the logging - logreader
log4j2.appender.event.filter.logreaderx.type = RegexFilter
log4j2.appender.event.filter.logreaderx.regex = .*logreader_reader.*
log4j2.appender.event.filter.logreaderx.onMatch = DENY
log4j2.appender.event.filter.logreaderx.onMisMatch = ACCEPT

it looked like the logging for the matching texts stopped but later it continued

i added the lines to

/var/lib/openhab2/etc/org.ops4j.pax.logging.cfg 

Homekit not working properly
(Marvin Autonomous) #10

Try this :slight_smile:

#  chod - less flood on the logging
log4j2.appender.event.filter.floodstop.type = RegexFilter
log4j2.appender.event.filter.floodstop.regex = .*(network|logreader_reader).*
log4j2.appender.event.filter.floodstop.onMatch = DENY
log4j2.appender.event.filter.floodstop.onMisMatch = ACCEPT

(Mihai Badea) #11

Does anyone have a clue on how to set RegexFilter for the karaf console?
I’d like to apply the filter on that too, not only to the Event log appender…


(Angelos) #12

did you try to grep stuff? Not sure if you can use a full RegexFilter on the console. Maybe if you modify the log4j2 config for the console settings?

e.g. log:display |grep … or log:tail |grep …

https://karaf.apache.org/manual/latest-2.x/commands/shell-grep.html


(Mihai Badea) #13

Thanks for the grep idea… I knew about it, but I didn’t think of it.
log:display | grep -v... works, but log:tail | grep -v ... does not… Weird…
But even if it works, looks kinda tedious to enter the command every time I’m watching the console.

I tried setting the console logger with the RegexFilter, but it’s not working - Console appender not used by default (see log4j2.rootLogger.appenderRefs)

# Appenders configuration

# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = STDOUT
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n

log4j2.appender.console.filter.ignore.type = RegexFilter
log4j2.appender.console.filter.ignore.regex = .*(NAS|SystemStatus).*
log4j2.appender.console.filter.ignore.onMatch = DENY
log4j2.appender.console.filter.ignore.onMisMatch = ACCEPT

(E. Gerland) #14

After changing the file org.ops4j.pax.logging.cfg

What is the fastest way to activate it?
It’s obviously not read automatically like rules and such!?

EDIT: Never mind. openhab DOES reload it obviously automatically.
My cfg file was somehow messed up the first time I tried it…


(Vincent Regaud) #15

Does anyone know how to filter openhab.log?


(The Squid) #16

Would you just swap out system for event in the examples above??


(Vincent Regaud) #17

Tried that. Doesn’t work.


(Rich Koshak) #18

OpenHAB - Filtering event logs shows for events.log but could be adapted to openhab.log. oops, that’s this thread. I guess I can’t help except to point out alternatives.

Log4j2 Sample Config shows how to shunt all the logs from a certain binding or part of oh to a separate file.

How to watch and look through logging shows both posix (Linux and Mac) as well as powershell ways to tail logs and filter what gets printed.