va_list ap;
int r;
+ if (u && !unit_log_level_test(u, level))
+ return -ERRNO_VALUE(error);
+
va_start(ap, format);
if (u)
r = log_object_internalv(level, error, file, line, func,
value > NOTICEWORTHY_IP_BYTES);
}
+ /* This check is here because it is the earliest point following all possible log_level assignments. If
+ * log_level is assigned anywhere after this point, move this check. */
+ if (!unit_log_level_test(u, log_level)) {
+ r = 0;
+ goto finish;
+ }
+
if (have_ip_accounting) {
if (any_traffic) {
if (igress)
t = strjoina(u->manager->invocation_log_field, u->invocation_id_string);
iovec[n_iovec + 3] = IOVEC_MAKE_STRING(t);
- log_struct_iovec(log_level, iovec, n_iovec + 4);
+ log_unit_struct_iovec(u, log_level, iovec, n_iovec + 4);
r = 0;
finish:
return 0;
}
-ExecContext *unit_get_exec_context(Unit *u) {
+ExecContext *unit_get_exec_context(const Unit *u) {
size_t offset;
assert(u);
assert(u);
assert(where);
+ if (!unit_log_level_test(u, LOG_NOTICE))
+ return;
+
r = dir_is_empty(where);
if (r > 0 || r == -ENOTDIR)
return;
return;
}
- log_struct(LOG_NOTICE,
- "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR,
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u),
- LOG_UNIT_MESSAGE(u, "Directory %s to mount over is not empty, mounting anyway.", where),
- "WHERE=%s", where);
+ log_unit_struct(u, LOG_NOTICE,
+ "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR,
+ LOG_UNIT_INVOCATION_ID(u),
+ LOG_UNIT_MESSAGE(u, "Directory %s to mount over is not empty, mounting anyway.", where),
+ "WHERE=%s", where);
}
int unit_fail_if_noncanonical(Unit *u, const char* where) {
return 0;
/* No need to mention "." or "..", they would already have been rejected by unit_name_from_path() */
- log_struct(LOG_ERR,
- "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR,
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u),
- LOG_UNIT_MESSAGE(u, "Mount path %s is not canonical (contains a symlink).", where),
- "WHERE=%s", where);
+ log_unit_struct(u, LOG_ERR,
+ "MESSAGE_ID=" SD_MESSAGE_OVERMOUNTING_STR,
+ LOG_UNIT_INVOCATION_ID(u),
+ LOG_UNIT_MESSAGE(u, "Mount path %s is not canonical (contains a symlink).", where),
+ "WHERE=%s", where);
return -ELOOP;
}
void unit_log_success(Unit *u) {
assert(u);
- log_struct(LOG_INFO,
- "MESSAGE_ID=" SD_MESSAGE_UNIT_SUCCESS_STR,
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u),
- LOG_UNIT_MESSAGE(u, "Deactivated successfully."));
+ log_unit_struct(u, LOG_INFO,
+ "MESSAGE_ID=" SD_MESSAGE_UNIT_SUCCESS_STR,
+ LOG_UNIT_INVOCATION_ID(u),
+ LOG_UNIT_MESSAGE(u, "Deactivated successfully."));
}
void unit_log_failure(Unit *u, const char *result) {
assert(u);
assert(result);
- log_struct(LOG_WARNING,
- "MESSAGE_ID=" SD_MESSAGE_UNIT_FAILURE_RESULT_STR,
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u),
- LOG_UNIT_MESSAGE(u, "Failed with result '%s'.", result),
- "UNIT_RESULT=%s", result);
+ log_unit_struct(u, LOG_WARNING,
+ "MESSAGE_ID=" SD_MESSAGE_UNIT_FAILURE_RESULT_STR,
+ LOG_UNIT_INVOCATION_ID(u),
+ LOG_UNIT_MESSAGE(u, "Failed with result '%s'.", result),
+ "UNIT_RESULT=%s", result);
}
void unit_log_skip(Unit *u, const char *result) {
assert(u);
assert(result);
- log_struct(LOG_INFO,
- "MESSAGE_ID=" SD_MESSAGE_UNIT_SKIPPED_STR,
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u),
- LOG_UNIT_MESSAGE(u, "Skipped due to '%s'.", result),
- "UNIT_RESULT=%s", result);
+ log_unit_struct(u, LOG_INFO,
+ "MESSAGE_ID=" SD_MESSAGE_UNIT_SKIPPED_STR,
+ LOG_UNIT_INVOCATION_ID(u),
+ LOG_UNIT_MESSAGE(u, "Skipped due to '%s'.", result),
+ "UNIT_RESULT=%s", result);
}
void unit_log_process_exit(
else
level = LOG_WARNING;
- log_struct(level,
- "MESSAGE_ID=" SD_MESSAGE_UNIT_PROCESS_EXIT_STR,
- LOG_UNIT_MESSAGE(u, "%s exited, code=%s, status=%i/%s",
- kind,
- 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,
- "COMMAND=%s", strna(command),
- LOG_UNIT_ID(u),
- LOG_UNIT_INVOCATION_ID(u));
+ log_unit_struct(u, level,
+ "MESSAGE_ID=" SD_MESSAGE_UNIT_PROCESS_EXIT_STR,
+ LOG_UNIT_MESSAGE(u, "%s exited, code=%s, status=%i/%s",
+ kind,
+ 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,
+ "COMMAND=%s", strna(command),
+ LOG_UNIT_INVOCATION_ID(u));
}
int unit_exit_status(Unit *u) {