daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a9339c
From ea366cda56dc0550b9829e4d9e733cb8b70ffb30 Mon Sep 17 00:00:00 2001
a9339c
From: Michal Schmidt <mschmidt@redhat.com>
a9339c
Date: Tue, 21 Jul 2015 19:07:24 +0200
a9339c
Subject: [PATCH] core: adjust job completion message log levels
a9339c
a9339c
We do not print all non-OK job completion status messages to the console
a9339c
in red, because not all of them are plain errors. We do however log the
a9339c
same messages as LOG_ERR.
a9339c
a9339c
Differentiate the log levels by deducing them from the job result in a
a9339c
way that more or less matches the color of the console message.
a9339c
a9339c
(cherry picked from commit 64f575d2ab9a6743d3c7172b7591c88ba243cf1b)
a9339c
a9339c
Related: #1506256
a9339c
---
a9339c
 src/core/job.c | 19 +++++++++++++++----
a9339c
 1 file changed, 15 insertions(+), 4 deletions(-)
a9339c
a9339c
diff --git a/src/core/job.c b/src/core/job.c
a9339c
index 086050aa7..1861c8a63 100644
a9339c
--- a/src/core/job.c
a9339c
+++ b/src/core/job.c
a9339c
@@ -714,6 +714,17 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
a9339c
 static void job_log_status_message(Unit *u, JobType t, JobResult result) {
a9339c
         const char *format;
a9339c
         char buf[LINE_MAX];
a9339c
+        static const int job_result_log_level[_JOB_RESULT_MAX] = {
a9339c
+                [JOB_DONE]        = LOG_INFO,
a9339c
+                [JOB_CANCELED]    = LOG_INFO,
a9339c
+                [JOB_TIMEOUT]     = LOG_ERR,
a9339c
+                [JOB_FAILED]      = LOG_ERR,
a9339c
+                [JOB_DEPENDENCY]  = LOG_WARNING,
a9339c
+                [JOB_SKIPPED]     = LOG_NOTICE,
a9339c
+                [JOB_INVALID]     = LOG_INFO,
a9339c
+                [JOB_ASSERT]      = LOG_WARNING,
a9339c
+                [JOB_UNSUPPORTED] = LOG_WARNING,
a9339c
+        };
a9339c
 
a9339c
         assert(u);
a9339c
         assert(t >= 0);
a9339c
@@ -738,14 +749,14 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
a9339c
 
a9339c
                 mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
a9339c
                 log_unit_struct(u->id,
a9339c
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
a9339c
+                                job_result_log_level[result],
a9339c
                                 LOG_MESSAGE_ID(mid),
a9339c
                                 LOG_MESSAGE("%s", buf),
a9339c
                                 "RESULT=%s", job_result_to_string(result),
a9339c
                                 NULL);
a9339c
         } else if (t == JOB_STOP || t == JOB_RESTART)
a9339c
                 log_unit_struct(u->id,
a9339c
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
a9339c
+                                job_result_log_level[result],
a9339c
                                 LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
a9339c
                                 LOG_MESSAGE("%s", buf),
a9339c
                                 "RESULT=%s", job_result_to_string(result),
a9339c
@@ -753,14 +764,14 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
a9339c
 
a9339c
         else if (t == JOB_RELOAD)
a9339c
                 log_unit_struct(u->id,
a9339c
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
a9339c
+                                job_result_log_level[result],
a9339c
                                 LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
a9339c
                                 LOG_MESSAGE("%s", buf),
a9339c
                                 "RESULT=%s", job_result_to_string(result),
a9339c
                                 NULL);
a9339c
         else
a9339c
                 log_unit_struct(u->id,
a9339c
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
a9339c
+                                job_result_log_level[result],
a9339c
                                 LOG_MESSAGE("%s", buf),
a9339c
                                 "RESULT=%s", job_result_to_string(result),
a9339c
                                 NULL);