]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
log: Add "disable log prefix" flag to log lines
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 17 Dec 2017 18:38:38 +0000 (20:38 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 18 Dec 2017 11:12:11 +0000 (13:12 +0200)
src/lib/failures.c
src/lib/failures.h
src/log/log-connection.c

index c7ad8578cb32064ed8530f3af6b447069186f9e1..eb9966312c7ff166dcd6591e934db222b05bb242 100644 (file)
@@ -16,6 +16,8 @@
 #include <syslog.h>
 #include <time.h>
 
+#define LOG_TYPE_FLAG_DISABLE_LOG_PREFIX 0x80
+
 const char *failure_log_type_prefixes[LOG_TYPE_COUNT] = {
        "Debug: ",
        "Info: ",
@@ -651,32 +653,38 @@ internal_handler(const struct failure_context *ctx,
        return ret;
 }
 
-static bool line_is_ok(const char *line)
+static bool line_parse_prefix(const char *line, enum log_type *log_type_r,
+                             bool *replace_prefix_r)
 {
        if (*line != 1)
                return FALSE;
 
-       if (line[1] == '\0') {
+       unsigned char log_type = (line[1] & 0x7f);
+       if (log_type == '\0') {
                i_warning("Broken log line follows (type=NUL)");
                return FALSE;
        }
+       log_type--;
 
-       if (line[1]-1 > LOG_TYPE_OPTION) {
-               i_warning("Broken log line follows (type=%d)", line[1]-1);
+       if (log_type > LOG_TYPE_OPTION) {
+               i_warning("Broken log line follows (type=%d)", log_type);
                return FALSE;
        }
+       *log_type_r = log_type;
+       *replace_prefix_r = (line[1] & LOG_TYPE_FLAG_DISABLE_LOG_PREFIX) != 0;
        return TRUE;
 }
 
 void i_failure_parse_line(const char *line, struct failure_line *failure)
 {
+
        i_zero(failure);
-       if (!line_is_ok(line)) {
+       if (!line_parse_prefix(line, &failure->log_type,
+                              &failure->disable_log_prefix)) {
                failure->log_type = LOG_TYPE_ERROR;
                failure->text = line;
                return;
        }
-       failure->log_type = line[1] - 1;
 
        line += 2;
        failure->text = line;
index 3b4a53c8d6c527fe0dac5ef60ee9763d4cd92af1..ab18e4c877a0bcf7cf9a7325225c7434dd9a64ff 100644 (file)
@@ -29,6 +29,7 @@ enum log_type {
 struct failure_line {
        pid_t pid;
        enum log_type log_type;
+       bool disable_log_prefix;
        const char *text;
 };
 
index aa8d8450cd3d5a5cadd5a266c8f79001457a348e..13ee6351fadd35131ffeedfe202650f55861623b 100644 (file)
@@ -271,6 +271,8 @@ log_it(struct log_connection *log, const char *line,
        failure_ctx.type = failure.log_type;
        failure_ctx.timestamp = tm;
        failure_ctx.timestamp_usecs = log_time->tv_usec;
+       if (failure.disable_log_prefix)
+               failure_ctx.log_prefix = "";
 
        prefix = client != NULL && client->prefix != NULL ?
                client->prefix : log->default_prefix;