From: Zbigniew Jędrzejewski-Szmek Date: Mon, 8 Oct 2012 17:02:30 +0000 (+0000) Subject: log: introduce a macro to format message id X-Git-Tag: upstream/195~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ca6783f5ea3755bd83e723f529c2eda512c7fed;p=platform%2Fupstream%2Fsystemd.git log: introduce a macro to format message id 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. --- diff --git a/src/core/job.c b/src/core/job.c index 706910b..cb5674b 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -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, diff --git a/src/core/manager.c b/src/core/manager.c index 6fecbc3..b19fc3d 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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), diff --git a/src/core/unit.c b/src/core/unit.c index ae43545..6396bfc 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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); diff --git a/src/journal/journald.c b/src/journal/journald.c index 0910d7d..4dcf7d3 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -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); } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index cbf43fe..b95cc9b 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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); } diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 0ae0c52..470d08b 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -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); diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 958b516..5d9401b 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -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, diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 71c7518..2f31267 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -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); diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h index 05521ae..fa17be8 100644 --- a/src/systemd/sd-id128.h +++ b/src/systemd/sd-id128.h @@ -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 } diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 8c589ba..40ba255 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -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);