From 09351beae713de6578fc7cbbbb3d1ab5acbb1b4d Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Mon, 31 Jan 2022 09:37:33 +0100 Subject: [PATCH] Change default logging format on disk (text, non-json) to include the server name. Nowadays we receive and log lines from remote servers so without this extra information it can be unclear where events (eg: problems) are happening which can be rather confusing. --- src/log.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/log.c b/src/log.c index 51787a3cf..f2c674f5b 100644 --- a/src/log.c +++ b/src/log.c @@ -1191,7 +1191,7 @@ literal: } /** Do the actual writing to log files */ -void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *event_id, MultiLine *msg, const char *json_serialized) +void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *event_id, MultiLine *msg, const char *json_serialized, Client *from_server) { static int last_log_file_warning = 0; Log *l; @@ -1343,13 +1343,9 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev for (m = msg; m; m = m->next) { char text_buf[8192]; - snprintf(text_buf, sizeof(text_buf), "%s.%s%s %s: %s\n", subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); - // FIXME: don't write in 2 stages, waste of slow system calls - if (write(l->logfd, timebuf, strlen(timebuf)) < 0) - { - /* Let's ignore any write errors for this one. Next write() will catch it... */ - ; - } + snprintf(text_buf, sizeof(text_buf), "%s%s %s.%s%s %s: %s\n", + timebuf, from_server->name, + subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); n = write(l->logfd, text_buf, strlen(text_buf)); if (n < strlen(text_buf)) { @@ -1824,16 +1820,17 @@ void do_unreal_log_internal(LogLevel loglevel, const char *subsystem, const char /* Convert the message buffer to MultiLine */ mmsg = line2multiline(msgbuf); - /* Now call the disk loggers */ - do_unreal_log_disk(loglevel, subsystem, event_id, mmsg, json_serialized); - - /* And the ircops stuff */ + /* Parse the "from server" info, if any */ t = json_object_get(j_details, "from_server_name"); if (t && (str = json_get_value(t))) from_server = find_server(str, NULL); if (from_server == NULL) from_server = &me; + /* Now call all the loggers: */ + + do_unreal_log_disk(loglevel, subsystem, event_id, mmsg, json_serialized, from_server); + if ((loop.rehashing == 2) || !strcmp(subsystem, "config")) do_unreal_log_control(loglevel, subsystem, event_id, mmsg, json_serialized, from_server); @@ -1860,7 +1857,7 @@ void do_unreal_log_internal_from_remote(LogLevel loglevel, const char *subsystem unreal_log_recursion_trap = 1; /* Call the disk loggers */ - do_unreal_log_disk(loglevel, subsystem, event_id, msg, json_serialized); + do_unreal_log_disk(loglevel, subsystem, event_id, msg, json_serialized, from_server); /* And to IRC */ do_unreal_log_opers(loglevel, subsystem, event_id, msg, json_serialized, from_server);