]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: add get-log-level, get-log-target verbs 6770/head
authorLucas Werkmeister <mail@lucaswerkmeister.de>
Thu, 7 Sep 2017 21:41:20 +0000 (23:41 +0200)
committerLucas Werkmeister <mail@lucaswerkmeister.de>
Thu, 7 Sep 2017 21:55:59 +0000 (23:55 +0200)
They’re counterparts to the existing set-log-level and set-log-target
verbs, simply printing the current value to stdout. This makes it
slightly easier to temporarily change the log level and/or target and
then restore the old value(s).

NEWS
man/systemd-analyze.xml
shell-completion/bash/systemd-analyze
shell-completion/zsh/_systemd-analyze
src/analyze/analyze.c

diff --git a/NEWS b/NEWS
index f843c35c4f5de769eebe646b35c999e61f6d2419..4940902451ec708c453cafda9c94453fbd50ab81 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,11 @@ CHANGES WITH 235:
           that case users will be prevented from correctly managing bond0
           interface using networkd.
 
+        * systemd-analyze gained new verbs "get-log-level" and "get-log-target"
+          which print the logging level and target of the system manager,
+          respectively. They complement the existing "set-log-level" and
+          "set-log-target" verbs, which can be used to change those values.
+
 CHANGES WITH 234:
 
         * Meson is now supported as build system in addition to Automake. It is
index 91edbfb3b55756c7f86813b34ab271fc249423dc..a3a3ce0e54160ca5133d017965abfc2d17f8c948 100644 (file)
       <arg choice="plain">set-log-target</arg>
       <arg choice="plain"><replaceable>TARGET</replaceable></arg>
     </cmdsynopsis>
+    <cmdsynopsis>
+      <command>systemd-analyze</command>
+      <arg choice="opt" rep="repeat">OPTIONS</arg>
+      <arg choice="plain">get-log-level</arg>
+    </cmdsynopsis>
+    <cmdsynopsis>
+      <command>systemd-analyze</command>
+      <arg choice="opt" rep="repeat">OPTIONS</arg>
+      <arg choice="plain">get-log-target</arg>
+    </cmdsynopsis>
     <cmdsynopsis>
       <command>systemd-analyze</command>
       <arg choice="opt" rep="repeat">OPTIONS</arg>
     <option>--log-target=</option>, described in
     <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para>
 
+    <para><command>systemd-analyze get-log-level</command>
+    prints the current log level of the <command>systemd</command> daemon.</para>
+
+    <para><command>systemd-analyze get-log-target</command>
+    prints the current log target of the <command>systemd</command> daemon.</para>
+
     <para><command>systemd-analyze syscall-filter <optional><replaceable>SET</replaceable>…</optional></command>
     will list system calls contained in the specified system call set <replaceable>SET</replaceable>,
     or all known sets if no sets are specified. Argument <replaceable>SET</replaceable> must include
index 75352a7b3eafc4426e398dee12794a6ff49a69f7..8c56a1cf9acb7f33bd3d35e66eae99052793239a 100644 (file)
@@ -40,7 +40,7 @@ _systemd_analyze() {
         )
 
         local -A VERBS=(
-                [STANDALONE]='time blame plot dump'
+                [STANDALONE]='time blame plot dump get-log-level get-log-target'
                 [CRITICAL_CHAIN]='critical-chain'
                 [DOT]='dot'
                 [LOG_LEVEL]='set-log-level'
index 3f091e326a2db5fd52009c9679c9bd38ce58feb6..22b4c181a137f94ecf35b96c16f6db2654c3c4c3 100644 (file)
@@ -28,6 +28,8 @@ _systemd_analyze_command(){
         'dump:Dump server status'
         'set-log-level:Set systemd log threshold'
         'set-log-target:Set systemd log target'
+        'get-log-level:Get systemd log threshold'
+        'get-log-target:Get systemd log target'
         'syscall-filter:List syscalls in seccomp filter'
         'verify:Check unit files for correctness'
     )
index 1eb2ca0ccf63a2418a1e4e6a9f9cdc8465fd7bde..a6a36a3d2e530fb8df4db1f573edff967a199d34 100644 (file)
@@ -1253,6 +1253,34 @@ static int set_log_level(sd_bus *bus, char **args) {
         return 0;
 }
 
+static int get_log_level(sd_bus *bus, char **args) {
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+        int r;
+        _cleanup_free_ char *level = NULL;
+
+        assert(bus);
+        assert(args);
+
+        if (!strv_isempty(args)) {
+                log_error("Too many arguments.");
+                return -E2BIG;
+        }
+
+        r = sd_bus_get_property_string(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "LogLevel",
+                        &error,
+                        &level);
+        if (r < 0)
+                return log_error_errno(r, "Failed to get log level: %s", bus_error_message(&error, r));
+
+        puts(level);
+        return 0;
+}
+
 static int set_log_target(sd_bus *bus, char **args) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
@@ -1280,6 +1308,34 @@ static int set_log_target(sd_bus *bus, char **args) {
         return 0;
 }
 
+static int get_log_target(sd_bus *bus, char **args) {
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+        int r;
+        _cleanup_free_ char *target = NULL;
+
+        assert(bus);
+        assert(args);
+
+        if (!strv_isempty(args)) {
+                log_error("Too many arguments.");
+                return -E2BIG;
+        }
+
+        r = sd_bus_get_property_string(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "LogTarget",
+                        &error,
+                        &target);
+        if (r < 0)
+                return log_error_errno(r, "Failed to get log target: %s", bus_error_message(&error, r));
+
+        puts(target);
+        return 0;
+}
+
 #ifdef HAVE_SECCOMP
 static void dump_syscall_filter(const SyscallFilterSet *set) {
         const char *syscall;
@@ -1365,6 +1421,8 @@ static void help(void) {
                "  dot                      Output dependency graph in man:dot(1) format\n"
                "  set-log-level LEVEL      Set logging threshold for manager\n"
                "  set-log-target TARGET    Set logging target for manager\n"
+               "  get-log-level            Get logging threshold for manager\n"
+               "  get-log-target           Get logging target for manager\n"
                "  dump                     Output state serialization of service manager\n"
                "  syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
                "  verify FILE...           Check unit files for correctness\n"
@@ -1532,8 +1590,12 @@ int main(int argc, char *argv[]) {
                         r = dump(bus, argv+optind+1);
                 else if (streq(argv[optind], "set-log-level"))
                         r = set_log_level(bus, argv+optind+1);
+                else if (streq(argv[optind], "get-log-level"))
+                        r = get_log_level(bus, argv+optind+1);
                 else if (streq(argv[optind], "set-log-target"))
                         r = set_log_target(bus, argv+optind+1);
+                else if (streq(argv[optind], "get-log-target"))
+                        r = get_log_target(bus, argv+optind+1);
                 else if (streq(argv[optind], "syscall-filter"))
                         r = dump_syscall_filters(argv+optind+1);
                 else