chiark / gitweb /
log: introduce a macro to format message id
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 8 Oct 2012 17:02:30 +0000 (17:02 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Oct 2012 12:26:30 +0000 (14:26 +0200)
The MESSAGE_ID=... stanza will appear in countless number of places.
It is just too long to write it out in full each time.

Incidentally, this also fixes a typo of MESSSAGE is three places.

src/core/job.c
src/core/manager.c
src/core/unit.c
src/journal/journald.c
src/login/logind-dbus.c
src/login/logind-seat.c
src/login/logind-session.c
src/sleep/sleep.c
src/systemd/sd-id128.h
src/timedate/timedated.c

index 706910b..cb5674b 100644 (file)
@@ -705,7 +705,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
 
                 mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
                 log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(mid),
+                           MESSAGE_ID(mid),
                            "UNIT=%s", u->id,
                            "RESULT=%s", job_result_to_string(result),
                            "MESSAGE=%s", buf,
@@ -713,7 +713,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
 
         } else if (t == JOB_STOP)
                 log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_UNIT_STOPPED),
+                           MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
                            "UNIT=%s", u->id,
                            "RESULT=%s", job_result_to_string(result),
                            "MESSAGE=%s", buf,
@@ -721,7 +721,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
 
         else if (t == JOB_RELOAD)
                 log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_UNIT_RELOADED),
+                           MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
                            "UNIT=%s", u->id,
                            "RESULT=%s", job_result_to_string(result),
                            "MESSAGE=%s", buf,
index 6fecbc3..b19fc3d 100644 (file)
@@ -2039,7 +2039,7 @@ void manager_check_finished(Manager *m) {
 
                         if (!log_on_console())
                                 log_struct(LOG_INFO,
-                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           MESSAGE_ID(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,
@@ -2055,7 +2055,7 @@ void manager_check_finished(Manager *m) {
 
                         if (!log_on_console())
                                 log_struct(LOG_INFO,
-                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           MESSAGE_ID(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.",
@@ -2070,7 +2070,7 @@ void manager_check_finished(Manager *m) {
 
                 if (!log_on_console())
                         log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                   MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                                    "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
                                    "MESSAGE=Startup finished in %s.",
                                    format_timespan(sum, sizeof(sum), total_usec),
index ae43545..6396bfc 100644 (file)
@@ -1023,7 +1023,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
                                SD_MESSAGE_UNIT_RELOADING;
 
         log_struct(LOG_INFO,
-                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(mid),
+                   MESSAGE_ID(mid),
                    "UNIT=%s", u->id,
                    "MESSAGE=%s", buf,
                    NULL);
index 0910d7d..4dcf7d3 100644 (file)
@@ -725,7 +725,7 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
         IOVEC_SET_STRING(iovec[n++], buffer);
 
         if (!sd_id128_equal(message_id, SD_ID128_NULL)) {
-                snprintf(mid, sizeof(mid), "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(message_id));
+                snprintf(mid, sizeof(mid), MESSAGE_ID(message_id));
                 char_array_0(mid);
                 IOVEC_SET_STRING(iovec[n++], mid);
         }
index cbf43fe..b95cc9b 100644 (file)
@@ -1180,8 +1180,7 @@ static int bus_manager_log_shutdown(
                 q = NULL;
         }
 
-        return log_struct(LOG_NOTICE,
-                          "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SHUTDOWN),
+        return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                           p,
                           q, NULL);
 }
index 0ae0c52..470d08b 100644 (file)
@@ -341,7 +341,7 @@ int seat_start(Seat *s) {
                 return 0;
 
         log_struct(LOG_INFO,
-                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SEAT_START),
+                   MESSAGE_ID(SD_MESSAGE_SEAT_START),
                    "SEAT_ID=%s", s->id,
                    "MESSAGE=New seat %s.", s->id,
                    NULL);
@@ -369,7 +369,7 @@ int seat_stop(Seat *s) {
 
         if (s->started)
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SEAT_STOP),
+                           MESSAGE_ID(SD_MESSAGE_SEAT_STOP),
                            "SEAT_ID=%s", s->id,
                            "MESSAGE=Removed seat %s.", s->id,
                            NULL);
index 958b516..5d9401b 100644 (file)
@@ -547,7 +547,7 @@ int session_start(Session *s) {
                 return r;
 
         log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_START),
+                   MESSAGE_ID(SD_MESSAGE_SESSION_START),
                    "SESSION_ID=%s", s->id,
                    "USER_ID=%s", s->user->name,
                    "LEADER=%lu", (unsigned long) s->leader,
@@ -689,7 +689,7 @@ int session_stop(Session *s) {
 
         if (s->started)
                 log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_STOP),
+                           MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
                            "SESSION_ID=%s", s->id,
                            "USER_ID=%s", s->user->name,
                            "LEADER=%lu", (unsigned long) s->leader,
index 71c7518..2f31267 100644 (file)
@@ -69,13 +69,13 @@ int main(int argc, char *argv[]) {
 
         if (streq(argv[1], "suspend"))
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_START),
+                           MESSAGE_ID(SD_MESSAGE_SLEEP_START),
                            "MESSAGE=Suspending system...",
                            "SLEEP=suspend",
                            NULL);
         else
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_START),
+                           MESSAGE_ID(SD_MESSAGE_SLEEP_START),
                            "MESSAGE=Hibernating system...",
                            "SLEEP=hibernate",
                            NULL);
@@ -88,13 +88,13 @@ int main(int argc, char *argv[]) {
 
         if (streq(argv[1], "suspend"))
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_STOP),
+                           MESSAGE_ID(SD_MESSAGE_SLEEP_STOP),
                            "MESSAGE=System resumed.",
                            "SLEEP=suspend",
                            NULL);
         else
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_STOP),
+                           MESSAGE_ID(SD_MESSAGE_SLEEP_STOP),
                            "MESSAGE=System thawed.",
                            "SLEEP=hibernate",
                            NULL);
index 05521ae..fa17be8 100644 (file)
@@ -65,6 +65,7 @@ static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
 }
 
 #define SD_ID128_NULL ((sd_id128_t) { .qwords = { 0, 0 }})
+#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)
 
 #ifdef __cplusplus
 }
index 8c589ba..40ba255 100644 (file)
@@ -701,7 +701,7 @@ static DBusHandlerResult timedate_message_handler(
                         }
 
                         log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_TIMEZONE_CHANGE),
+                                   MESSAGE_ID(SD_MESSAGE_TIMEZONE_CHANGE),
                                    "TIMEZONE=%s", tz.zone,
                                    "MESSAGE=Changed timezone to '%s'.", tz.zone,
                                    NULL);
@@ -843,7 +843,7 @@ static DBusHandlerResult timedate_message_handler(
                         hwclock_set_time(tm);
 
                         log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_TIME_CHANGE),
+                                   MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
                                    "REALTIME=%llu", (unsigned long long) timespec_load(&ts),
                                    "MESSAGE=Changed local time to %s", ctime(&ts.tv_sec),
                                    NULL);