Closed aaronk6 closed 3 months ago
Could you add support for logging to stdout?
I would prefer to see the logs with journalctl -fu sml2mqtt rather than in a separate log file.
journalctl -fu sml2mqtt
I tried this:
logging: level: INFO file: /dev/stdout
This works when running the script manually, but not in the systemd context:
Sep 01 22:13:44 stromableser systemd[1]: Started sml2mqtt. Sep 01 22:13:45 stromableser sml2mqtt[3187]: Traceback (most recent call last): Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/local/lib/python3.9/dist-packages/sml2mqtt/__main__.py", line 57, in main Sep 01 22:13:45 stromableser sml2mqtt[3187]: setup_log() Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/local/lib/python3.9/dist-packages/sml2mqtt/__log__.py", line 46, in setup_log Sep 01 22:13:45 stromableser sml2mqtt[3187]: handler = MidnightRotatingFileHandler( Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/local/lib/python3.9/dist-packages/sml2mqtt/__log__.py", line 20, in __init__ Sep 01 22:13:45 stromableser sml2mqtt[3187]: super().__init__(*args, **kwargs) Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/lib/python3.9/logging/handlers.py", line 153, in __init__ Sep 01 22:13:45 stromableser sml2mqtt[3187]: BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding, Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/lib/python3.9/logging/handlers.py", line 58, in __init__ Sep 01 22:13:45 stromableser sml2mqtt[3187]: logging.FileHandler.__init__(self, filename, mode=mode, Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/lib/python3.9/logging/__init__.py", line 1142, in __init__ Sep 01 22:13:45 stromableser sml2mqtt[3187]: StreamHandler.__init__(self, self._open()) Sep 01 22:13:45 stromableser sml2mqtt[3187]: File "/usr/lib/python3.9/logging/__init__.py", line 1171, in _open Sep 01 22:13:45 stromableser sml2mqtt[3187]: return open(self.baseFilename, self.mode, encoding=self.encoding, Sep 01 22:13:45 stromableser sml2mqtt[3187]: OSError: [Errno 6] No such device or address: '/dev/stdout' Sep 01 22:13:45 stromableser sml2mqtt[3187]: [Errno 6] No such device or address: '/dev/stdout'
My guess is that it would work when using sys.stdout in the Python script.
sys.stdout
Thanks for considering this and thanks for the great work!
Implemented in the rewrite. If you want to try it out there is #39
Could you add support for logging to stdout?
I would prefer to see the logs with
journalctl -fu sml2mqtt
rather than in a separate log file.I tried this:
This works when running the script manually, but not in the systemd context:
My guess is that it would work when using
sys.stdout
in the Python script.Thanks for considering this and thanks for the great work!