From 8e0e57e193f9a6ebca6c5a384cb18aac32b6b9ca Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Thu, 25 May 2023 04:38:12 +0300 Subject: [PATCH] switch to explicit journald logger instead of syslog --- .github/workflows/setup.sh | 2 +- Dockerfile | 4 ++-- docker/entrypoint.sh | 2 +- docs/faq.rst | 8 ++++++-- package/archlinux/PKGBUILD | 3 ++- .../settings/ahriman.ini.d/logging.ini | 20 ++++++++++++------- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/setup.sh b/.github/workflows/setup.sh index 5f5aebaa..2324c371 100755 --- a/.github/workflows/setup.sh +++ b/.github/workflows/setup.sh @@ -10,7 +10,7 @@ echo -e '[arcanisrepo]\nServer = http://repo.arcanis.me/$arch\nSigLevel = Never' # refresh the image pacman --noconfirm -Syu # main dependencies -pacman --noconfirm -Sy base-devel devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo sudo +pacman --noconfirm -Sy base-devel devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo python-systemd sudo # make dependencies pacman --noconfirm -Sy python-build python-installer python-wheel # optional dependencies diff --git a/Dockerfile b/Dockerfile index 8bd2138c..a9ddd925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV AHRIMAN_DEBUG="" ENV AHRIMAN_FORCE_ROOT="" ENV AHRIMAN_HOST="0.0.0.0" ENV AHRIMAN_MULTILIB="yes" -ENV AHRIMAN_OUTPUT="syslog" +ENV AHRIMAN_OUTPUT="journald" ENV AHRIMAN_PACKAGER="ahriman bot " ENV AHRIMAN_PACMAN_MIRROR="" ENV AHRIMAN_PORT="" @@ -28,7 +28,7 @@ RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build && \ COPY "docker/install-aur-package.sh" "/usr/local/bin/install-aur-package" ## install package dependencies ## darcs is not installed by reasons, because it requires a lot haskell packages which dramatically increase image size -RUN pacman -Sy --noconfirm --asdeps devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo && \ +RUN pacman -Sy --noconfirm --asdeps devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo python-systemd && \ pacman -Sy --noconfirm --asdeps python-build python-installer python-wheel && \ pacman -Sy --noconfirm breezy mercurial python-aiohttp python-aiohttp-cors python-boto3 python-cryptography python-jinja python-requests-unixsocket rsync subversion && \ runuser -u build -- install-aur-package python-aioauth-client python-aiohttp-apispec-git python-aiohttp-jinja2 \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 69bc91cf..2b5dbb0d 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -15,7 +15,7 @@ database = $AHRIMAN_REPOSITORY_ROOT/ahriman.db host = $AHRIMAN_HOST EOF -sed -i "s|handlers = syslog_handler|handlers = ${AHRIMAN_OUTPUT}_handler|g" "/etc/ahriman.ini.d/logging.ini" +sed -i "s|handlers = journald_handler|handlers = ${AHRIMAN_OUTPUT}_handler|g" "/etc/ahriman.ini.d/logging.ini" AHRIMAN_DEFAULT_ARGS=("--architecture" "$AHRIMAN_ARCHITECTURE") if [[ "$AHRIMAN_OUTPUT" == "syslog" ]]; then diff --git a/docs/faq.rst b/docs/faq.rst index 4c6f4557..717625a7 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -974,13 +974,17 @@ It is automation tools for ``repoctl`` mentioned above. Except for using shell i How to check service logs ^^^^^^^^^^^^^^^^^^^^^^^^^ -By default, the service writes logs to ``/dev/log`` which can be accessed by using ``journalctl`` command (logs are written to the journal of the user under which command is run). +By default, the service writes logs to ``/dev/log`` which can be accessed by using ``journalctl`` command (logs are written to the journal of the user under which command is run). In order to retrieve logs for the process you can use the following command: + +.. code-block:: shell + + sudo journalctl SYSLOG_IDENTIFIER=ahriman You can also edit configuration and forward logs to ``stderr``, just change ``handlers`` value, e.g.: .. code-block:: shell - sed -i 's/handlers = syslog_handler/handlers = console_handler/g' /etc/ahriman.ini.d/logging.ini + sed -i 's/handlers = journald_handler/handlers = console_handler/g' /etc/ahriman.ini.d/logging.ini You can even configure logging as you wish, but kindly refer to python ``logging`` module `configuration `_. The application uses java concept to log messages, e.g. class ``Application`` imported from ``ahriman.application.application`` package will have logger called ``ahriman.application.application.Application``. In order to e.g. change logger name for whole application package it is possible to change values for ``ahriman.application`` package; thus editing ``ahriman`` logger configuration will change logging for whole application (unless there are overrides for another logger). diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index d3c6540b..c5e47b27 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -7,7 +7,8 @@ pkgdesc="ArcH linux ReposItory MANager" arch=('any') url="https://github.com/arcan1s/ahriman" license=('GPL3') -depends=('devtools>=1:1.0.0' 'git' 'pyalpm' 'python-cerberus' 'python-inflection' 'python-passlib' 'python-requests' 'python-srcinfo') +depends=('devtools>=1:1.0.0' 'git' 'pyalpm' 'python-cerberus' 'python-inflection' 'python-passlib' 'python-requests' + 'python-srcinfo' 'python-systemd') makedepends=('python-build' 'python-installer' 'python-wheel') optdepends=('breezy: -bzr packages support' 'darcs: -darcs packages support' diff --git a/package/share/ahriman/settings/ahriman.ini.d/logging.ini b/package/share/ahriman/settings/ahriman.ini.d/logging.ini index 3bd5194a..d1d74fdd 100644 --- a/package/share/ahriman/settings/ahriman.ini.d/logging.ini +++ b/package/share/ahriman/settings/ahriman.ini.d/logging.ini @@ -2,7 +2,7 @@ keys = root,http,stderr,boto3,botocore,nose,s3transfer [handlers] -keys = console_handler,syslog_handler +keys = console_handler,journald_handler,syslog_handler [formatters] keys = generic_format,syslog_format @@ -13,6 +13,12 @@ level = DEBUG formatter = generic_format args = (sys.stderr,) +[handler_journald_handler] +class = systemd.journal.JournalHandler +level = DEBUG +formatter = syslog_format +kwargs = {"SYSLOG_IDENTIFIER": "ahriman"} + [handler_syslog_handler] class = logging.handlers.SysLogHandler level = DEBUG @@ -29,12 +35,12 @@ datefmt = [logger_root] level = DEBUG -handlers = syslog_handler +handlers = journald_handler qualname = root [logger_http] level = DEBUG -handlers = syslog_handler +handlers = journald_handler qualname = http propagate = 0 @@ -45,24 +51,24 @@ qualname = stderr [logger_boto3] level = INFO -handlers = syslog_handler +handlers = journald_handler qualname = boto3 propagate = 0 [logger_botocore] level = INFO -handlers = syslog_handler +handlers = journald_handler qualname = botocore propagate = 0 [logger_nose] level = INFO -handlers = syslog_handler +handlers = journald_handler qualname = nose propagate = 0 [logger_s3transfer] level = INFO -handlers = syslog_handler +handlers = journald_handler qualname = s3transfer propagate = 0