From: asterix Date: Wed, 4 Jun 2008 14:37:18 +0000 (+0000) Subject: Move log macros to log module and refactor if. Fix comments. X-Git-Tag: 2.0.0~520 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=bae32100e6d844c07afdbfcddb616f508fb1b978;p=bertos.git Move log macros to log module and refactor if. Fix comments. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1414 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/debug.h b/bertos/cfg/debug.h index 2fbedc51..dde6af5e 100644 --- a/bertos/cfg/debug.h +++ b/bertos/cfg/debug.h @@ -186,71 +186,6 @@ #define TRACEMSG(...) do {} while(0) #endif - /** - * Multi level logging system. - * - * You can use these macro directy or using the cfg/log.h module - * that provide a simple interface for using the logging multilevel system. - * The priority level is order form error messages (hight priority) to info messages - * (low priority), so if you choose a low level log message you can see also all message - * that have a hight priority. - * - * \{ - */ - /// Logging level definition - #define DBG_LOG_ERROR 0 - #define DBG_LOG_WARNING 1 - #define DBG_LOG_INFO 2 - - /// Logging verbose mode - #define DBG_LOG_VERBOSE 1 - #define DBG_LOG_SILENT 0 - - #define DBG_ERROR(debug_level, mode, str,...) \ - do { \ - if(debug_level >= DBG_LOG_ERROR) \ - { \ - if (mode == DBG_LOG_VERBOSE)\ - kprintf("Error(%s():%d): "str, __func__, __LINE__, ## __VA_ARGS__); \ - else \ - kprintf("Error: "str, ## __VA_ARGS__); \ - } \ - else \ - { \ - /* NONE */ \ - } \ - } while (0) - - #define DBG_WARNING(debug_level, mode, str,...) \ - do { \ - if(debug_level >= DBG_LOG_WARNING) \ - { \ - if (mode == DBG_LOG_VERBOSE) \ - kprintf("Warning(%s():%d): "str, __func__, __LINE__, ## __VA_ARGS__); \ - else \ - kprintf("Warning: "str, ## __VA_ARGS__); \ - } \ - else \ - { \ - /* NONE */ \ - } \ - } while (0) - - #define DBG_INFO(debug_level, mode, str,...) \ - do { \ - if(debug_level >= DBG_LOG_INFO) \ - { \ - if (mode == DBG_LOG_VERBOSE) \ - kprintf("Info(%s():%d): "str, __func__, __LINE__, ## __VA_ARGS__); \ - else \ - kprintf("Info: "str, ## __VA_ARGS__); \ - } \ - else \ - { \ - /* NONE */ \ - } \ - } while (0) - /* \} */ /** * \name Walls to detect data corruption diff --git a/bertos/cfg/log.h b/bertos/cfg/log.h index b3fa27f9..063f1625 100644 --- a/bertos/cfg/log.h +++ b/bertos/cfg/log.h @@ -32,30 +32,32 @@ * * \brief Logging system module. * - * This module implement a simple interface to use the multi level - * logging system. + * This module implement a simple interface to use the multi level logging system. * The log message have the priority order, like this: * * - error message (most hight) - * - warning message + * - warning message * - info message (most low) * * With this priority system we can log only the message that have egual or major - * priority than log level that you has been configurate. Further you can have a - * differ log level for each module that you want. To do this you just need to + * priority than log level that you has been configurate. Further you can have a + * differ log level for each module that you want. To do this you just need to * define LOG_LEVEL in cfg of select module. * When you set a log level, the system logs only the message that have priority * egual or major that you have define, but the other logs function are not include * at compile time, so all used logs function are linked, but the other no. * - * To use logging system you should include this module in your drive and use + * To use logging system you should include this module in your drive and use * a LOG_ERROR, LOG_WARNING and LOG_INFO macros to set the level log of the message. * Then you should define a LOG_LEVEL and LOG_VERBOSE costant in your * cfg/cfg_.h using the follow police: - * + * + * - in your file cfg/cfg_.h, you define the logging + * level and verbosity mode for your specific module: + * * \code * - * /** + * ** * * Logging level definition. * * * * Use 0 to log only the error messages @@ -64,16 +66,26 @@ * * * #define _LOG_LEVEL 2 * - * /** + * ** * * Set logging verbosity. * * * * If verbose is zero print short log messages. * * * #define _LOG_VERBOSE 1 * + * \endcode + * + * - then, in the module that you use a logging macros you should define + * a LOG_LEVEL and LOG_VERBOSE using the previous value that you have define + * in cfg_.h header. After this you should include the cfg/log.h + * module: + * + * \code + * * // Define logging setting (for cfg/log.h module). * #define LOG_LEVEL _LOG_LEVEL * #define LOG_VERBOSE _LOG_VERBOSE + * #include * * \endcode * @@ -95,22 +107,48 @@ #include + // Use a default setting if nobody have define a log level #ifndef LOG_LEVEL -#define LOG_LEVEL DBG_LOG_ERROR +#define LOG_LEVEL LOG_LVL_ERR #endif // Use a default setting if nobody have define a log verbosity -#ifndef LOG_VERBOSE -#define LOG_VERBOSE DBG_LOG_SILENT +#ifndef LOG_VERBOSITY +#define LOG_VERBOSITY LOG_SILENT #endif /** - * Error log message. - * Use this macro to print error messages. This log level have hight priority, - * that means the error messages are always printed, if debug is enable. - */ -#define LOG_ERROR(str,...) DBG_ERROR(LOG_LEVEL, LOG_VERBOSE, str, ## __VA_ARGS__) +* Multi level logging system. +* +* You can use these macro directy or using the cfg/log.h module +* that provide a simple interface for using the logging multilevel system. +* The priority level is order form error messages (hight priority) to info messages +* (low priority), so if you choose a low level log message you can see also all message +* that have a hight priority. +* +* \{ +*/ +/// Logging level definition +#define LOG_LVL_ERR 0 +#define LOG_LVL_WARN 1 +#define LOG_LVL_INFO 2 + +/// Logging verbose mode +#define LOG_VERBOSE 1 +#define LOG_SILENT 0 + + +#if LOG_VERBOSITY == LOG_VERBOSE + #define LOG_PRINT(str_level, str,...) kprintf("%s(%s():%d): "str, str_level, __func__, __LINE__, ## __VA_ARGS__) + +#elif LOG_VERBOSITY == LOG_SILENT + #define LOG_PRINT(str_level, str,...) kprintf("%s: "str, str_level, ## __VA_ARGS__) + +#else + #error No log verbosity defined + +#endif /** * Log message level select. @@ -118,20 +156,22 @@ * also which print function are linked. * If you choose a low level of log you link all log function (error, warning and info), * but if choose a hight level you link only that have the priority egual or hight. - * The priority level go from error (most hight) to info (most low) (see cfg/debug.h + * The priority level go from error (most hight) to info (most low) (see cfg/debug.h * for more detail). * */ -#if (LOG_LEVEL <= DBG_LOG_INFO) - #define LOG_WARNING(str,...) DBG_WARNING(LOG_LEVEL, LOG_VERBOSE, str, ## __VA_ARGS__) - #define LOG_INFO(str,...) DBG_INFO(LOG_LEVEL, LOG_VERBOSE, str, ## __VA_ARGS__) +#define LOG_ERR(str,...) LOG_PRINT("ERR", str, ## __VA_ARGS__) + +#if (LOG_LEVEL <= LOG_LVL_INFO) + #define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__) + #define LOG_INFO(str,...) LOG_PRINT("INFO", str, ## __VA_ARGS__) -#elif (LOG_LEVEL <= DBG_LOG_WARNING) - #define LOG_WARNING(str,...) DBG_WARNING(LOG_LEVEL, LOG_VERBOSE, str, ## __VA_ARGS__) +#elif (LOG_LEVEL <= LOG_LVL_WARN) + #define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__) #define LOG_INFO(str,...) /* Nothing */ -#else /* LOG_LEVEL <= DBG_LOG_ERROR */ - #define LOG_WARNING(str,...) /* Nothing */ +#else /* LOG_LEVEL <= LOG_LVL_ERR */ + #define LOG_WARN(str,...) /* Nothing */ #define LOG_INFO(str,...) /* Nothing */ #endif