Taming openHAB 2 Logging

I did. The only difference I can see (for Zwave) is:
Logger: you have INFO and I have DEBUG
Appender: We have different paths because mine installation is apt based

Or am I completely blind? :confused:

Just a guess on my part but I think the problem may be the # OSGi appender section just above your ### Custom Loggers ### section. I think that section was added if you set your zwave binding to debug in Karaf and may be overriding your custom appender. Once again, this is just a guess.

I added @sihui zwave code to the end of my cfg and everything works fine. I also changed the level to DEBUG and the DEBUG info started showing up in my zwave.log file. I do not have a OSGi appender section in my config though, nor did I ever change to DEBUG in Karaf.

Just a thought. :slightly_smiling_face:

2 Likes

Brilliant guess, Bill :grinning: I was about to just copy Dim’s full config and get done with it. Though I was wondering about that additional zwave logger in the osgi section too. Then I saw your post and commented out that logger. Problem solved, thanks! :beer:

1 Like

Just adding this here since I couldn’t find it again after doing it almost a year ago, and the OH2.2 upgrade reverted the /srv/openhab2-userdata/etc/org.ops4j.pax.logging.cfg file.

Simple string filtering on the event log. Useful for filtering out high change items that don’t need constant log visibility.

Prior to OH2.2 - using log4j

# Jp - filter out stuff
log4j.appender.event.filter.smappee=org.apache.log4j.varia.StringMatchFilter
log4j.appender.event.filter.smappee.StringToMatch=power_smappee
log4j.appender.event.filter.smappee.AcceptOnMatch=false

Taken from an example in Log4j2 Sample Config, the following appears to do the same under OH2.2

# Jp - filter out stuff
log4j2.appender.event.filter.regex.type = RegexFilter
log4j2.appender.event.filter.regex.regex = .*power_smappee.*
log4j2.appender.event.filter.regex.onMatch = DENY
log4j2.appender.event.filter.regex.onMisMatch = ACCEPT

There are probably better ways to do it, but for now that works, and excludes the power_smappee (power consumption, changes by the second) from the log files.

Thx.
Jp.

5 Likes

It would be great if you post this as its own thread in Examples and Tutorials. Lots of people have asked for how to filter out events from events.log.

1 Like

Took your advice and split it out into it’s own post. Since I had such a hard time finding the information originally (and after updating with OH2.2 replacing the config file) I don’t doubt you’re right it’s something a lot of people ask for.

New topic is at : OpenHAB - Filtering event logs

It’s pretty straightforward as configuration goes, and hopefully adding the filtering reference to the topic name should help people find it readily enough.

Thx.
Jp.

2 Likes

Side hint: If you change you logging conf and the change does not seem to work, check if the lines you changed have trailing whitespaces ! It took me several hours to figure that out - so I like to save that time to you … :smiley:

1 Like

log4j also seems to privide a CronTriggeringPolicy in order to rotate the log. For example rotating at midnight.

Did someone already manage to implement that? I tried but failed because all examples found in the internet use xml and not this openhabs approach.

I was asking something similar here:

Unfortunately official documentation is for the xml file which was discontinued with OH2.
I am not sure why and nobody answered me. Maybe beacuse things would be too easy, then! :wink:

Do these instructions still apply to the current release? Is there anything different if running on Windows as a Windows Service?

The OP is out of date. See some of the later posts in the thread or Log4j2 Sample Config.

There is nothing different with the configs when running on Windows.

1 Like

What exactly do you mean?

The log4j config file is identical when running on all platforms. One does not need to do anything special to make logging work when running on Windows as a service.

I totally broke all openhab logging after I edited the org.ops4j.pax.logging.cfg file. Now nothing is logging at all. I replaced the text of the file with what I found in the org.ops4j.pax.logging.cfg.dpkg-old file but no luck.

I’ve restarted it several times, used the openhabian config tool to install openhabian 2.2 (I believe I was running 2.3 snapshot) because I was under the impression that would reset everything in /var/lib/openhab2 and there for fix it but still no luck.

here is the file as it sits now

# Root logger
log4j.rootLogger = WARN, out, osgi:*
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer

# openHAB specific logger configuration
log4j.logger.smarthome.event = INFO, event, osgi:*
log4j.logger.smarthome.event.ItemStateEvent = ERROR
log4j.logger.smarthome.event.ItemAddedEvent = ERROR
log4j.logger.smarthome.event.ItemRemovedEvent = ERROR
log4j.logger.smarthome.event.ThingStatusInfoEvent = ERROR
log4j.logger.smarthome.event.InboxUpdatedEvent = ERROR
log4j.additivity.smarthome.event = false

log4j.logger.org.openhab = INFO
log4j.logger.org.eclipse.smarthome = INFO
log4j.logger.org.jupnp = ERROR
log4j.logger.javax.jmdns = ERROR
log4j.logger.org.ops4j.pax.web.service.jetty.internal.JettyServerWrapper = ERROR
log4j.logger.org.apache.karaf.kar.internal.KarServiceImpl = ERROR
log4j.logger.org.apache.aries.spifly = ERROR

# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n

# File appender - openhab.log
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j.appender.out.file=${openhab.logdir}/openhab.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=10MB
log4j.appender.out.maxBackupIndex=10

# File appender - events.log
log4j.appender.event=org.apache.log4j.RollingFileAppender
log4j.appender.event.layout=org.apache.log4j.PatternLayout
log4j.appender.event.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-26.26c{1}] - %m%n
log4j.appender.event.file=${openhab.logdir}/events.log
log4j.appender.event.append=true
log4j.appender.event.maxFileSize=10MB
log4j.appender.event.maxBackupIndex=10

# Sift appender
log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.sift.key=bundle.name
log4j.appender.sift.default=openhab
log4j.appender.sift.appender=org.apache.log4j.FileAppender
log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.sift.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j.appender.sift.appender.file=${openhab.logdir}/$\\{bundle.name\\}.log
log4j.appender.sift.appender.append=true

Anyone have any pointers?

That is not the content of the original file. Grab it from here and copy it to your file.

1 Like

Sure enough, that did it. I could have sworn I tried that in my attempts to fix it. Thanks.

Does anyone have any Idea how to get TimeBasedTriggering working?

I replied with my ideas on your original thread. I must have missed it when you first posted.

How do I clear the openhab.log file (not the console log which is explained in the documentation)?
Mine got to 15MB in size during the last install.
Thanks.

rm openhab.log

You just delete it (stop openhab of course before deleting it).

Be aware that it will roll over on its own when the file reaches 16 MB.