chiark / gitweb /
log: fix order of log_unit_struct() to match other logging calls
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 01:05:14 +0000 (02:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 01:18:46 +0000 (02:18 +0100)
Also, while we are at it, introduce some syntactic sugar for creating
ERRNO= and MESSAGE= structured logging fields.

17 files changed:
src/core/execute.c
src/core/job.c
src/core/manager.c
src/core/mount.c
src/core/service.c
src/core/unit.c
src/core/unit.h
src/journal/journald-server.c
src/login/logind-button.c
src/login/logind-dbus.c
src/login/logind-seat.c
src/login/logind-session.c
src/machine/machine.c
src/shared/conf-parser.c
src/shared/log.h
src/sleep/sleep.c
src/timedate/timedated.c

index dd182f5..a48c15d 100644 (file)
@@ -426,12 +426,13 @@ static int setup_output(const ExecContext *context, int fileno, int socket_fd, c
         case EXEC_OUTPUT_JOURNAL_AND_CONSOLE:
                 r = connect_logger_as(context, o, ident, unit_id, fileno);
                 if (r < 0) {
-                        log_unit_struct(LOG_CRIT, unit_id,
-                                "MESSAGE=Failed to connect std%s of %s to the journal socket: %s",
-                                fileno == STDOUT_FILENO ? "out" : "err",
-                                unit_id, strerror(-r),
-                                "ERRNO=%d", -r,
-                                NULL);
+                        log_unit_struct(unit_id,
+                                        LOG_CRIT,
+                                        LOG_MESSAGE("Failed to connect %s of %s to the journal socket: %s",
+                                                    fileno == STDOUT_FILENO ? "stdout" : "stderr",
+                                                    unit_id, strerror(-r)),
+                                        LOG_ERRNO(-r),
+                                        NULL);
                         r = open_null_as(O_WRONLY, fileno);
                 }
                 return r;
@@ -1751,10 +1752,10 @@ static int exec_child(ExecCommand *command,
                 line = exec_command_line(final_argv);
                 if (line) {
                         log_open();
-                        log_unit_struct(LOG_DEBUG,
-                                        params->unit_id,
+                        log_unit_struct(params->unit_id,
+                                        LOG_DEBUG,
                                         "EXECUTABLE=%s", command->path,
-                                        "MESSAGE=Executing: %s", line,
+                                        LOG_MESSAGE("Executing: %s", line),
                                         NULL);
                         log_close();
                 }
@@ -1799,11 +1800,11 @@ int exec_spawn(ExecCommand *command,
 
         err = exec_context_load_environment(context, params->unit_id, &files_env);
         if (err < 0) {
-                log_unit_struct(LOG_ERR,
-                           params->unit_id,
-                           "MESSAGE=Failed to load environment files: %s", strerror(-err),
-                           "ERRNO=%d", -err,
-                           NULL);
+                log_unit_struct(params->unit_id,
+                                LOG_ERR,
+                                LOG_MESSAGE("Failed to load environment files: %s", strerror(-err)),
+                                LOG_ERRNO(-err),
+                                NULL);
                 return err;
         }
 
@@ -1813,10 +1814,10 @@ int exec_spawn(ExecCommand *command,
         if (!line)
                 return log_oom();
 
-        log_unit_struct(LOG_DEBUG,
-                        params->unit_id,
+        log_unit_struct(params->unit_id,
+                        LOG_DEBUG,
                         "EXECUTABLE=%s", command->path,
-                        "MESSAGE=About to execute: %s", line,
+                        LOG_MESSAGE("About to execute: %s", line),
                         NULL);
         free(line);
 
@@ -1838,12 +1839,13 @@ int exec_spawn(ExecCommand *command,
                                  &r);
                 if (r != 0) {
                         log_open();
-                        log_struct(LOG_ERR, MESSAGE_ID(SD_MESSAGE_SPAWN_FAILED),
+                        log_struct(LOG_ERR,
+                                   LOG_MESSAGE_ID(SD_MESSAGE_SPAWN_FAILED),
                                    "EXECUTABLE=%s", command->path,
-                                   "MESSAGE=Failed at step %s spawning %s: %s",
-                                          exit_status_to_string(r, EXIT_STATUS_SYSTEMD),
-                                          command->path, strerror(-err),
-                                   "ERRNO=%d", -err,
+                                   LOG_MESSAGE("Failed at step %s spawning %s: %s",
+                                               exit_status_to_string(r, EXIT_STATUS_SYSTEMD),
+                                               command->path, strerror(-err)),
+                                   LOG_ERRNO(-err),
                                    NULL);
                         log_close();
                 }
@@ -1851,10 +1853,10 @@ int exec_spawn(ExecCommand *command,
                 _exit(r);
         }
 
-        log_unit_struct(LOG_DEBUG,
-                        params->unit_id,
-                        "MESSAGE=Forked %s as "PID_FMT,
-                        command->path, pid,
+        log_unit_struct(params->unit_id,
+                        LOG_DEBUG,
+                        LOG_MESSAGE("Forked %s as "PID_FMT,
+                                    command->path, pid),
                         NULL);
 
         /* We add the new process to the cgroup both in the child (so
index 80fdbde..8968091 100644 (file)
@@ -730,28 +730,28 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
                 sd_id128_t mid;
 
                 mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
-                log_unit_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           u->id,
-                           MESSAGE_ID(mid),
-                           "RESULT=%s", job_result_to_string(result),
-                           "MESSAGE=%s", buf,
-                           NULL);
+                log_unit_struct(u->id,
+                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                                LOG_MESSAGE_ID(mid),
+                                LOG_MESSAGE("%s", buf),
+                                "RESULT=%s", job_result_to_string(result),
+                                NULL);
 
         } else if (t == JOB_STOP)
-                log_unit_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           u->id,
-                           MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
-                           "RESULT=%s", job_result_to_string(result),
-                           "MESSAGE=%s", buf,
-                           NULL);
+                log_unit_struct(u->id,
+                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                                LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
+                                LOG_MESSAGE("%s", buf),
+                                "RESULT=%s", job_result_to_string(result),
+                                NULL);
 
         else if (t == JOB_RELOAD)
-                log_unit_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
-                           u->id,
-                           MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
-                           "RESULT=%s", job_result_to_string(result),
-                           "MESSAGE=%s", buf,
-                           NULL);
+                log_unit_struct(u->id,
+                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                                LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
+                                LOG_MESSAGE("%s", buf),
+                                "RESULT=%s", job_result_to_string(result),
+                                NULL);
 }
 
 int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
@@ -837,15 +837,15 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
          * this context. And JOB_FAILURE is already handled by the
          * unit itself. */
         if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY) {
-                log_unit_struct(LOG_NOTICE,
-                           u->id,
-                           "JOB_TYPE=%s", job_type_to_string(t),
-                           "JOB_RESULT=%s", job_result_to_string(result),
-                           "Job %s/%s failed with result '%s'.",
-                           u->id,
-                           job_type_to_string(t),
-                           job_result_to_string(result),
-                           NULL);
+                log_unit_struct(u->id,
+                                LOG_NOTICE,
+                                "JOB_TYPE=%s", job_type_to_string(t),
+                                "JOB_RESULT=%s", job_result_to_string(result),
+                                LOG_MESSAGE("Job %s/%s failed with result '%s'.",
+                                            u->id,
+                                            job_type_to_string(t),
+                                            job_result_to_string(result)),
+                                NULL);
 
                 unit_start_on_failure(u);
         }
index 0d1f5bb..63102d1 100644 (file)
@@ -1881,8 +1881,8 @@ static int manager_dispatch_time_change_fd(sd_event_source *source, int fd, uint
         assert(m->time_change_fd == fd);
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
-                   "MESSAGE=Time has been changed",
+                   LOG_MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
+                   LOG_MESSAGE("Time has been changed"),
                    NULL);
 
         /* Restart the watch */
@@ -2590,28 +2590,28 @@ static void manager_notify_finished(Manager *m) {
                         initrd_usec = m->userspace_timestamp.monotonic - m->initrd_timestamp.monotonic;
 
                         log_struct(LOG_INFO,
-                                   MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                                    "KERNEL_USEC="USEC_FMT, kernel_usec,
                                    "INITRD_USEC="USEC_FMT, initrd_usec,
                                    "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
-                                   format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
-                                   format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                                   LOG_MESSAGE("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
+                                               format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
+                                               format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
+                                               format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
+                                               format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                                    NULL);
                 } else {
                         kernel_usec = m->userspace_timestamp.monotonic - m->kernel_timestamp.monotonic;
                         initrd_usec = 0;
 
                         log_struct(LOG_INFO,
-                                   MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                                    "KERNEL_USEC="USEC_FMT, kernel_usec,
                                    "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
-                                   format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                                   LOG_MESSAGE("Startup finished in %s (kernel) + %s (userspace) = %s.",
+                                               format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
+                                               format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
+                                               format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                                    NULL);
                 }
         } else {
@@ -2619,10 +2619,10 @@ static void manager_notify_finished(Manager *m) {
                 total_usec = userspace_usec = m->finish_timestamp.monotonic - m->userspace_timestamp.monotonic;
 
                 log_struct(LOG_INFO,
-                           MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
+                           LOG_MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
                            "USERSPACE_USEC="USEC_FMT, userspace_usec,
-                           "MESSAGE=Startup finished in %s.",
-                           format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
+                           LOG_MESSAGE("Startup finished in %s.",
+                                       format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC)),
                            NULL);
         }
 
index 36375f6..d34699b 100644 (file)
@@ -823,12 +823,12 @@ void warn_if_dir_nonempty(const char *unit, const char* where) {
         if (r > 0)
                 return;
         else if (r == 0)
-                log_unit_struct(LOG_NOTICE,
-                                unit,
-                                "MESSAGE=%s: Directory %s to mount over is not empty, mounting anyway.",
-                                unit, where,
+                log_unit_struct(unit,
+                                LOG_NOTICE,
+                                LOG_MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
+                                LOG_MESSAGE("%s: Directory %s to mount over is not empty, mounting anyway.",
+                                            unit, where),
                                 "WHERE=%s", where,
-                                MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
                                 NULL);
         else
                 log_unit_warning(unit,
@@ -840,12 +840,12 @@ static int fail_if_symlink(const char *unit, const char* where) {
         assert(where);
 
         if (is_symlink(where) > 0) {
-                log_unit_struct(LOG_WARNING,
-                                unit,
-                                "MESSAGE=%s: Mount on symlink %s not allowed.",
-                                unit, where,
+                log_unit_struct(unit,
+                                LOG_ERR,
+                                LOG_MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
+                                LOG_MESSAGE("%s: Mount on symlink %s not allowed.",
+                                            unit, where),
                                 "WHERE=%s", where,
-                                MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
                                 NULL);
 
                 return -ELOOP;
index 72e8f71..a55be8f 100644 (file)
@@ -2205,16 +2205,16 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                                 f = SERVICE_SUCCESS;
                 }
 
-                log_unit_struct(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
-                           u->id,
-                           "MESSAGE=%s: main process exited, code=%s, status=%i/%s",
-                                  u->id, sigchld_code_to_string(code), status,
-                                  strna(code == CLD_EXITED
-                                        ? exit_status_to_string(status, EXIT_STATUS_FULL)
-                                        : signal_to_string(status)),
-                           "EXIT_CODE=%s", sigchld_code_to_string(code),
-                           "EXIT_STATUS=%i", status,
-                           NULL);
+                log_unit_struct(u->id,
+                                f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
+                                LOG_MESSAGE("%s: main process exited, code=%s, status=%i/%s",
+                                            u->id, sigchld_code_to_string(code), status,
+                                            strna(code == CLD_EXITED
+                                                  ? exit_status_to_string(status, EXIT_STATUS_FULL)
+                                                  : signal_to_string(status))),
+                                "EXIT_CODE=%s", sigchld_code_to_string(code),
+                                "EXIT_STATUS=%i", status,
+                                NULL);
 
                 if (f != SERVICE_SUCCESS)
                         s->result = f;
index 2e8df7d..88cddbd 100644 (file)
@@ -1394,10 +1394,10 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
               t == JOB_STOP  ? SD_MESSAGE_UNIT_STOPPING :
                                SD_MESSAGE_UNIT_RELOADING;
 
-        log_unit_struct(LOG_INFO,
-                        u->id,
-                        MESSAGE_ID(mid),
-                        "MESSAGE=%s", buf,
+        log_unit_struct(u->id,
+                        LOG_INFO,
+                        LOG_MESSAGE_ID(mid),
+                        LOG_MESSAGE("%s", buf),
                         NULL);
 }
 
index 5c0fba7..5983a51 100644 (file)
@@ -605,4 +605,4 @@ UnitActiveState unit_active_state_from_string(const char *s) _pure_;
 #define log_unit_warning(unit, ...)     log_unit_full(unit, LOG_WARNING, __VA_ARGS__)
 #define log_unit_error(unit, ...)       log_unit_full(unit, LOG_ERR, __VA_ARGS__)
 
-#define log_unit_struct(level, unit, ...) log_struct(level, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__)
+#define log_unit_struct(unit, level, ...) log_struct(level, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__)
index cd4843c..4fd2069 100644 (file)
@@ -841,7 +841,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(message_id));
+                snprintf(mid, sizeof(mid), LOG_MESSAGE_ID(message_id));
                 char_array_0(mid);
                 IOVEC_SET_STRING(iovec[n++], mid);
         }
index 57e619e..e380dc0 100644 (file)
@@ -159,8 +159,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
                 case KEY_POWER:
                 case KEY_POWER2:
                         log_struct(LOG_INFO,
-                                   "MESSAGE=Power key pressed.",
-                                   MESSAGE_ID(SD_MESSAGE_POWER_KEY),
+                                   LOG_MESSAGE("Power key pressed."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_POWER_KEY),
                                    NULL);
 
                         manager_handle_action(b->manager, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true);
@@ -174,8 +174,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 case KEY_SLEEP:
                         log_struct(LOG_INFO,
-                                   "MESSAGE=Suspend key pressed.",
-                                   MESSAGE_ID(SD_MESSAGE_SUSPEND_KEY),
+                                   LOG_MESSAGE("Suspend key pressed."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_SUSPEND_KEY),
                                    NULL);
 
                         manager_handle_action(b->manager, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true);
@@ -183,8 +183,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 case KEY_SUSPEND:
                         log_struct(LOG_INFO,
-                                   "MESSAGE=Hibernate key pressed.",
-                                   MESSAGE_ID(SD_MESSAGE_HIBERNATE_KEY),
+                                   LOG_MESSAGE("Hibernate key pressed."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_HIBERNATE_KEY),
                                    NULL);
 
                         manager_handle_action(b->manager, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true);
@@ -195,8 +195,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 if (ev.code == SW_LID) {
                         log_struct(LOG_INFO,
-                                   "MESSAGE=Lid closed.",
-                                   MESSAGE_ID(SD_MESSAGE_LID_CLOSED),
+                                   LOG_MESSAGE("Lid closed."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_LID_CLOSED),
                                    NULL);
 
                         b->lid_closed = true;
@@ -205,8 +205,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 } else if (ev.code == SW_DOCK) {
                         log_struct(LOG_INFO,
-                                   "MESSAGE=System docked.",
-                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_DOCKED),
+                                   LOG_MESSAGE("System docked."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_SYSTEM_DOCKED),
                                    NULL);
 
                         b->docked = true;
@@ -216,8 +216,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 if (ev.code == SW_LID) {
                         log_struct(LOG_INFO,
-                                   "MESSAGE=Lid opened.",
-                                   MESSAGE_ID(SD_MESSAGE_LID_OPENED),
+                                   LOG_MESSAGE("Lid opened."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_LID_OPENED),
                                    NULL);
 
                         b->lid_closed = false;
@@ -225,8 +225,8 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
 
                 } else if (ev.code == SW_DOCK) {
                         log_struct(LOG_INFO,
-                                   "MESSAGE=System undocked.",
-                                   MESSAGE_ID(SD_MESSAGE_SYSTEM_UNDOCKED),
+                                   LOG_MESSAGE("System undocked."),
+                                   LOG_MESSAGE_ID(SD_MESSAGE_SYSTEM_UNDOCKED),
                                    NULL);
 
                         b->docked = false;
index f18d210..d225ba1 100644 (file)
@@ -1300,9 +1300,11 @@ static int bus_manager_log_shutdown(
                 q = NULL;
         }
 
-        return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
+        return log_struct(LOG_NOTICE,
+                          LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                           p,
-                          q, NULL);
+                          q,
+                          NULL);
 }
 
 static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) {
index 9992195..709c638 100644 (file)
@@ -400,9 +400,9 @@ int seat_start(Seat *s) {
                 return 0;
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_SEAT_START),
+                   LOG_MESSAGE_ID(SD_MESSAGE_SEAT_START),
                    "SEAT_ID=%s", s->id,
-                   "MESSAGE=New seat %s.", s->id,
+                   LOG_MESSAGE("New seat %s.", s->id),
                    NULL);
 
         /* Initialize VT magic stuff */
@@ -428,9 +428,9 @@ int seat_stop(Seat *s, bool force) {
 
         if (s->started)
                 log_struct(LOG_INFO,
-                           MESSAGE_ID(SD_MESSAGE_SEAT_STOP),
+                           LOG_MESSAGE_ID(SD_MESSAGE_SEAT_STOP),
                            "SEAT_ID=%s", s->id,
-                           "MESSAGE=Removed seat %s.", s->id,
+                           LOG_MESSAGE("Removed seat %s.", s->id),
                            NULL);
 
         seat_stop_sessions(s, force);
index 65bbb77..c4fe53b 100644 (file)
@@ -549,11 +549,11 @@ int session_start(Session *s) {
                 return r;
 
         log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_SESSION_START),
+                   LOG_MESSAGE_ID(SD_MESSAGE_SESSION_START),
                    "SESSION_ID=%s", s->id,
                    "USER_ID=%s", s->user->name,
                    "LEADER="PID_FMT, s->leader,
-                   "MESSAGE=New session %s of user %s.", s->id, s->user->name,
+                   LOG_MESSAGE("New session %s of user %s.", s->id, s->user->name),
                    NULL);
 
         if (!dual_timestamp_is_set(&s->timestamp))
@@ -652,11 +652,11 @@ int session_finalize(Session *s) {
 
         if (s->started)
                 log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO,
-                           MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
+                           LOG_MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
                            "SESSION_ID=%s", s->id,
                            "USER_ID=%s", s->user->name,
                            "LEADER="PID_FMT, s->leader,
-                           "MESSAGE=Removed session %s.", s->id,
+                           LOG_MESSAGE("Removed session %s.", s->id),
                            NULL);
 
         s->timer_event_source = sd_event_source_unref(s->timer_event_source);
index 13d3448..a6d636e 100644 (file)
@@ -377,10 +377,10 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
                 return r;
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_MACHINE_START),
+                   LOG_MESSAGE_ID(SD_MESSAGE_MACHINE_START),
                    "NAME=%s", m->name,
                    "LEADER="PID_FMT, m->leader,
-                   "MESSAGE=New machine %s.", m->name,
+                   LOG_MESSAGE("New machine %s.", m->name),
                    NULL);
 
         if (!dual_timestamp_is_set(&m->timestamp))
@@ -426,10 +426,10 @@ int machine_stop(Machine *m) {
 
         if (m->started)
                 log_struct(LOG_INFO,
-                           MESSAGE_ID(SD_MESSAGE_MACHINE_STOP),
+                           LOG_MESSAGE_ID(SD_MESSAGE_MACHINE_STOP),
                            "NAME=%s", m->name,
                            "LEADER="PID_FMT, m->leader,
-                           "MESSAGE=Machine %s terminated.", m->name,
+                           LOG_MESSAGE("Machine %s terminated.", m->name),
                            NULL);
 
         /* Kill cgroup */
index 6bd9d9e..f9a3459 100644 (file)
@@ -64,19 +64,19 @@ int log_syntax_internal(
                                         error > 0 ? error : EINVAL,
                                         file, line, func,
                                         getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit,
-                                        MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
+                                        LOG_MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
                                         "CONFIG_FILE=%s", config_file,
                                         "CONFIG_LINE=%u", config_line,
-                                        "MESSAGE=[%s:%u] %s", config_file, config_line, msg,
+                                        LOG_MESSAGE("[%s:%u] %s", config_file, config_line, msg),
                                         NULL);
         else
                 r = log_struct_internal(level,
                                         error > 0 ? error : EINVAL,
                                         file, line, func,
-                                        MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
+                                        LOG_MESSAGE_ID(SD_MESSAGE_CONFIG_ERROR),
                                         "CONFIG_FILE=%s", config_file,
                                         "CONFIG_LINE=%u", config_line,
-                                        "MESSAGE=[%s:%u] %s", config_file, config_line, msg,
+                                        LOG_MESSAGE("[%s:%u] %s", config_file, config_line, msg),
                                         NULL);
 
         return r;
index 2780104..3a4d113 100644 (file)
@@ -199,7 +199,10 @@ bool log_on_console(void) _pure_;
 const char *log_target_to_string(LogTarget target) _const_;
 LogTarget log_target_from_string(const char *s) _pure_;
 
-#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)
+/* Helpers to prepare various fields for structured logging */
+#define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__
+#define LOG_MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)
+#define LOG_ERRNO(error) "ERRNO=%i", error
 
 void log_received_signal(int level, const struct signalfd_siginfo *si);
 
index ca00eea..0d7c1e3 100644 (file)
@@ -88,10 +88,16 @@ static int write_state(FILE **f, char **states) {
 }
 
 static int execute(char **modes, char **states) {
-        char* arguments[4];
+
+        char *arguments[] = {
+                NULL,
+                (char*) "pre",
+                arg_verb,
+                NULL
+        };
+
         int r;
         _cleanup_fclose_ FILE *f = NULL;
-        const char* note = strappenda("SLEEP=", arg_verb);
 
         /* This file is opened first, so that if we hit an error,
          * we can abort before modifying any state. */
@@ -106,16 +112,12 @@ static int execute(char **modes, char **states) {
         if (r < 0)
                 return r;
 
-        arguments[0] = NULL;
-        arguments[1] = (char*) "pre";
-        arguments[2] = arg_verb;
-        arguments[3] = NULL;
         execute_directory(SYSTEM_SLEEP_PATH, NULL, DEFAULT_TIMEOUT_USEC, arguments);
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_SLEEP_START),
-                   "MESSAGE=Suspending system...",
-                   note,
+                   LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_START),
+                   LOG_MESSAGE("Suspending system..."),
+                   "SLEEP=%s", arg_verb,
                    NULL);
 
         r = write_state(&f, states);
@@ -123,9 +125,9 @@ static int execute(char **modes, char **states) {
                 return r;
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_SLEEP_STOP),
-                   "MESSAGE=System resumed.",
-                   note,
+                   LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_STOP),
+                   LOG_MESSAGE("MESSAGE=System resumed."),
+                   "SLEEP=%s", arg_verb,
                    NULL);
 
         arguments[1] = (char*) "post";
index e720227..4af054e 100644 (file)
@@ -429,9 +429,9 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, s
         }
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_TIMEZONE_CHANGE),
+                   LOG_MESSAGE_ID(SD_MESSAGE_TIMEZONE_CHANGE),
                    "TIMEZONE=%s", c->zone,
-                   "MESSAGE=Changed time zone to '%s'.", c->zone,
+                   LOG_MESSAGE("Changed time zone to '%s'.", c->zone),
                    NULL);
 
         sd_bus_emit_properties_changed(bus, "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "Timezone", NULL);
@@ -581,9 +581,9 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
         clock_set_hwclock(tm);
 
         log_struct(LOG_INFO,
-                   MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
+                   LOG_MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
                    "REALTIME="USEC_FMT, timespec_load(&ts),
-                   "MESSAGE=Changed local time to %s", ctime(&ts.tv_sec),
+                   LOG_MESSAGE("Changed local time to %s", ctime(&ts.tv_sec)),
                    NULL);
 
         return sd_bus_reply_method_return(m, NULL);