diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/execute.c | 54 | ||||
-rw-r--r-- | src/core/job.c | 54 | ||||
-rw-r--r-- | src/core/manager.c | 32 | ||||
-rw-r--r-- | src/core/mount.c | 20 | ||||
-rw-r--r-- | src/core/service.c | 20 | ||||
-rw-r--r-- | src/core/unit.c | 8 | ||||
-rw-r--r-- | src/core/unit.h | 2 | ||||
-rw-r--r-- | src/journal/journald-server.c | 2 | ||||
-rw-r--r-- | src/login/logind-button.c | 28 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 6 | ||||
-rw-r--r-- | src/login/logind-seat.c | 8 | ||||
-rw-r--r-- | src/login/logind-session.c | 8 | ||||
-rw-r--r-- | src/machine/machine.c | 8 | ||||
-rw-r--r-- | src/shared/conf-parser.c | 8 | ||||
-rw-r--r-- | src/shared/log.h | 5 | ||||
-rw-r--r-- | src/sleep/sleep.c | 26 | ||||
-rw-r--r-- | src/timedate/timedated.c | 8 |
17 files changed, 153 insertions, 144 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index dd182f5564..a48c15d817 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -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 diff --git a/src/core/job.c b/src/core/job.c index 80fdbde5ab..8968091bdc 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -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); } diff --git a/src/core/manager.c b/src/core/manager.c index 0d1f5bb10e..63102d1785 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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); } diff --git a/src/core/mount.c b/src/core/mount.c index 36375f65bc..d34699bca8 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -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; diff --git a/src/core/service.c b/src/core/service.c index 72e8f71e5f..a55be8f3ac 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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; diff --git a/src/core/unit.c b/src/core/unit.c index 2e8df7d8d8..88cddbd023 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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); } diff --git a/src/core/unit.h b/src/core/unit.h index 5c0fba7cf2..5983a51477 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -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__) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index cd4843c986..4fd2069d81 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -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); } diff --git a/src/login/logind-button.c b/src/login/logind-button.c index 57e619efe6..e380dc0611 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -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; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index f18d21055a..d225ba1619 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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) { diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 9992195151..709c6385e6 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -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); diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 65bbb77750..c4fe53bc61 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -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); diff --git a/src/machine/machine.c b/src/machine/machine.c index 13d3448adf..a6d636ea49 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -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 */ diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 6bd9d9ebf7..f9a3459caa 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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; diff --git a/src/shared/log.h b/src/shared/log.h index 278010432d..3a4d1134a1 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -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); diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index ca00eea4ab..0d7c1e3fbe 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -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"; diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index e720227338..4af054e6b0 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -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); |