From d914495ab4a0ad87ccb071ae8dec9347f423c5c1 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 13 Jan 2021 11:11:50 +0100 Subject: [PATCH] Fixed a bug where clicon_debug_init interfered with clicon_log_file --- lib/src/clixon_log.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index f3858099..58a067f4 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -71,7 +71,6 @@ static int _logflags = 0x0; /* Set to open file to write debug messages directly to file */ static FILE *_logfile = NULL; - /*! Initialize system logger. * * Make syslog(3) calls with specified ident and gates calls of level upto specified level (upto). @@ -144,6 +143,7 @@ clicon_log_opt(char c) * @param[in] filename File to log to * @retval 0 OK * @retval -1 Error + * @see clicon_debug_init where a strean */ int clicon_log_file(char *filename) @@ -236,9 +236,7 @@ clicon_log_str(int level, flogtime(_logfile); fprintf(_logfile, "%s\n", msg); fflush(_logfile); - } - /* Enable this if you want syslog in a stream. But there are problems with * recursion */ @@ -305,17 +303,23 @@ clicon_log(int level, * debugging. * * @param[in] dbglevel 0 is show no debug messages, 1 is normal, 2.. is high debug. - Note this is _not_ level from syslog(3) + * Note this is _not_ level from syslog(3) * @param[in] f Debug-file. Open file where debug messages are directed. - This overrides the clicon_log settings which is otherwise where - debug messages are directed. + * If not NULL, it overrides the clicon_log settings which is otherwise + * where debug messages are directed. + * @see clicon_log_file where a filename can be given */ int clicon_debug_init(int dbglevel, FILE *f) { _clixon_debug = dbglevel; /* Global variable */ - _logfile = f; + + if (f != NULL){ + if (_logfile) + fclose(_logfile); + _logfile = f; + } return 0; }