daandemeyer / rpms / systemd

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