Combine Accept and Deny RegexFilter possible?

Hello everyone,
is it possible in Openhab 3 to combine multiple filters?
I want to filter all events of a specific binding to a special logfile.

		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/novelanevent.log" filePattern="${sys:openhab.logdir}/novelanevent.log.%i" name="NOVELANEVENT">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
			<RegexFilter onMatch="ACCEPT" onMismatch="DENY" regex=".*(Waermepumpe).*"/>
			<Policies>
			<OnStartupTriggeringPolicy/>
			<SizeBasedTriggeringPolicy size="8 MB"/>
			</Policies>
		</RollingRandomAccessFile>

Currently I do this based on the Item name in the regex filter.
This seems to work. But is it possible to log the ItemStateChangedEvent (which is also in the NOVELANEVENT AppenderRef) based on the binding names?

And is it possible to combine multiple filters? For example I want to see all log messages for the binding except for 2?
I thougt maybe something like this:

			<RegexFilter onMatch="ACCEPT" onMismatch="DENY" regex=".*(Waermepumpe).*"/>
			<RegexFilter onMatch="DENY" onMismatch="NEUTRAL" regex=".*(Waermepumpe_Total|Waermepumpe_Wasser).*"/>

But then the whole logging is not working correctly.

So maybe there is any other possibility to do this?

Thanks in advance

As far as I understand the log4j2 concept of filters the next regex filter in a list of filters is only executed if the previous filters did not return ACCEPT or DENY but NEUTRAL.
That means your first filter always returns either ACCEPT or DENY and thus the second filter will not be executed.
=> try to change the sequence

Like this?

		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/novelanevent.log" filePattern="${sys:openhab.logdir}/novelanevent.log.%i" name="NOVELANEVENT">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
			<RegexFilter onMatch="ACCEPT" onMismatch="NEUTRAL" regex=".*(Waermepumpe).*"/>
			<RegexFilter onMatch="DENY" onMismatch="NEUTRAL" regex=".*(WaermepumpeRuntime).*"/>
			<Policies>
			<OnStartupTriggeringPolicy/>
			<SizeBasedTriggeringPolicy size="8 MB"/>
			</Policies>
		</RollingRandomAccessFile>

If I understand it correctly I have a filter which accepts all log entries which match to Waermepumpe. If it mismatchs it is neutral so the next filter could be applied. This should deny the entries with WaermepumpeRuntime.
But in my Logfile I see all Events. Not only the Waermepumpe related entries.

Ah I found the solution. Thank you for your support


		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/novelanevent.log" filePattern="${sys:openhab.logdir}/novelanevent.log.%i" name="NOVELANEVENT">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
			<RegexFilter onMatch="NEUTRAL" onMismatch="DENY" regex=".*(Waermepumpe).*"/>
			<RegexFilter onMatch="DENY" onMismatch="NEUTRAL" regex=".*(WaermepumpeRuntime).*"/>
			<Policies>
			<OnStartupTriggeringPolicy/>
			<SizeBasedTriggeringPolicy size="8 MB"/>
			</Policies>
		</RollingRandomAccessFile>
1 Like

Ah. But there is still the question if it is possible to filter for the ItemChangedEvent of a specific binding or if I need to rename every Item so it starts with the binding name like MQTT_*** deconz_**** and use this naming to filter some things out. Does anybody know if this is possible without renaming?

Do a trial …
Make a first rule ( beofore the other ones ).
Make this rule an expression that matches everything ( (.*) ) with onMatch=“ACCEPT” onMismatch=“NEUTRAL”.
This should put everything into that file. In case the event is in that you are looking for as well it should be possible to additionally catch that event.

Then replace the first rule with:

onMatch="ACCEPT" onMismatch="NEUTRAL regex=".*bindingnamehere.*ItemChangedEvent.*"

It might be possible that the PatternLayout part needs to be changed in a way that the binding name appears in the logging ( in case it not does already ).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.