]> 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)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 3 Sep 2018 08:46:58 +0000 (08:46 +0000)
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 bc4841839b03d0e8b1545c8f3782cb20188f1903..2833592d8e70e94edb68be4b6bdb5e49f2d195b7 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 7e163668fd0a73e5ec62ddc522c01bb7d5ae9b0a..5235edd5634c324b9d9e4d015948d8480daf7573 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 "