diff --git a/include/h.h b/include/h.h index 69d88a1e8..9df1bb04d 100644 --- a/include/h.h +++ b/include/h.h @@ -1090,10 +1090,13 @@ extern LogType log_type_stringtoval(char *str); extern char *log_type_valtostring(LogType v); #ifdef DEBUGMODE #define unreal_log(...) do_unreal_log(__VA_ARGS__, log_data_source(__FILE__, __LINE__, __FUNCTION__), NULL) +#define unreal_log_raw(...) do_unreal_log_raw(__VA_ARGS__, log_data_source(__FILE__, __LINE__, __FUNCTION__), NULL) #else #define unreal_log(...) do_unreal_log(__VA_ARGS__, NULL) +#define unreal_log_raw(...) do_unreal_log_raw(__VA_ARGS__, NULL) #endif extern void do_unreal_log(LogLevel loglevel, char *subsystem, char *event_id, Client *client, char *msg, ...) __attribute__((format(printf,5,0))); +extern void do_unreal_log_raw(LogLevel loglevel, char *subsystem, char *event_id, Client *client, char *msg, ...); extern LogData *log_data_string(const char *key, const char *str); extern LogData *log_data_integer(const char *key, int64_t integer); extern LogData *log_data_client(const char *key, Client *client); diff --git a/src/conf.c b/src/conf.c index 437a8569f..eb396210e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1489,6 +1489,7 @@ void config_error(FORMAT_STRING(const char *format), ...) va_end(ap); if ((ptr = strchr(buffer, '\n')) != NULL) *ptr = '\0'; + unreal_log_raw(ULOG_ERROR, "config", "CONFIG_ERROR_GENERIC", NULL, buffer, NULL); ircd_log(LOG_ERROR, "config error: %s", buffer); sendto_realops("error: %s", buffer); if (remote_rehash_client) diff --git a/src/log.c b/src/log.c index 86b5a6286..565b570e6 100644 --- a/src/log.c +++ b/src/log.c @@ -30,6 +30,7 @@ /* Forward declarations */ long log_to_snomask(LogLevel loglevel, char *subsystem, char *event_id); +void do_unreal_log_internal(LogLevel loglevel, char *subsystem, char *event_id, Client *client, int expand_msg, char *msg, va_list vl); LogType log_type_stringtoval(char *str) { @@ -685,10 +686,27 @@ void do_unreal_log_loggers(LogLevel loglevel, char *subsystem, char *event_id, c /* Logging function, called by the unreal_log() macro. */ void do_unreal_log(LogLevel loglevel, char *subsystem, char *event_id, - Client *client, - char *msg, ...) + Client *client, char *msg, ...) { va_list vl; + va_start(vl, msg); + do_unreal_log_internal(loglevel, subsystem, event_id, client, 1, msg, vl); + va_end(vl); +} + +/* Logging function, called by the unreal_log_raw() macro. */ +void do_unreal_log_raw(LogLevel loglevel, char *subsystem, char *event_id, + Client *client, char *msg, ...) +{ + va_list vl; + va_start(vl, msg); + do_unreal_log_internal(loglevel, subsystem, event_id, client, 0, msg, vl); + va_end(vl); +} + +void do_unreal_log_internal(LogLevel loglevel, char *subsystem, char *event_id, + Client *client, int expand_msg, char *msg, va_list vl) +{ LogData *d; char *json_serialized; json_t *j = NULL; @@ -718,7 +736,6 @@ void do_unreal_log(LogLevel loglevel, char *subsystem, char *event_id, if (client) json_expand_client(j_details, "client", client, 0); /* Additional details (if any) */ - va_start(vl, msg); while ((d = va_arg(vl, LogData *))) { switch(d->type) @@ -743,7 +760,12 @@ void do_unreal_log(LogLevel loglevel, char *subsystem, char *event_id, } log_data_free(d); } - buildlogstring(msg, msgbuf, sizeof(msgbuf), j_details); + + if (expand_msg) + buildlogstring(msg, msgbuf, sizeof(msgbuf), j_details); + else + strlcpy(msgbuf, msg, sizeof(msgbuf)); + json_object_set_new(j, "msg", json_string(msgbuf)); /* Now merge the details into root object 'j': */ diff --git a/src/misc.c b/src/misc.c index e629d0173..908f3f465 100644 --- a/src/misc.c +++ b/src/misc.c @@ -114,8 +114,7 @@ void ircd_log(int flags, FORMAT_STRING(const char *format), ...) ircvsnprintf(buf, sizeof(buf), format, vl); va_end(vl); - // This is a stupid escape trick, we better use a different method / other function - unreal_log(ULOG_ERROR, "unknown", "UNKNOWN", NULL, "$_data", log_data_string("_data", buf)); + unreal_log_raw(ULOG_ERROR, "unknown", "UNKNOWN", NULL, buf); } /** Returns the date in rather long string */