openHAB - Filtering event logs

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

Yes I tried that one before but I assumed that is just filtering from the event.log because it did not work

And that?
= = ??

ah!!

ah!! indeed… Does is work?

just testing!

Yes this works thanks for your help! I’m still not too clear on the regex pattern matching - I can’t find a good site that explains exactly how it works with wildcards but for now this is fine.

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

I find this site to be of great help in testing regex. Put in your regex pattern and then copy/paste a chunk of your event.log. Note that I’m not sure how much you can paste into the text box.

https://www.freeformatter.com/java-regex-tester.html

I can’t get the log4j2 regex filter work on my events.log file. I’m running OH 2.5.0 M1 on openhabian.

I added the following 4 lines at the end of /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg

log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .*(Astro_(Sun|Moon|Civil|Nautic|Astro|Noon|Morning|Evening)|Wx_OWM_(Current|Forecast)|openweathermap_(weather_and_forecast|uvindex)).*
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

I tested the regex online and it shows the matches on the sample input I provided.
When I restart openhab2, then I see the event log lines matching the regex are still logged in /var/log/openhab2/events.log.
What am I doing wrong?

EDIT: it now works

Hi, please can someone help me? MY configuration is not working:

Here are my errors/warnings i want to remove from openhab.log:

2019-03-06 15:51:07.240 [WARN ] [.binding.knx.internal.bus.KNXBinding] - Value '167310.0' could not be sent to the KNX bus using datapoint 'command DP 4/3/1 HeatPump_Stromzaehler, DPT main 0 id 12.001, low priority' - retrying one time: 12.001 Unsigned count: wrong value format: 167310.0

2019-03-06 15:51:07.240 [ERROR] [.binding.knx.internal.bus.KNXBinding] - Value '167310.0' could not be sent to the KNX bus using datapoint 'command DP 4/3/1 HeatPump_Stromzaehler, DPT main 0 id 12.001, low priority' - giving up after second try: 12.001 Unsigned count: wrong value format: 167310.0

And here is my pax4j-logging-config:

################# KNX Fehler ausbelenden ###########
# Filtering Rules
log4j2.appender.event.filter.KNXremove.type = RegexFilter
log4j2.appender.event.filter.KNXremove.regex = .*could not be sent to the KNX bus using datapoint.*
log4j2.appender.event.filter.KNXremove.onMatch = DENY
log4j2.appender.event.filter.KNXremove.onMisMatch = ACCEPT
#####################

If you want to filter openhab.log, don’t you want this to be

log4j2.appender.out.filter.KNXremove.type = RegexFilter
log4j2.appender.out.filter.KNXremove.regex = .*could not be sent to the KNX bus using datapoint.*
log4j2.appender.out.filter.KNXremove.onMatch = DENY
log4j2.appender.out.filter.KNXremove.onMisMatch = ACCEPT
1 Like

I changed event to out, but the errors and warnings still appear in my openhab.log.

Since when does it not work for you (anymore). Maybe I currently have the same problem:

Hmm. Then I’m not sure what’s going on.

I have the same problem. I guess I have the right logging settings (see below), but without effect. Actually the logs don’t even confirm that the logfile has been re-read, but I’m not sure if that is logged (if not, it should).

log4j2.appender.event.filter.CurrentCost.type = RegexFilter
log4j2.appender.event.filter.CurrentCost.regex = .*CurrentCost_xml. (there is a star after the point, but it is filtered out by the editor…)
log4j2.appender.event.filter.CurrentCost.useRawMsg = false
log4j2.appender.event.filter.CurrentCost.onMatch = DENY
log4j2.appender.event.filter.CurrentCost.onMisMatch = ACCEPT

Only thing that could be are the camel case. Try currentcost instead of CurrentCost.

It’s unfortunately not.