Merge/synchronize events.log and openhab.log

When I try to debug some rule in openHAB, I often need the logs from events.log and openhab.log.
But it is often annoying to “synchronize” these logs afterwards.

events.log:

2022-01-27 12:20:28.185 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestItem1' changed from OFF to ON
2022-01-27 12:21:01.016 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestItem1' changed from ON to OFF

openhab.log:

2022-01-27 12:20:44.386 [INFO ] [penhab.core.model.script.Media_Scene] - TestRule executed

My goal is one file where all messages are listed chronologically.

2022-01-27 12:20:28.185 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestItem1' changed from OFF to ON
2022-01-27 12:20:44.386 [INFO ] [penhab.core.model.script.Media_Scene] - TestRule executed
2022-01-27 12:21:01.016 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestItem1' changed from ON to OFF

You can achieve this with this little shell command:

sort -nbms -k1.1,1.4 -k1.6,1.7 -k1.9,1.10 -k1.12,1.13 -k1.15,1.16 -k1.18,1.19 -k1.21,1.23 events.log openhab.log

I created a simple script to generate a new file with the current timestamp.

_merged_logs.sh:

#!/bin/bash

sort -nbms -k1.1,1.4 -k1.6,1.7 -k1.9,1.10 -k1.12,1.13 -k1.15,1.16 -k1.18,1.19 -k1.21,1.23 events.log openhab.log > _merged_logs_$(date "+%Y%m%d-%H%M").log

source:

real time synchronization

If you want to view the logs synchronized in real time you can use multitail.

# one top, one bottom
multitail events.log openhab.log

# synchronized
multitail events.log -I openhab.log

# synchronized, two colors
multitail -ci red events.log -ci yellow -I openhab.log

For cool syntax highlighting see:

3 Likes

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