logging to systemd journal

135 views
Skip to first unread message

Graham Eddy

unread,
Aug 4, 2023, 11:50:07 AM8/4/23
to weewx-development
i have been playing with debian bookworm, where rsyslog is no longer in the core and has to be installed (if you use it). i would describe that as a ’new’ dependency for weewx under debian

the weewx 5.0 re-packaging looks awesome - i have now tried pip-installing it under bookworm

i have also been playing with systemd journalctl, which is now core to debian bookworm. i know there are systemd haters, but there it is. so for those users who will want to use the standard operational environment, we need a bridge from weewx [Logging] into journalctl, given rsyslog will continue to be the logging engine within weewx

there is class systemd.journal.JournalHandler that can be used under [Logging]. it is an external module, not (yet?) part of the logging.handlers module. i tried to pip a couple of pypy modules (systemd and systems-python) but both have install issues. so i have tried apt install python3-systemd, updated env/pyenv.cfg to include external packages, then updated weewx.conf as follows:
  1. copied all the [Logging] section from defaults into weewx.conf
  2. change [[root]] handlers = systemd,
  3. add [[handlers]] [[[systemd]]]
      level = DEBUG
      formatter = verbose
      class = systemd.journal.JournalHandler
      SYSLOG_IDENTIFIER = weewx
i had to add the SYSLOG_IDENTIFIER because the JournalHandler defaults to using the whole path of weewxd as the logging ident not just the basename

then journalctl can be run as usual, using -t to select just weewx entries e.g. journalctl -t weewx -f is equiv to tail -f /var/log/weewx.log.
cheers
⊣GE⊢

Paul R Anderson

unread,
Aug 4, 2023, 12:45:15 PM8/4/23
to Graham Eddy, weewx-development
Not sure I understand the extra work needed to get logging with WeeWx V5 under Bookworm to work as you want. I have been  running the alpha versions, then the beta versions of V5 under Bookworm for several months, starting before Bookworm was released. Using the pip-install of WeeWX under Bookworm systemd journalctl logging has been working fine with no special work on my part to logging as far as modifying handlers and such. I am able to use:
journalctl -f -u weewx
to follow the logging as you would with  tail -f /var/log/weewx.log
Similar to your journalct query but using the  -u --unit=UNIT option rather than the -t --identifier=STRING
Added  alias f="journalctl -f -u " to my .bashrc so I can start weewx and follow the log:
sudo systemctl start weewx;f weewx
Also ran a bash script daily that captures info on WeeWx and use a  query like this to get yesterday's info in what i'm interested in 
ERRORS="journalctl -q -u weewx.service --since yesterday --until today -g 'ERROR' "
thanks
Paul



--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/9A2E99D1-0665-4B18-B215-4911050396B9%40geddy.au.

Vince Skahan

unread,
Aug 4, 2023, 1:33:49 PM8/4/23
to weewx-development
Agree with Paul.
On debian12 bookworm I had to do nothing for the various 'journalctl -u weewx' commands to work.

Paul R Anderson

unread,
Aug 4, 2023, 4:35:42 PM8/4/23
to Graham Eddy, weewx-development
Just a follow up Under Debian Bullseye, and many releases prior to that many of us would follow the classic steps in the WeeWX Wiki of setting up rsyslog and logrotate, to save WeeWX log messages to a separate file. But under the hood Debian Bullseye, and many releases prior to that, altho rsyslog was installed by default, the systemd journal was configured to do logging and forward the log messages to rsyslog. 
So if you followed the steps to log to the classic /var/log/weewx.log file, in addition to that systemd journalctl was logging WeeWX activity to system journal as well. Essentially doing redundant logging to 2 locations . So you could either read the text based log file , or use journalctl tool to read the log from systemd journal.
    
Change in Bookworm is that rsyslog is not installed by default. So logging is only done to systemd journal unless you choose to install rsyslog.
Main drive behind this has been stated to eliminate redundant logging.

Paul   

Graham Eddy

unread,
Aug 5, 2023, 12:34:51 AM8/5/23
to weewx-development
note to self: verify problem exists before trying to fix it

bridge from [Logging] to journalctl already exists, obviating rsyslog:

(venv) graham@burner:~/data$ ls -l /dev/log

lrwxrwxrwx 1 root root 28 Aug  4 17:19 /dev/log -> /run/systemd/journal/dev-log

⊣GE⊢

Reply all
Reply to author
Forward
0 new messages