Update dependency to cysystemd

closes #8187
This commit is contained in:
Matthias 2023-02-19 19:30:27 +01:00
parent b0ec35d526
commit e9c64c5839
4 changed files with 6 additions and 5 deletions

View File

@ -192,7 +192,7 @@ $RepeatedMsgReduction on
### Logging to journald ### Logging to journald
This needs the `systemd` python package installed as the dependency, which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows. This needs the `cysystemd` python package installed as dependency (`pip install cysystemd`), which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.
To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format: To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:

View File

@ -103,7 +103,7 @@ def setup_logging(config: Config) -> None:
logging.root.addHandler(handler_sl) logging.root.addHandler(handler_sl)
elif s[0] == 'journald': # pragma: no cover elif s[0] == 'journald': # pragma: no cover
try: try:
from systemd.journal import JournaldLogHandler from cysystemd.journal import JournaldLogHandler
except ImportError: except ImportError:
raise OperationalException("You need the systemd python package be installed in " raise OperationalException("You need the systemd python package be installed in "
"order to use logging to journald.") "order to use logging to journald.")

View File

@ -2573,7 +2573,7 @@ def import_fails() -> None:
realimport = builtins.__import__ realimport = builtins.__import__
def mockedimport(name, *args, **kwargs): def mockedimport(name, *args, **kwargs):
if name in ["filelock", 'systemd.journal', 'uvloop']: if name in ["filelock", 'cysystemd.journal', 'uvloop']:
raise ImportError(f"No module named '{name}'") raise ImportError(f"No module named '{name}'")
return realimport(name, *args, **kwargs) return realimport(name, *args, **kwargs)

View File

@ -701,15 +701,16 @@ def test_set_loggers_journald(mocker):
'logfile': 'journald', 'logfile': 'journald',
} }
setup_logging_pre()
setup_logging(config) setup_logging(config)
assert len(logger.handlers) == 2 assert len(logger.handlers) == 3
assert [x for x in logger.handlers if type(x).__name__ == "JournaldLogHandler"] assert [x for x in logger.handlers if type(x).__name__ == "JournaldLogHandler"]
assert [x for x in logger.handlers if type(x) == logging.StreamHandler] assert [x for x in logger.handlers if type(x) == logging.StreamHandler]
# reset handlers to not break pytest # reset handlers to not break pytest
logger.handlers = orig_handlers logger.handlers = orig_handlers
def test_set_loggers_journald_importerror(mocker, import_fails): def test_set_loggers_journald_importerror(import_fails):
logger = logging.getLogger() logger = logging.getLogger()
orig_handlers = logger.handlers orig_handlers = logger.handlers
logger.handlers = [] logger.handlers = []