1
0
Fork 0
This commit is contained in:
Rodney Lorrimar 2026-05-20 18:24:36 +03:00 committed by GitHub
commit 32cdbdd985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 3 deletions

View file

@ -9,7 +9,7 @@ Documentation=man:tuned(8) man:tuned.conf(5) man:tuned-adm(8)
Type=dbus
PIDFile=/run/tuned/tuned.pid
BusName=com.redhat.tuned
ExecStart=/usr/sbin/tuned -l -P
ExecStart=/usr/sbin/tuned -P
[Install]
WantedBy=multi-user.target

View file

@ -249,6 +249,17 @@ CAPTURE_LOG_LEVELS = {
"console": LOG_LEVEL_CONSOLE,
"none": None,
}
def syslog_priority(levelno):
"""
Convert sparse numeric python logging level to syslog priority.
"""
if levelno <= logging.DEBUG: return 7 # debug
elif levelno <= logging.INFO: return 6 # info
elif levelno == LOG_LEVEL_CONSOLE: return 5 # notice
elif levelno <= logging.WARNING: return 4 # warning
elif levelno <= logging.ERROR: return 3 # err
elif levelno <= logging.CRITICAL: return 2 # crit
else: return 1 # alert
# number of retries when waiting for device initialization
HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES = 100

View file

@ -88,6 +88,7 @@ def get():
class TunedLogger(logging.getLoggerClass()):
"""Custom TuneD daemon logger class."""
_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s: %(message)s")
_formatter_journal = logging.Formatter("<%(priority)d>%(name)s: %(message)s")
_console_handler = None
_file_handler = None
@ -99,6 +100,11 @@ class TunedLogger(logging.getLoggerClass()):
def console(self, msg, *args, **kwargs):
self.log(consts.LOG_LEVEL_CONSOLE, msg, *args, **kwargs)
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None):
extra = extra or {}
extra["priority"] = consts.syslog_priority(level)
return super(TunedLogger, self).makeRecord(name, level, fn, lno, msg, args, exc_info, func, extra, sinfo)
def switch_to_console(self):
self._setup_console_handler()
self.remove_all_handlers()
@ -116,13 +122,25 @@ class TunedLogger(logging.getLoggerClass()):
for handler in _handlers:
self.removeHandler(handler)
@classmethod
def _detect_systemd_journal_stream(cls):
"""
Returns True iff systemd tells us we are running with
stdout/stderr connected to the journal.
"""
return os.environ.get("JOURNAL_STREAM", "") != ""
@classmethod
def _setup_console_handler(cls):
if cls._console_handler is not None:
return
cls._console_handler = logging.StreamHandler()
cls._console_handler.setFormatter(cls._formatter)
if cls._detect_systemd_journal_stream():
fmt = cls._formatter_journal
else:
fmt = cls._formatter
cls._console_handler.setFormatter(fmt)
@classmethod
def _setup_file_handler(cls, filename, maxBytes, backupCount):

View file

@ -8,7 +8,7 @@ Before=multi-user.target display-manager.target
Type=dbus
BusName=org.freedesktop.UPower.PowerProfiles
BusName=net.hadess.PowerProfiles
ExecStart=/usr/sbin/tuned-ppd -l
ExecStart=/usr/sbin/tuned-ppd
[Install]
WantedBy=graphical.target