This is necessary to avoid buffering messages in incorrect format
(without the priority indicator).
// Initialise the logging subsystem
// Potentially throws std::bad_alloc or std::system_error
// Initialise the logging subsystem
// Potentially throws std::bad_alloc or std::system_error
-void init_log(service_set *sset)
+void init_log(service_set *sset, bool syslog_format)
{
services = sset;
log_stream[DLOG_CONS].add_watch(event_loop, STDOUT_FILENO, dasynq::OUT_EVENTS, false);
enable_console_log(true);
{
services = sset;
log_stream[DLOG_CONS].add_watch(event_loop, STDOUT_FILENO, dasynq::OUT_EVENTS, false);
enable_console_log(true);
+
+ // The main (non-console) log won't be active yet, but we set the format here so that we
+ // buffer messages in the correct format:
+ log_format_syslog[DLOG_MAIN] = syslog_format;
}
// Set up the main log to output to the given file descriptor.
// Potentially throws std::bad_alloc or std::system_error
}
// Set up the main log to output to the given file descriptor.
// Potentially throws std::bad_alloc or std::system_error
-void setup_main_log(int fd, bool syslog_format)
+void setup_main_log(int fd)
{
log_stream[DLOG_MAIN].init(fd);
log_stream[DLOG_MAIN].add_watch(event_loop, fd, dasynq::OUT_EVENTS);
{
log_stream[DLOG_MAIN].init(fd);
log_stream[DLOG_MAIN].add_watch(event_loop, fd, dasynq::OUT_EVENTS);
- log_format_syslog[DLOG_MAIN] = syslog_format;
}
bool is_log_flushed() noexcept
}
bool is_log_flushed() noexcept
// Try to open control socket (may fail due to readonly filesystem)
open_control_socket(false);
// Try to open control socket (may fail due to readonly filesystem)
open_control_socket(false);
- // Only try to set up the external log now if we aren't the system init. (If we are the
- // system init, wait until the log service starts).
- if (! am_system_init) setup_external_log();
-
#ifdef __linux__
if (am_system_init) {
// Disable non-critical kernel output to console
#ifdef __linux__
if (am_system_init) {
// Disable non-critical kernel output to console
services->add_service_dir("/lib/dinit.d", false);
}
services->add_service_dir("/lib/dinit.d", false);
}
+ init_log(services, log_is_syslog);
if (am_system_init) {
log(loglevel_t::INFO, false, "starting system");
}
if (am_system_init) {
log(loglevel_t::INFO, false, "starting system");
}
+ // Only try to set up the external log now if we aren't the system init. (If we are the
+ // system init, wait until the log service starts).
+ if (! am_system_init) setup_external_log();
+
if (env_file != nullptr) {
read_env_file(env_file);
}
if (env_file != nullptr) {
read_env_file(env_file);
}
// the file descriptor so we will be notified when it's ready. In other words we can
// basically use it anyway.
try {
// the file descriptor so we will be notified when it's ready. In other words we can
// basically use it anyway.
try {
- setup_main_log(sockfd, true);
+ setup_main_log(sockfd);
}
catch (std::exception &e) {
log(loglevel_t::ERROR, "Setting up log failed: ", e.what());
}
catch (std::exception &e) {
log(loglevel_t::ERROR, "Setting up log failed: ", e.what());
int log_fd = open(log_path, O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK | O_CLOEXEC, 0644);
if (log_fd >= 0) {
try {
int log_fd = open(log_path, O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK | O_CLOEXEC, 0644);
if (log_fd >= 0) {
try {
- setup_main_log(log_fd, false);
+ setup_main_log(log_fd);
}
catch (std::exception &e) {
log(loglevel_t::ERROR, "Setting up log failed: ", e.what());
}
catch (std::exception &e) {
log(loglevel_t::ERROR, "Setting up log failed: ", e.what());
// These are defined in dinit-log.cc:
extern loglevel_t log_level[2];
void enable_console_log(bool do_enable) noexcept;
// These are defined in dinit-log.cc:
extern loglevel_t log_level[2];
void enable_console_log(bool do_enable) noexcept;
-void init_log(service_set *sset);
-void setup_main_log(int fd, bool syslog_format);
+void init_log(service_set *sset, bool syslog_format);
+void setup_main_log(int fd);
bool is_log_flushed() noexcept;
void discard_console_log_buffer() noexcept;
bool is_log_flushed() noexcept;
void discard_console_log_buffer() noexcept;