Mercurial > dovecot > core-2.2
changeset 12276:e68366e88099
Failure logging supports now getting timestamp as parameter.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 15 Oct 2010 16:08:12 +0100 |
parents | 4933c3095ee2 |
children | 80097e5c38e9 |
files | src/lib/failures.c src/lib/failures.h |
diffstat | 2 files changed, 13 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/failures.c Fri Oct 15 15:46:43 2010 +0100 +++ b/src/lib/failures.c Fri Oct 15 16:08:12 2010 +0100 @@ -64,15 +64,17 @@ exit(status); } -static void log_prefix_add(string_t *str) +static void log_prefix_add(const struct failure_context *ctx, string_t *str) { - struct tm *tm; + const struct tm *tm = ctx->timestamp; char buf[256]; time_t now; if (log_stamp_format != NULL) { - now = time(NULL); - tm = localtime(&now); + if (tm == NULL) { + now = time(NULL); + tm = localtime(&now); + } if (strftime(buf, sizeof(buf), get_log_stamp_format("unused"), tm) > 0) @@ -139,7 +141,8 @@ } static int ATTR_FORMAT(3, 0) -default_handler(const char *prefix, int fd, const char *format, va_list args) +default_handler(const struct failure_context *ctx, int fd, + const char *format, va_list args) { static int recursed = 0; int ret; @@ -153,8 +156,8 @@ recursed++; T_BEGIN { string_t *str = t_str_new(256); - log_prefix_add(str); - str_append(str, prefix); + log_prefix_add(ctx, str); + str_append(str, failure_log_type_prefixes[ctx->type]); /* make sure there's no %n in there and fix %m */ str_vprintfa(str, printf_format_fix(format), args); @@ -191,8 +194,7 @@ { int status = ctx->exit_status; - if (default_handler(failure_log_type_prefixes[ctx->type], - log_fd, format, args) < 0 && + if (default_handler(ctx, log_fd, format, args) < 0 && status == FATAL_DEFAULT) status = FATAL_LOGWRITE; @@ -215,8 +217,7 @@ fd = log_fd; } - if (default_handler(failure_log_type_prefixes[ctx->type], - fd, format, args) < 0) { + if (default_handler(ctx, fd, format, args) < 0) { if (fd == log_fd) failure_exit(FATAL_LOGWRITE); /* we failed to log to info/debug log, try to log the
--- a/src/lib/failures.h Fri Oct 15 15:46:43 2010 +0100 +++ b/src/lib/failures.h Fri Oct 15 16:08:12 2010 +0100 @@ -35,6 +35,7 @@ struct failure_context { enum log_type type; int exit_status; /* for LOG_TYPE_FATAL */ + const struct tm *timestamp; /* NULL = use time() + localtime() */ }; #define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "