External "logbook/event log" - file for specific item states recording

  • Platform information:
    • Hardware: Raspberry Pi4
    • OS: Openhabian
    • openHAB version: OH2.5.2

I searched the search engine for the words “logbook” and “event log” but I found nothing. Probably because the “event log” is throwing out a lot of OH service related results, but that’s not what I’m looking for.

Dear friends, I would like a few items available in OH to be collected and saved for a period of, say, 1 year.
It would be best if it was a separate file from which I can read that the door was open 2022-01-24 09: 58: 21.256, the light was turned on 2022-01-24 09: 59: 25.483 and then the door was closed 2022-01-24 09: 59: 55.483 . Similarly as it can be read in the event log of alarm control panels.
Will you suggest what I am looking for or how can I organize it?
Can this be achieved by creating some rule “if item changed then writedowntosomefile” but not to delete previous entries?

Have a look here inside the documentation.
Especially the part on Log4j configuration and logging into separate files.

Look into persistence services, where you can store your items historical values into a database.
That’s maybe better than just logging, as you have much more options to reuse the data than only creating a text file

This smells like an XY Problem.

If all you really want is to be able to see specific log entries see How to watch and look through logging. There are all sorts of ways to watch and extract logging for specific Items without changing anything about how it logged in the first place.

As Matthias suggests, maybe persistence and charting is a better approach to see what you are after.

If you really need these in a separate file for some reason, you could configure log4j2 to log out some Item events to another file but it will require modifying the existing config for events.log to no write out those Items and a completely separate logger config to only write out those Items. You’ll have to get good at log4j2 config and regular expressions since you’ll need a filter to identify those entries to long and not log. events.log logs out the events on the event bus itself, it doesn’t have a separate logger for each and every Item. See openHAB - Filtering event logs (note these need to be translated to XML on OH 3).