How to get historic errors from log file

In oh console I can access the log files by log:display
But how can I print all WARN, ERROR, FATAL entries let’s say of the past 5 days?
I searched for a few hours but am not able to find any hint.

Could somebody please guide me in the right direction?

Connect to your openhab environment and have a look into the log files directly, as explained here

That does not answer my question. The question was how to access HISTORIC log data (those which are stored in the standard log directory of the PAST 5 days or so.
log:display (which I have already mentioned in my first post and which you are referring to) only returns the last few hours

I don’t think @Matze0211 is. Check the link again. The first subsection, before the console is even mentioned, tells you where the log files are located so you can access them directly, and interrogate with your favourite method.

I have not referred to log:display, I have referred to the log files that are physically stored on the harddisk of your openhab installation. Both is explained in the article that I have linked.
If you take a look into the log folder, you will see that there is not only an openhab.log file but also rolling logfiles with even older log entries.

Not sure for karaf log:display, but e.g. on fronttail you can configure the default amount of lines to show in the GUI.

But if you want to go back several days, for performance reasons it is maybe best to have a look into the file itself directly.

then I still probably do not see the forest for the trees.

log:display -l WARN only shows warnings of the past FEW HOURS, as it just reads OPENHAB.LOG and EVENTS.LOG.
This command does NOT show you the log entries of the past DAYS, which are stored in events.log.1 2 3 4 5 6 7 and openhab.log.1 2 3 4 5 6 7

Your OP says you want historic data from the log files. @Matze0211 has provided a link on how to get to the log files.

Forget about using the Karaf console. The suggestion here is to directly interrogate the log files themselves.

As already stated in my post above I am already aware where the files are and that historic log files are kept in that directory

the question still remains if there is a command which prints all entries WARN, ERROR, FATAL from all files.
The question was not where I can find those files. And it does not solve my task to manually walk through those files.
If it does not work with log:display then the solution probably is a kind of bash script which iterates through all files and greps all warnings. If this is the case then I am interested in that command as I guess somebody already had that task as well

In your initial post it was not clear that you are aware of the log folder.

Reading your last posts gives the impressing that you want to change the config of log:display and not want to know about log files in general.

If you have a question about log: display and the karaf console itself, maybe ask your question here

OMG…
My OP was

we all know that in openhab.log and events.log there are entries of just the last couple of hours so it should be clear that we are talking about archived log files, too (events.log.1 2 3 4 5 6 7, openhab.log.1 2 3 4 5 6 7)

I am just talking about a little help what the correct syntax of either log:display is (ok. understood, it does not have the option to include historic files) or any other command like cat grep whatever.

:slight_smile: it is getting funny now. I am not asking for log:display support.

But thank you anyway for your help

I think you almost have it yourself Oliver… I tried

cat /var/log/openhab/openhab.log | grep ERROR

and get all the errors in that file. I think you can use a wildcard to get all the files in the directory
edit: yup…

cat /var/log/openhab/*.log | grep ERROR

thanks. probably I have to write a bash script like

cat /var/log/openhab/openhab.log | grep ERROR
cat /var/log/openhab/openhab.log.1 | grep ERROR
cat /var/log/openhab/openhab.log.2 | grep ERROR
...
cat /var/log/openhab/openhab.log | grep WARN
cat /var/log/openhab/openhab.log.1 | grep WARN
cat /var/log/openhab/openhab.log.2 | grep WARN
...

which will result in a script with 8 x 3 x 2 = 48 lines :slight_smile: I am sure there is a one liner available with some foreach instruction to cycle through all log files. For that my little linux experience is not good enough. As said, maybe somebody else already had that requirement too and already found a solution.
Thanks for your constructive help.

cat is not required. See Useless Use of Cat Award
To have it all in one command would be something like:

cd /var/log/openhab; egrep "WARN|ERROR|FATAL" openhab.log openhab.log.[1-9] events.log events.log.[1-9]

This does not include the compressed log files.

1 Like

Hey Wolfgang,
you’re a star :slight_smile:
I would probably have had to spend tens of hours to dig into linux cli to get somewhere close to that solution.

Very elegant! thank you very much!

1 Like

this also works with compressed logs

 zgrep -e ERROR -e WARN /var/log/openhab/openhab.log* | sed 's/^[^:]*://g' | sort
2 Likes

even better :slight_smile:

OK… Wolfgang made me lolz :laughing:
best is at the end for kill -9
Don’t bring out the combine harvester just to tidy up the flower pot.

and just to add… jeeezzz there are a bunch of errors in there I never noticed