Anybody knows a simple solution to get event logs into different log files corresponding to item?
e.g. for the two log lines below, I’d like to have the events for each of the items in its own log file.
2022-01-02 19:31:31.573 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Systeminfo_CPU_Load1' changed from 0.5 to 0.9
2022-01-02 19:31:31.574 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Systeminfo_CPU_Uptime' changed from 57897.8 to 57902.8
Actually, the idea is to get noisy items into their own event log.
If there is no other solution, I guess for this to work one would have to add a context as input for a log4j2 Route.
with itemID parsed from event.getPayload()
An ready way? No. log4j configured logging based on the code running. In this case the code running is the event bus. You can move all the item events to a different file but not just those for a single Item.
You could set up a a separate logger that logs for events.log and then set up a regex filter to only log those entries that match a given pattern. There are tourism’s on the forum for seeing that up. But it’s going to be a whole lot of config.
Personally, if it’s worth while logging any items, it’s worth while logging all the items. Frontal, grep, etc all have great ways to filter a log file to only see what’s relevant.
Yes, but I do not want to filter, I’d like to distribute log events to different log files. I could that do that of course somehow with tail and grep, but it would be nice have it done by log4j.
And log4j2’s way to distribute to different log files is Routes. Maybe I try to play with the context IDs.