chiark / gitweb /
journal: suppress structured messages if they'd go to the console
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Aug 2012 20:43:33 +0000 (22:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 4 Sep 2012 01:59:04 +0000 (18:59 -0700)
src/core/job.c
src/core/manager.c
src/core/unit.c
src/shared/log.c
src/shared/log.h

index 9614642..706910b 100644 (file)
@@ -687,6 +687,12 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
         assert(t >= 0);
         assert(t < _JOB_TYPE_MAX);
 
+        /* Skip this if it goes to the console. since we already print
+         * to the console anyway... */
+
+        if (log_on_console())
+                return;
+
         format = job_get_status_message_format_try_harder(u, t, result);
         if (!format)
                 return;
index da766e6..40b0c50 100644 (file)
@@ -2032,41 +2032,44 @@ void manager_check_finished(Manager *m) {
                         kernel_usec = m->initrd_timestamp.monotonic;
                         initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
 
-                        log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
-                                   "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
-                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                   format_timespan(initrd, sizeof(initrd), initrd_usec),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                   format_timespan(sum, sizeof(sum), total_usec),
-                                   NULL);
+                        if (!log_on_console())
+                                log_struct(LOG_INFO,
+                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                           "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
+                                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                           "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
+                                           format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                           format_timespan(initrd, sizeof(initrd), initrd_usec),
+                                           format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                           format_timespan(sum, sizeof(sum), total_usec),
+                                           NULL);
                 } else {
                         kernel_usec = m->startup_timestamp.monotonic;
                         initrd_usec = 0;
 
-                        log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
-                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                   format_timespan(sum, sizeof(sum), total_usec),
-                                   NULL);
+                        if (!log_on_console())
+                                log_struct(LOG_INFO,
+                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                           "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
+                                           format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                           format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                           format_timespan(sum, sizeof(sum), total_usec),
+                                           NULL);
                 }
         } else {
                 initrd_usec = kernel_usec = 0;
                 total_usec = userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
 
-                log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                           "MESSAGE=Startup finished in %s.",
-                           format_timespan(sum, sizeof(sum), total_usec),
-                           NULL);
+                if (!log_on_console())
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                   "MESSAGE=Startup finished in %s.",
+                                   format_timespan(sum, sizeof(sum), total_usec),
+                                   NULL);
         }
 
         bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
index 8246837..ba4c7d5 100644 (file)
@@ -1004,6 +1004,9 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
         if (t != JOB_START && t != JOB_STOP && t != JOB_RELOAD)
                 return;
 
+        if (log_on_console())
+                return;
+
         /* We log status messages for all units and all operations. */
 
         format = unit_get_status_message_format_try_harder(u, t);
index 67a3e1b..847202d 100644 (file)
@@ -859,6 +859,13 @@ int log_show_location_from_string(const char *e) {
         return 0;
 }
 
+bool log_on_console(void) {
+        if (log_target == LOG_TARGET_CONSOLE)
+                return true;
+
+        return syslog_fd < 0 && kmsg_fd < 0 && journal_fd < 0;
+}
+
 static const char *const log_target_table[] = {
         [LOG_TARGET_CONSOLE] = "console",
         [LOG_TARGET_KMSG] = "kmsg",
index 0c60b76..c242cc2 100644 (file)
@@ -131,5 +131,7 @@ _noreturn_ void log_assert_failed_unreachable(
 /* This modifies the buffer passed! */
 #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
 
+bool log_on_console(void);
+
 const char *log_target_to_string(LogTarget target);
 LogTarget log_target_from_string(const char *s);