Hello good folk,
My OpenHAB deployment is coming on and great performance, albeit the log files are now quite large approaching GB size - which is ok because I have been debugging and adding Info logging. I do not want to lose the Info logs but perhaps it would be advantageous if I could implement inside OpenHAB configuration - somehow - using the systemd/journal log system.
I would like all logs to be managed systemctl/journalctl.
My openhab2.service file looks like this:
[Unit]
Description=openHAB 2 - empowering the smart home
Documentation=https://www.openhab.org/docs/
Documentation=https://community.openhab.org
Wants=network-online.target
Requires=EnergenieMQTT.service
After=network-online.target
[Service]
Environment=OPENHAB_HOME=/usr/share/openhab2
Environment=OPENHAB_CONF=/etc/openhab2
Environment=OPENHAB_RUNTIME=/usr/share/openhab2/runtime
Environment=OPENHAB_USERDATA=/var/lib/openhab2
Environment=OPENHAB_STARTMODE=daemon
EnvironmentFile=-/etc/default/openhab2
User=openhab
Group=openhab
WorkingDirectory=/usr/share/openhab2
ExecStart=/usr/share/openhab2/runtime/bin/karaf ${OPENHAB_STARTMODE}
ExecStop=/usr/share/openhab2/runtime/bin/karaf stop
# Uncomment to have openhab control logging. Karaf may also need turing??
#Environment=OPENHAB_LOGDIR=/var/log/openhab2
#StandardOuput=/var/log/openhab2/openhab.log
#StandardError=inherit
SuccessExitStatus=0 143
RestartSec=5
Restart=on-failure
TimeoutStopSec=120
LimitNOFILE=102642
[Install]
WantedBy=multi-user.target
I have commented out the OPENHAB_LOGDIR and instructed systemd to log to /var/log/openhab2/openhab.log
However, karaf is also logging now to /var/lib/openhab2/logs
I’d prefer all logs to goto standard output / standard error that way I can use journalctl and fully manage as I want to.
I don’t know if you can have all logs managed by systemctl. You can have all logs go to the syslog (see https://stackoverflow.com/questions/17947611/log4j2-syslog-appender-and-patternlayout) but it’s going to be a bit of work on your part and you’ll have to learn log4j2 and according to that thread there are bugs that need to be worked around. I know of no one who has attempted to do this so you will largely be on your own.
Log4j2 Sample Config shows how to move all the logging from a specific binding to it’s own log file and change the logging level of just that one binding. It should be an example to get you started. But to expand beyond that example and what’s in the docs you will have to go to the Log4j docs.
But if you want full control over the logs you will need to muck around with the log4j2 configuration anyway so you may as well just do it all there. You have full control over what get’s logged and at what level to what files and how those files are managed and rotated there.
Have you done any changes to your log configuration? By default, the logger is configured to rotate the files at 17 mb and only keeps the last 10 files to two different log files (events.log and openhab.log). So either you changed something or there is something wrong because you should never see more than 340 MB of log files from openHAB at any given time, assuming the default configuration.
Mmmm
interesting about rotation, that’s essentially what I’m after and systemd/systemctl was one way i had envisaged. I’ve got a lot of services running, converted many applications on my setup to run and log that way.
Right, i shall take a more in-depth look at karaf and “have a play”
I’m with you ritch, log4j2 will be a pain, much like log4c was for me with other apps.
thanks for the education around OH logging, i clearly have “done / broke something”