5iver
(Scott Rushworth)
February 12, 2018, 6:03pm
1
Here is an example of how logging levels can be changed without having to manually enter commands into the Karaf console or editing org.ops4j.pax.logging.cfg. I set this up and it is working in my environment, but the ssh command will need to be modified to work for someone running openHabian or if OH is being run on Windows. The key based authentication is the trickiest bit to setup. Be sure to configure Karaf with the public key and then ssh in manually first to accept the host’s public key. What you see below is simple… but the setup can be daunting.
ITEM
String LogLevel_Rules "Logging Level: Rules [%s]" <text>
String LogLevel_Zwave "Logging Level: Zwave [%s]" <text>
String LogLevel_Zigbee "Logging Level: Zigbee [%s]" <text>
SITEMAP
Selection item=LogLevel_Rules mappings=["INFO"="INFO","DEBUG"="DEBUG"]
Selection item=LogLevel_Zwave mappings=["INFO"="INFO","DEBUG"="DEBUG"]
Selection item=LogLevel_Zigbee mappings=["INFO"="INFO","DEBUG"="DEBUG"]
RULE
rule "Set log level"
when
Item LogLevel_Rules received command
or
Item LogLevel_Zwave received command
or
Item LogLevel_Zigbee received command
then
val String commandPrefix = "/bin/bash@@-c@@/usr/bin/ssh openhab@localhost -p 8101 log:set "
//val String commandPrefix = "/bin/bash@@-c@@/usr/bin/ssh openhabian@localhost -p 8101 log:set "// this might work for openHabian?
switch (triggeringItem.getName) {
case "Virtual_String_1" : executeCommandLine(commandPrefix + receivedCommand + " org.eclipse.smarthome.model.script.Rules"),
case "LogLevel_Zwave" : executeCommandLine(commandPrefix + receivedCommand + " org.openhab.binding.zwave"),
case "LogLevel_Zigbee" : {
executeCommandLine(commandPrefix + receivedCommand + " org.openhab.binding.zigbee")
executeCommandLine(commandPrefix + receivedCommand + " com.zsmartsystems.zigbee")
}
}
logInfo("Rules", "Set log level: {} set to {}",triggeringItem.getName,receivedCommand)
end
5 Likes
NCO
(E. Gerland)
June 23, 2018, 5:05am
2
Thanks.
This was one topic I had on my list since the first OH2 stable.
Thanks for sharing!
NCO
(E. Gerland)
June 24, 2018, 6:36am
3
Actually I had successfully connect to karaf by key authentication and wrote a tutorial about it here:
All,
I currently struggle with my Netatmo binding. After a few hours it stops getting updates from the Netatmo station.
So I implemented a solution to restart the binding from within a rule.
I hope this helps someone for solving similar issues with specific bindings:
First generate the key (as an alternative to sshpass) to enable you to start karaf without beeing asked for your password
sudo -u openhab ssh-keygen -t rsa -f openhab.id_rsa (no passphrase)
Next, put the result (key only of co…
NCO
(E. Gerland)
June 27, 2018, 4:17pm
4
I did not find a command to set globally the loglevel to Error.
Isn’t there such option?
5iver
(Scott Rushworth)
June 27, 2018, 5:09pm
5
Globally, as in for all of the appenders? Not that I am aware of.
NCO
(E. Gerland)
June 27, 2018, 5:21pm
6
I try to figure out where my CPU load comes from and I have concerns that it’s from logging!?
(Raspi 3)
When changing the global logfile org.ops4j.pax.logging.cfg
Does this require a restart of OH?
5iver
(Scott Rushworth)
June 27, 2018, 5:29pm
7
No, it’s immediate. Doing a log:set [blah] modifies this file. I find VS Code (with LSP enabled) puts a good bit of load on my server, and sometimes shutting it down does not help, but an OH restart clears it up.
Dim
(Angelos)
June 27, 2018, 5:32pm
8
I think that the first line will work for both since you are logging into Karaf console and the username there is openhab.
I think that the Linux username is different in openHABian versus “standard” Raspbian (pi vs openhabian)
5iver
(Scott Rushworth)
June 27, 2018, 5:36pm
9
I thought openHABian used a different set of credentials (I’ve never used it). From here…
Connect to your Raspberry Pi SSH console using the username openhabian and password openhabian.
Dim
(Angelos)
June 27, 2018, 5:37pm
10
I used it also some time ago (when it was started), but not currently.
I think that this doc entry refers only to the O/S. The console docs entry is common for all O/S.
The username being used is: https://docs.openhab.org/administration/console.html#changing-the-password