openHAB - Filtering event logs

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

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:

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 

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
1 Like

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…

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

1 Like

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
1 Like

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…

Does anyone know how to filter openhab.log?

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

Tried that. Doesn’t work.

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.

3 Likes

I thought I had a fix by using NEUTRAL instead of ACCEPT for the first filter, which seemed to work initially but that didn’t work out either. So back to using Marvin_Autonomous’ solution.

Did you ever figure this out for openhab.log ? I can’t seem to get this to work for that log file…

Kind of, what do you want to do?

I think I managed to figure something out. I could not get the filtering approach to work to filter out some recurring warning messages in the openhab log. I tried setting the root logger to ERROR and it took care of it. Not ideal but will avoid flooding my logs for now.

I am having the same problem trying to filter out Errors from the Openhab.log

This tutorial only seems to be for Events.log

I just want to stop these messages appearing in the openhab.log

> 2019-02-01 14:52:10.081 [ERROR] [sciani.connector.MyHomeJavaConnector] - Monitor connection problem. Attempting retry 2.
> 2019-02-01 14:52:10.081 [ERROR] [sciani.connector.MyHomeJavaConnector] - Monitor connection problem. Attempting retry 2.

In the file:
/srv/openhab2-userdata/etc/org.ops4j.pax.logging.cfg
There is a section for each log file
Modify the section for openhab.log the same way as the examples above

This is what I’ve tried but it does not seem to work? Am I in the correct section

Rolling file appender

log4j2.appender.out.type = RollingRandomAccessFile
log4j2.appender.out.name = LOGFILE
log4j2.appender.out.fileName = ${openhab.logdir}/openhab.log
log4j2.appender.out.filePattern = ${openhab.logdir}/openhab.log.%i
log4j2.appender.out.immediateFlush = true
log4j2.appender.out.append = true
log4j2.appender.out.layout.type = PatternLayout
log4j2.appender.out.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j2.appender.out.policies.type = Policies
log4j2.appender.out.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.out.policies.size.size = 16MB

#log enhancement
log4j2.appender.out.filter.btcino.type = RegexFilter
log4j2.appender.out.filter.btcino.regex = = .*Monitor connection problem*
log4j2.appender.out.filter.btcino.onMatch = DENY
log4j2.appender.out.filter.btcino.onMisMatch = ACCEPT

This is yours:

log4j2.appender.out.filter.btcino.regex = = .*Monitor connection problem*

This is the example:

log4j2.appender.event.filter.smappee.regex = .*power_smappee.*

See the difference?

1 Like