From 3a286103c3900a60627585e32aa8959a3de046f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Thu, 11 Apr 2024 18:38:56 +0200 Subject: [PATCH] functions: added 'log' which helps with debugging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E.g.: [variables] dummy=${f:log:${f:exec:uname}} Logs the output of the 'uname' command to the TuneD log. Also added more verbose debug output which can help with functions debugging. Enable with 'tuned -D'. Signed-off-by: Jaroslav Škarvada --- tuned/profiles/functions/function_log.py | 19 +++++++++++++++++++ tuned/profiles/functions/functions.py | 1 + 2 files changed, 20 insertions(+) create mode 100644 tuned/profiles/functions/function_log.py diff --git a/tuned/profiles/functions/function_log.py b/tuned/profiles/functions/function_log.py new file mode 100644 index 0000000..43e6f43 --- /dev/null +++ b/tuned/profiles/functions/function_log.py @@ -0,0 +1,19 @@ +import tuned.logs +from . import base + +log = tuned.logs.get() + +class execute(base.Function): + """ + Expands to concatenation of arguments and logs the result, useful for debugging. + """ + def __init__(self): + # unlimited number of arguments, min 1 argument (the value to log) + super(execute, self).__init__("log", 0, 1) + + def execute(self, args): + if not super(execute, self).execute(args): + return None + s = "".join(args) + log.info(s) + return s diff --git a/tuned/profiles/functions/functions.py b/tuned/profiles/functions/functions.py index 6ea2baa..5280606 100644 --- a/tuned/profiles/functions/functions.py +++ b/tuned/profiles/functions/functions.py @@ -56,6 +56,7 @@ class Functions(): log.error("function '%s' not implemented" % sl[1]) return s = f.execute(sl[2:]) + log.debug("${f:%s} expands to: '%s'" % (":".join(sl[1:]), s)) if s is None: return self._sub(_from, self._cnt, s)