Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tuned.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions tuned/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@
"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
Expand Down
20 changes: 19 additions & 1 deletion tuned/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -99,6 +100,11 @@ def __init__(self, *args, **kwargs):
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()
Expand All @@ -116,13 +122,25 @@ def remove_all_handlers(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion tuned/ppd/tuned-ppd.service
Original file line number Diff line number Diff line change
Expand Up @@ -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