Debug logs not visible in OH4

Hey all,

console.debug('');

is not showing up in my frontail after setting rule logging in the karaf console with

log:set DEBUG org.openhab.automation.script

I found this old thread and wondered if I missed the config update too and what the exact config update is: Openhab 4 log debug doesn't work anymore - #2 by rlkoshak

My log4j.xml contains a logger config with level=“Info” for the package.

Maybe I misunderstand. I can certainly update the log level in the xml file but isn’t the whole point of the karaf log settings that I do not have to edit files?

Thanks,
Florian

Usually when you set the log level from karaf, karaf actually adds a line to the bottom of log4j2.xml. If there is no line added, something went wrong with the command.

All the ways you can change the log level of a logger include:

  • modify log4j2.xml manually (note that all other methods really just add/change this file)
  • karaf console log:set
  • REST API logging endpoint
  • if it’s a binding, under Settings → Add-on Settings → Binding
  • in a JS Scripting rule using osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG');, I suspect jRuby has something similar. Now that because this command causes the log4j2.xml file to be opened and modified if two rules try to change log level at the same time it might blow away your log4j2.xml file entirely so use caution.

Thanks, that makes sense. I updated the log2j.xml but for some odd reason, I do not see any debug logs using console.debug(‘test’) from rules.

I see other DEBUG logs when I run log:set DEBUG in karaf, however nothing from my rules where console.debug is used.

It’s getting a bit frustrating cause I don’t know where else I can look. Any further ideas?

In all likelihood you’ve a typo in the logger name or the logger name is something else. I’n the rule add console.info(console.loggerName); That will show the name of the logger you need to set.

Setting Log Level in JRuby

Logger for the current rule

This will change the log level for the current rule (See logger):

logger.level = :debug # other valid values include :info, :warn, :error, :trace, or :default
# Note jruby rule's prefix is org.openhab.automation.jrubyscripting.<RULEID>

Logger for a given prefix

To change the log level of a given prefix (see Logger class):

OpenHAB::Log.logger("org.openhab.automation.script").level = :debug
1 Like