Inverted log level enumeration

This commit is contained in:
Franck Joncourt 2013-04-26 16:18:08 +02:00
parent bb70a9752f
commit 65d0517a9c
6 changed files with 21 additions and 17 deletions

View File

@ -2,7 +2,8 @@ bin_PROGRAMS = fwknop
fwknop_SOURCES = fwknop.c fwknop.h config_init.c config_init.h \
fwknop_common.h spa_comm.c spa_comm.h utils.c utils.h \
http_resolve_host.c getpasswd.c getpasswd.h cmd_opts.h
http_resolve_host.c getpasswd.c getpasswd.h cmd_opts.h \
log_msg.c log_msg.h
fwknop_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common

View File

@ -1332,6 +1332,9 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
}
}
/* Update the verbosity level for the log module */
log_set_verbosity(LOG_DEFAULT_VERBOSITY + options->verbose);
/* First process the .fwknoprc file.
*/
process_rc_section(RC_SECTION_DEFAULT, options);

View File

@ -265,6 +265,9 @@ main(int argc, char **argv)
memset(hmac_key, 0x00, MAX_KEY_LEN+1);
memset(access_buf, 0x00, MAX_LINE_LEN);
/* Initialize the log module */
log_new();
/* Handle command line
*/
config_init(&options, argc, argv);

View File

@ -32,6 +32,7 @@
#define FWKNOP_COMMON_H
#include "common.h"
#include "log_msg.h"
/* My Name and Version
*/

View File

@ -4,7 +4,7 @@
* @author Damien S. Stuart
*
* @brief General logging routine that can write to stderr
* and can take varibale number of args.
* and can take variable number of args.
*
* Copyright 2009-2010 Damien Stuart (dstuart@dstuart.org)
*
@ -31,7 +31,6 @@
#include <stdarg.h>
#define LOG_STREAM stderr /*!< All of the messages log by the module are sent to the sderr stream */
#define LOG_DEFAULT_VERBOSITY LOG_VERBOSITY_NORMAL /*!< Default verbosity to use */
typedef struct
{
@ -66,7 +65,7 @@ log_free(void)
* Set the verbosity level
*
* The function set the verbosity level for the current context of the log
* module. New messages with a lower priority will not be printed afterwards.
* module. New messages with a higher priority will not be printed afterwards.
* For example setting the verbosity to LOG_VERBOSITY_WARNING will not
* print a message with a priority set to LOG_VERBOSITY_NORMAL to the stream
* LOG_STREAM.
@ -76,11 +75,7 @@ log_free(void)
void
log_set_verbosity(int level)
{
if (level < LOG_VERBOSITY_MAX)
log_ctx.verbosity = level;
else
log_ctx.verbosity = LOG_DEFAULT_VERBOSITY;
log_ctx.verbosity = level;
}
/**
@ -97,8 +92,8 @@ log_msg(int level, char* msg, ...)
va_list ap;
/* Send the message only to the stream for messages with a verbosity
* equal or higher than the verbosity context. */
if (level >= log_ctx.verbosity)
* equal or lower than the verbosity context. */
if (level <= log_ctx.verbosity)
{
va_start(ap, msg);
vfprintf(LOG_STREAM, msg, ap);

View File

@ -30,14 +30,15 @@
enum
{
LOG_VERBOSITY_DEBUG = 0, /*<! Constant to define a DEBUG message */
LOG_VERBOSITY_INFO, /*<! Constant to define a INFO message */
LOG_VERBOSITY_NORMAL, /*<! Constant to define a NORMAL message */
LOG_VERBOSITY_WARNING, /*<! Constant to define a WARNING message */
LOG_VERBOSITY_ERROR, /*<! Constant to define a ERROR message */
LOG_VERBOSITY_MAX
LOG_VERBOSITY_ERROR = 0, /*!< Constant to define a ERROR message */
LOG_VERBOSITY_WARNING, /*!< Constant to define a WARNING message */
LOG_VERBOSITY_NORMAL, /*!< Constant to define a NORMAL message */
LOG_VERBOSITY_INFO, /*!< Constant to define a INFO message */
LOG_VERBOSITY_DEBUG, /*!< Constant to define a DEBUG message */
} log_level_t;
#define LOG_DEFAULT_VERBOSITY LOG_VERBOSITY_NORMAL /*!< Default verbosity to use */
void log_new(void);
void log_free(void);
void log_set_verbosity(int level);