Skip to content

Commit

Permalink
Move constants to top-level module
Browse files Browse the repository at this point in the history
  • Loading branch information
miccoli committed Aug 14, 2023
1 parent aee8a43 commit 515a327
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/trick17/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# SPDX-FileCopyrightText: 2023-present Stefano Miccoli <[email protected]>
#
# SPDX-License-Identifier: MIT

# systemd notable paths
SD_BOOTED_PATH = "/run/systemd/system"
SD_JOURNAL_SOCKET_PATH = "/run/systemd/journal/socket"

# environmet variables possibly set by systemd
SD_JOURNAL_STREAM_ENV = "JOURNAL_STREAM"
9 changes: 7 additions & 2 deletions src/trick17/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
import sys
import syslog

import trick17


def stderr_is_journal() -> bool:
stat = os.fstat(sys.stderr.fileno())
return os.environ.get("JOURNAL_STREAM", "") == f"{stat.st_dev}:{stat.st_ino}"
return (
os.environ.get(trick17.SD_JOURNAL_STREAM_ENV, "")
== f"{stat.st_dev}:{stat.st_ino}"
)


class JournalHandler(logging.Handler):
"""Simple logger for the Systemd Native Journal Protocol"""

SADDR: str = "/run/systemd/journal/socket"
SADDR: str = trick17.SD_JOURNAL_SOCKET_PATH

@staticmethod
def _serialize(key: bytes, val: bytes) -> bytes:
Expand Down

0 comments on commit 515a327

Please sign in to comment.