Help with setting log level

Hi, new OH user here.
Was hoping someone could point me in the right direction regarding setting log level for specific packages.

I’ve installed the Yeelight binding and the binding is quite verbose in regard to logging state changes. Ex. for every call to the binding I’m seeing messages similar to these in /var/log/openhab2/openhab.log:

2017-06-28 22:16:13.204 [INFO ] [yeelight.handler.YeelightHandlerBase] - YeelightStripeHandler: command: ON
2017-06-28 22:16:16.395 [INFO ] [yeelight.handler.YeelightHandlerBase] - YeelightStripeHandler: command: 24
2017-06-28 22:16:16.586 [INFO ] [yeelight.handler.YeelightHandlerBase] - YeelightStripeHandler: command: 24
2017-06-28 22:16:17.413 [INFO ] [yeelight.handler.YeelightHandlerBase] - YeelightStripeHandler: command: OFF

Now, I figured just change the log level of yeelight.handler.YeelightHandlerBase to WARN right?
Seems like I’m not able to this (probably because I’ve missed something in the docs). What I’ve tried:

In the OH console: log:set WARN yeelight.handler.YeelightHandlerBase. After doing this, verifying config with:

openhab> log:get yeelight.handler.YeelightHandlerBase
Logger                               | Level
--------------------------------------------
yeelight.handler.YeelightHandlerBase | WARN

Manually configure log levels in /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg (even though log:set seems to to this automatically). My current /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg:

[21:23:08] openhabian@IoT-OH-host:/usr/share/openhab2/addons$ cat /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg
# 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.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

# Yeelight
log4j.logger.yeelight.handler.YeelightHandlerBase = WARN
log4j.logger.yeelight.handler.* = WARN
log4j.logger.yeelight.handler = WARN

I’ve also attempted to restart OH using sudo systemctl restart openhab2

Despite my attempts I’m still seeing the log messages in /var/log/openhab2/openhab.log.

I’m running Openhabian v1.3 (OH2 stable updated recently) on a Raspberry pi model 3b.

Any help much appreciated.

usually, you need to specify the binding name like:

log:set WARN org.openhab.binding.yeelight
and/or
log:set WARN org.openhab.binding.yeelight.handler.YeelightHandlerBase

you can find the correct “Symbolic name” by:

list -s |grep -i yeelight

Indeed. See:

http://docs.openhab.org/administration/logging.html#logging-into-separate-file

You need to create an appender for your yeelight config and then a logger mapped to that appender.

Here is how I shunt my zwave logs to another file:

# zwave logger
log4j.logger.org.openhab.binding.zwave = INFO, zwave, osgi:*
log4j.additivity.org.openhab.binding.zwave = false

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

The first line defines a new Logger and tells it to log at the INFO level using the zwave and osgi:* appenders.

The second line tells it not to append the stuff that goes to this logger to the default appender (i.e. keep these logs out of openhab.log).

The rest defines the zwave appender.

Thanks @Dim, this is exactly the info I was looking for :slight_smile:

@rlkoshak Thank you too. I was not really looking to pipe the log to an other file for now (I may have been a bit unclear in my original question about what I was looking to do). I’m definitely bookmarking your post as I will need to do this further down the road when my system has grown beyond one switch and two led strips :stuck_out_tongue:

So, just to be clear, if you just wanted to change the level of the binding’s logging in openhab.log I think all you would need to do is:

log4j.logger.org.openhab.binding.zwave = WARN, out, osgi:*

I’m not sure whether the additivity is required or not but think not.

The big change (besides dropping the appender stuff) is I changed the stuff after the log level to use the already existing out appender (which controls openhab.log) instead of the zwave appender I have defined above. The osgi:* part makes these logs appear in the karaf console.