Remove Log Source

Hi guys,

Just upgraded from 5.0 to 5.1 and now I am getting the ‘source’ on all the events.

Can I remove this ‘source’ part?

18:34:58.262 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Multi1_Motion’ changed from ON to OFF (source: org.openhab.core.thing$zigbee:device:986908efef:a4c1388e0e613536:A4C1388E0E613536_1_intrusion)

It’s cluttering my logs.

No, not at this time. It’s part of the event. I’m sure an option to turn it on and off could be implemented but there isn’t one now.

I can’t find it now but somewhere someone posted a log4j2 regex filter that removes it at the logging configuration level.

I’ll only add that the source has already helped several users solve otherwise hard to diagnose problems, immediately identifying whether a rule or a Thing or a UI was behaving strangely and in the case of rules exactly which rule was the problem. It wasn’t added “just because”, especially for those experiencing problems knowing where an event comes from is as important as knowing the event occurred in the first place.

That’s fair enough, I fail to see why when it was added it wasn’t added as optional though, not everybody wants a bloated log. If there’s a problem that a ‘normal’ log can’t identify, simply turn on this new extended logging.

This is getting hard to read. Was there a way to apply some coloring in the log, so eyes focus on the important stuff?

In the log reader under Developer Tools? You’ll need to open an issue to request that but it should be possible to add that.

Anywhere else you’ll need to look into how that tool does coordinating and configure it as appropriate. The logger itself doesn’t do any color coding. That’s all implemented by what ever you are using to view the logs.

I think it is already there:

On the bottom of the log viewer, click “Configure highlights”, then for example:

I don’t think that’s what @agrarina is asking for. I understand them to be asking to highlight the whole “(source:…)” part of the line in a different color.

Does the highlight field accept regex?

Yes:

and for those with the same problem as @psych
in log4j.xml the log-appenders are configured… so for events.log as well
if you replace

<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} \[%-5.5p\] \[%-36.36c\] - %m%n"/>

with

<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %replace{%m}{\s\(source:.*\)}{}%n"/>

it will strip the (source: … ) part in the logs

… and also remove important information for troubleshooting :person_shrugging:

which is correct…
however, the ones that are able to implement the change to make logs more readable, are also able to revert it if they need the level of debugging.
I have tail -f for both openhab.log and events.log running full width on a 32” monitor… and the “source-information” will introduce line-breaks even in that setup :face_with_spiral_eyes:
[edit]
it’s as always nowadays with the disclaimers… “use at own risk” :smiley:
or even better… if space and read-write-cycles on a SD-card are of no concern… create a dedicated appender logging to “events-readable.log”

upgraded from 4.3.x to 5.1.x today and struggle over the annoying (source: xxx) in the Logs ^^

have changed my /var/lib/openhab/etc/log4j2.xml which differs namely from your log4j.xml and is does not work…

any chance to get rid from the (source: xxx) Information?

AFAIK all changes in the log4j2.xml is changed on-the-fly - so no restart tested from my side

log4j2.xml is correct… was a typo on my end

for the changes to take effect, I had to restart the logging-engine via KARAF
bundle:restart org.ops4j.pax.logging.pax-logging-log4j2

Thx, for any Reason it don’t works?!? even after reboot the entire Machine

<!-- Rolling file appender -->
		<RollingFile fileName="${sys:openhab.logdir}/openhab.log" filePattern="${sys:openhab.logdir}/openhab.log.%i.gz" name="LOGFILE">
				<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} \[%-5.5p\] \[%-36.36c\] - %replace{%m}{\\s\\(source:.\*\\)}{}%n"/>
			<Policies>
				<OnStartupTriggeringPolicy/>
				<SizeBasedTriggeringPolicy size="16 MB"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingFile>

<!-- Event log appender -->
		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/events.log" filePattern="${sys:openhab.logdir}/events.log.%i.gz" name="EVENT">
				<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} \[%-5.5p\] \[%-36.36c\] - %replace{%m}{\\s\\(source:.\*\\)}{}%n"/>
			<RegexFilter onMatch="DENY" onMismatch="ACCEPT" regex=".*(_Auswahl|_avg|_Blocker|_colortemp|_color|_dimmer|_effect|_Entrance|ESP32_BLE_|_Ext_Temp_Sensor|_lqi|_Nopresence|_onoff|_Ping|prx|_RSSI|_Stellgrad_ist|_Target_Distance|_Temperatur_ist|_Timestamp|_triggered|Tuya_Waschkeller_|_Uptime|_Voltage|_Wifi_Signal|AQI_|Astro_|cp|gBewegung|Helligkeit|Licht_Wohnung|OWM_|PERSON1_WECKER|Spritpreis_|sp).*"/>
			<Policies>
				<OnStartupTriggeringPolicy/>
				<SizeBasedTriggeringPolicy size="16 MB"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingRandomAccessFile>

attached my configuration…

		<!-- Rolling file appender -->
		<RollingFile fileName="${sys:openhab.logdir}/openhab.log" filePattern="${sys:openhab.logdir}/openhab.log.%i.gz" name="LOGFILE">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
			<Policies>
				<!-- <OnStartupTriggeringPolicy/> -->
				<SizeBasedTriggeringPolicy size="10 MB"/>
			</Policies>
			<DefaultRolloverStrategy max="14"/>
		</RollingFile>

		<!-- Event log appender -->
		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/events.log" filePattern="${sys:openhab.logdir}/events.log.%i.gz" name="EVENT">
			<!-- <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/> -->
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %replace{%m}{\s\(source:.*\)}{}%n"/>
			<Policies>
				<!-- <OnStartupTriggeringPolicy/> -->
				<SizeBasedTriggeringPolicy size="10 MB"/>
			</Policies>
			<DefaultRolloverStrategy max="7"/>
		</RollingRandomAccessFile>

events.log is still being created, but “source” info is not removed?
or is the log no longer created with the changed appender?

EDIT:
there are additional “\” introduced when copying code (code-fence mismatch)… it’s

%replace{%m}{\s\(source:.*\)}{}%n"

instead of

%replace{%m}{\\s\\(source:.\*\\)}{}%n"

that’s it! this works :slightly_smiling_face: restart logging with KARAF Console and all (source: xxx) is gone

Many Thx! :handshake:

@all Devs

please consider to add this as Debug Option switchable via WebGUI :innocent: