log_target = target;
}
+void log_set_target_and_open(LogTarget target) {
+ log_set_target(target);
+ log_open();
+}
+
void log_close(void) {
/* Do not call from library code. */
const char *log_target_to_string(LogTarget target) _const_;
LogTarget log_target_from_string(const char *s) _pure_;
void log_set_target(LogTarget target);
+void log_set_target_and_open(LogTarget target);
int log_set_target_from_string(const char *e);
LogTarget log_get_target(void) _pure_;
if (detect_container() <= 0) {
/* Running outside of a container as PID 1 */
- log_set_target(LOG_TARGET_KMSG);
- log_open();
+ log_set_target_and_open(LOG_TARGET_KMSG);
if (in_initrd())
initrd_timestamp = userspace_timestamp;
} else {
/* Running inside a container, as PID 1 */
- log_set_target(LOG_TARGET_CONSOLE);
- log_open();
+ log_set_target_and_open(LOG_TARGET_CONSOLE);
/* For later on, see above... */
log_set_target(LOG_TARGET_JOURNAL);
/* Running as user instance */
arg_system = false;
log_set_always_reopen_console(true);
- log_set_target(LOG_TARGET_AUTO);
- log_open();
+ log_set_target_and_open(LOG_TARGET_AUTO);
/* clear the kernel timestamp, because we are not PID 1 */
kernel_timestamp = DUAL_TIMESTAMP_NULL;
if (r < 0)
goto finish;
- if (!context.is_journald) {
+ if (!context.is_journald)
/* OK, now we know it's not the journal, hence we can make use of it now. */
- log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
- log_open();
- }
+ log_set_target_and_open(LOG_TARGET_JOURNAL_OR_KMSG);
/* If this is PID 1 disable coredump collection, we'll unlikely be able to process
* it later on.
/* First, log to a safe place, since we don't know what crashed and it might
* be journald which we'd rather not log to then. */
- log_set_target(LOG_TARGET_KMSG);
- log_open();
+ log_set_target_and_open(LOG_TARGET_KMSG);
/* Make sure we never enter a loop */
(void) prctl(PR_SET_DUMPABLE, 0);
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t);
log_info("Setting log target to %s.", log_target_to_string(target));
- log_set_target(target);
- log_open();
+ log_set_target_and_open(target);
return 0;
}