]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add failure_context.log_prefix_type_pos
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 31 Aug 2018 12:03:37 +0000 (15:03 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 7 Sep 2018 07:41:16 +0000 (10:41 +0300)
If non-zero, this specifies where the log type (e.g. "Info: ") is written
within the log prefix. By default it's appended.

src/lib/failures.c
src/lib/failures.h

index 4f2f33f33a64e136dc91f10ad401b78bffdb319d..d0e02864a47581d6ae0c76dd41eb43063b89b124 100644 (file)
@@ -187,6 +187,8 @@ static string_t * ATTR_FORMAT(3, 0) internal_format(const struct failure_context
 
        if (ctx->log_prefix != NULL) {
                log_type |= LOG_TYPE_FLAG_DISABLE_LOG_PREFIX;
+               if (ctx->log_prefix_type_pos != 0)
+                       log_type |= LOG_TYPE_FLAG_PREFIX_LEN;
        } else if (!log_prefix_sent && log_prefix != NULL) {
                log_prefix_sent = TRUE;
                i_failure_send_option("prefix", log_prefix);
@@ -194,6 +196,8 @@ static string_t * ATTR_FORMAT(3, 0) internal_format(const struct failure_context
 
        str = t_str_new(128);
        str_printfa(str, "\001%c%s ", log_type, my_pid);
+       if ((log_type & LOG_TYPE_FLAG_PREFIX_LEN) != 0)
+               str_printfa(str, "%u ", ctx->log_prefix_type_pos);
        if (ctx->log_prefix != NULL)
                str_append(str, ctx->log_prefix);
        *prefix_len_r = str_len(str);
@@ -335,10 +339,17 @@ static void log_prefix_add(const struct failure_context *ctx, string_t *str)
                /* use global log prefix */
                if (log_prefix != NULL)
                        str_append(str, log_prefix);
-       } else {
+               str_append(str, failure_log_type_prefixes[ctx->type]);
+       } else if (ctx->log_prefix_type_pos == 0) {
                str_append(str, ctx->log_prefix);
+               str_append(str, failure_log_type_prefixes[ctx->type]);
+       } else {
+               i_assert(ctx->log_prefix_type_pos <= strlen(ctx->log_prefix));
+               str_append_data(str, ctx->log_prefix, ctx->log_prefix_type_pos);
+               str_insert(str, ctx->log_prefix_type_pos,
+                          failure_log_type_prefixes[ctx->type]);
+               str_append(str, ctx->log_prefix + ctx->log_prefix_type_pos);
        }
-       str_append(str, failure_log_type_prefixes[ctx->type]);
 }
 
 static void fd_wait_writable(int fd)
index 4e514c9df99abc8e3438424323bbc20946458739..82db0a6183220bcac061fd32717766d70283dfc0 100644 (file)
@@ -43,6 +43,9 @@ struct failure_context {
        const struct tm *timestamp; /* NULL = use time() + localtime() */
        unsigned int timestamp_usecs;
        const char *log_prefix; /* override the default log prefix */
+       /* If non-0, insert the log type text (e.g. "Info: ") at this position
+          in the log_prefix instead of appending it. */
+       unsigned int log_prefix_type_pos;
 };
 
 #define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "