From d737c0749582e05e29a6da8c177cc21515ddb50e Mon Sep 17 00:00:00 2001 From: Michel Normand Date: Fri, 15 May 2009 10:47:08 +0200 Subject: [PATCH] add a default stderror log appender This is adding a stderror log appender that is used as default one. Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- src/lxc/log.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/lxc/log.c b/src/lxc/log.c index af5566933..fa6fe4a68 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -38,11 +38,24 @@ #define LXC_LOG_PREFIX_SIZE 32 #define LXC_LOG_BUFFER_SIZE 512 -int lxc_log_fd = 2; +int lxc_log_fd = -1; static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc"; lxc_log_define(lxc_log, lxc); +/*---------------------------------------------------------------------------*/ +static int log_append_stderr(const struct lxc_log_appender *appender, + struct lxc_log_event *event) +{ + if (event->priority < LXC_LOG_PRIORITY_ERROR) + return 0; + + fprintf(stderr, "%s: ", log_prefix); + vfprintf(stderr, event->fmt, *event->vap); + fprintf(stderr, "\n"); + return 0; +} + /*---------------------------------------------------------------------------*/ static int log_append_logfile(const struct lxc_log_appender *appender, struct lxc_log_event *event) @@ -75,10 +88,16 @@ static int log_append_logfile(const struct lxc_log_appender *appender, return write(lxc_log_fd, buffer, n + 1); } +static struct lxc_log_appender log_appender_stderr = { + .name = "stderr", + .append = log_append_stderr, + .next = NULL, +}; + static struct lxc_log_appender log_appender_logfile = { .name = "logfile", .append = log_append_logfile, - .next = NULL, + .next = &log_appender_stderr, }; static struct lxc_log_category log_root = { -- 2.47.2