]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event-log - Add support for inserting a prefix in event_logv().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 2 Jul 2019 18:50:07 +0000 (20:50 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 9 Jul 2019 19:42:49 +0000 (21:42 +0200)
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.

src/lib/event-log.c
src/lib/event-log.h

index b8ce28735df2d4b90359a3315d6526116926ad1c..1a4387bb202da73c1380026d3d7f5cc41b3f6a76 100644 (file)
@@ -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))
index e38ce9ff23355b05e63d35684ee3ca6340d5b3a3..4dfb18c4d52c6d69c63f117a641f54e6ae2b2575 100644 (file)
@@ -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;