Is there a way to clear the log while openhab is running? I have just deleted and that mostly works but a few times it didn’t start logging again so I had to reboot the whole computer. During experimentation it gets rather large.
The logback config file allows you to restrict log file sizes etc. For example I have my Z-Wave log rotating daily and only keeping that last 2 days files to prevent them getting too big.
That should work for me. Where do I find the logback config file?
The logback.xml file that I have is in openhab/configurations. I’m pretty sure this is the one that is being used as I added a suggested section to separate my ecobee logging and that has been working. Anyway I don’t see anything that would allow me to limit the size of the file. I do see the that reference file size.
Have you had a look at the logback documentation? It is very thorough with examples and detailed explanations. Google is your friend ;).
http://logback.qos.ch/manual/appenders.html#RollingFileAppender
Whilst Google is indeed a friend to all of us, the documentation to logback and openHAB is not quite as friendly.
The openHAB docs on logging are very vague and outdated. They were referring to files and locations that I thought had changed. But it isn’t a change, it is a difference in locations depending on the way you install it.
I have just updated the wiki so it now correctly points people to the right location for both manual installs and apt-get
Though it doesn’t tell me where the request.log is coming from?
(I also urge everyone to please if you spot something is incorrect on the wiki, to please click the “edit” button and make the correction. There is no need to request it be changed, all changes are tracked and the whole concept of a wiki is that if you do make a mistake someone else will hopefully correct it)
The machine written logback documentation is not very approachable at all. Especially for a beginner.
I would rather not have to start reading the entire logback docs to learn the entire ins and outs of the project in order to work out a configuration.
I am trying to use a maxfilesize trigger but am failing to get it to trigger.
I doubt there would ever be a reason for me to have to look at a log file archived in a zip from 30 days ago in order to debug something.
So ideally I would have the log break into files every 250KB and only keep 2 or 3.
The constant log writing on a SD is very bad for it, and I have twice had to rebuild by Pi because the log was constantly writing to the point where the Pi froze and I had to pull the power out. It wouldn’t boot up after that.
Granted the log was reporting an error from one of my rules that just kept looping, but I wouldn’t of expected the log files to keep filling up the card to the point where it wouldn’t work.
I have since made the logs folder to be written to ram only with a max size of 2mb. I am also running it of an external USB rather than the SD from tips found here Raspberry Pi: Extending the life of the SD card
Also through my friend Google I have tried multiple configurations and from this post on stackoverflow this is my latest:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>openhab.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${openhab.logdir:-logs}/openhab.%i.log</fileNamePattern>
<maxHistory>2</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>250KB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%-30.30logger{36}] - %msg%n</pattern>
</encoder>
<prudent>true</prudent>
</appender>
Which gives me nothing
Prior to that I tried variations
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${openhab.logdir:-logs}/openhab.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${openhab.logdir:-logs}/openhab-%d{yyyy-ww}.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>250KB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%-30.30logger{36}] - %msg%n</pattern>
</encoder>
</appender>
Either they didn’t write anything at all or they didn’t rollover.
If anyone can share their logback.xml configs that they have customised and explain a little bit about what happens, that would also be very welcome.
Or if someone could integrate a method where you set variables in the openhab.cfg setting the type of rollover/trigger (history/size/both) and max file size. That would be ideal.
I am all for reading the docs, and encouraging others to solve problems themselves, as it is a very good way to learn. But when the docs constantly raise question after question, each requiring more research and experimentation, a little hand holding would go a long way
Thanks
Ok, I think I have a working logback.xml that will breakup the log file based the size and also it will only keep a custom amount of archives.
A key discovery was that “fileNamePattern” doesn’t just define the file name pattern.
It also is used to define the scope of the rollover.
So when I was using openhab-%d{yyyy-ww}.log.zip
thinking it would just name the file with the date, which i didn’t have a problem with. The %d
part was actually the thing tells logback to “roll this over every day”
It is very confusing and illogical that a verbose logging system like Logback would then hide the controlling variable within something that appears to only affect the filename. Rather than use a separate attribute. Oh well
Using FixedWindowRollingPolicy below the key bit is you must include %i
in the filename pattern. Or it won’t know how many there are.
The logback.xml config
The code below will keep only 3 versions of the EVENT and OPENHAB log, and breaks the log into separate files every 250KB.
Resulting in…
openhab.log
openhab.1.log
openhab.2.log
openhab.3.log
Each file is around 250KB, and when it is time to rollover again, version 3 gets bumped off as they shuffle up one.
You can change these with the minIndex, maxIndex and maxFileSize values.
Note that you must include the measurement e.g. 10KB, 500KB, 7MB, 500MB, 1GB
I hope this helps others who want to tame that beat that is “the log”
enjoy
The full file can be found in a Gist here
Slight edit of the pattern for the log entry as the date and time were not included, they are now. (28th Sept 2015)
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${openhab.logdir:-logs}/openhab.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${openhab.logdir:-logs}/openhab.%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>250KB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="EVENTFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${openhab.logdir:-logs}/events.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${openhab.logdir:-logs}/events.%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>250KB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
I must say that this is pretty darn cool!!!
I have preached the configurability of logback to other projects, and this built in log rotation and naming is the icing on the cake!
This begs the question… could someone (ie: @ben_jones12) integrate such rotating log files into the core configuration? Obviously various people would want different things, but something generic like weekly or monthly rotations which could be easily changed would probably suit most peoples needs; as well as providing a working example for people to hack as they need.
Just be careful when fooling around with the logback.xml. I managed to do something wrong and ended up with a whole lot of .tmp files (10,000 plus of them) that literately filled up my very large hard drive the other night. I barely was able to recover, good thing for ubuntu 14.04 having some alternate boot abilities I guess for just these types of problems.
The logback.xml
that ships with openHAB already has a rolling log appender configured which rolls over the openhab.log
and events.log
every week, and keeps the last 30 weeks worth of logs.
See here;
https://github.com/openhab/openhab/blob/master/distribution/openhabhome/configurations/logback.xml
… and what do you know, when I go and have a look at my logs, I do have
29 zipped log files plus the active one.
Simply astounding!
Cheers
Greg Eva
geva@ge-volution.eu geva@ge-volution.eu
www.gE-volution.eu
France : +33 4 81 68 09 64
Canada : +1 226 476 1192
iNum : +833 51 00 09 90 28 81