Skip to content

Commit

Permalink
Revert "bridge: try logging to systemd-journald"
Browse files Browse the repository at this point in the history
This reverts commit e71bf74.
  • Loading branch information
martinpitt committed Dec 6, 2023
1 parent b7832a2 commit 3768fed
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/cockpit/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pwd
import shlex
import socket
import stat
import subprocess
from typing import Iterable, List, Optional, Sequence, Tuple, Type

Expand Down Expand Up @@ -203,33 +202,11 @@ def try_to_receive_stderr():
os.close(fd)


def setup_journald() -> bool:
# If stderr is a socket, prefer systemd-journal logging. This covers the
# case we're already connected to the journal but also the case where we're
# talking to the ferny agent, while leaving logging to file or terminal
# unaffected.
if not stat.S_ISSOCK(os.fstat(2).st_mode):
# not a socket? Don't redirect.
return False

try:
import systemd.journal # type: ignore[import]
except ImportError:
# No python3-systemd? Don't redirect.
return False

logging.root.addHandler(systemd.journal.JournalHandler())
return True


def setup_logging(*, debug: bool) -> None:
def setup_logging(*, debug: bool):
"""Setup our logger with optional filtering of modules if COCKPIT_DEBUG env is set"""

modules = os.getenv('COCKPIT_DEBUG', '')

# Either setup logging via journal or via formatted messages to stderr
if not setup_journald():
logging.basicConfig(format='%(name)s-%(levelname)s: %(message)s')
logging.basicConfig(format='%(name)s-%(levelname)s: %(message)s')

if debug or modules == 'all':
logging.getLogger().setLevel(level=logging.DEBUG)
Expand Down

0 comments on commit 3768fed

Please sign in to comment.