From: Stephan Bosch Date: Tue, 2 Jul 2019 18:50:07 +0000 (+0200) Subject: lib: event-log - Add support for inserting a prefix in event_logv(). X-Git-Tag: 2.3.9~397 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb7c6b099d09fbf3eff42e0945283ae58296cd40;p=thirdparty%2Fdovecot%2Fcore.git lib: event-log - Add support for inserting a prefix in event_logv(). The prefix is provided in the event_logv() call and not attached to the event hierarchy. It is inserted at the position indicated by the base_event. Different prefixes can be provided for the message appended to the string buffer and the sent event message. --- diff --git a/src/lib/event-log.c b/src/lib/event-log.c index b8ce28735d..1a4387bb20 100644 --- a/src/lib/event-log.c +++ b/src/lib/event-log.c @@ -119,6 +119,8 @@ event_get_log_message_str_out(struct event_get_log_message_context *glmctx, return; /* append the current log prefix to the string buffer */ + if (params->base_str_prefix != NULL && !glmctx->replace_prefix) + str_append(str_out, params->base_str_prefix); str_append_str(str_out, glmctx->log_prefix); if (glmctx->message != NULL) { @@ -150,6 +152,12 @@ event_get_log_message(struct event *event, if (event == params->base_event) { /* Append the message to the provided string buffer. */ event_get_log_message_str_out(glmctx, fmt, args); + /* Insert the base send prefix */ + if (params->base_send_prefix != NULL) { + str_insert(glmctx->log_prefix, 0, + params->base_send_prefix); + ret = TRUE; + } } /* Call the message amendment callback for this event if there is one. @@ -196,6 +204,13 @@ event_get_log_message(struct event *event, } if (event->parent == NULL) { event_get_log_message_str_out(glmctx, fmt, args); + if (params->base_event == NULL && + params->base_send_prefix != NULL && + !glmctx->replace_prefix) { + str_insert(glmctx->log_prefix, 0, + params->base_send_prefix); + ret = TRUE; + } } else if (!event->log_prefix_replace && (!params->no_send || !glmctx->str_out_done)) { if (event_get_log_message(event->parent, glmctx, fmt, args)) diff --git a/src/lib/event-log.h b/src/lib/event-log.h index e38ce9ff23..4dfb18c4d5 100644 --- a/src/lib/event-log.h +++ b/src/lib/event-log.h @@ -22,6 +22,12 @@ struct event_log_params { logging in parallel logs that are visible to users. */ string_t *base_str_out; + /* Prefix inserted at the base_event for the sent log message. */ + const char *base_send_prefix; + /* Prefix inserted at the base_event for the log message appended to the + string buffer. */ + const char *base_str_prefix; + /* Don't actually send the event; only append to the provided string buffer (base_str_out must not be NULL). */ bool no_send:1;