4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 * \brief Logging system module.
35 * This module implement a simple interface to use the multi level logging system.
36 * The log message have the priority order, like this:
38 * - error message (highest)
40 * - info message (lowest)
42 * With this priority system we can log only the message that have egual or major
43 * priority than log level that you has been configurate. Further you can have a
44 * differ log level for each module that you want. To do this you just need to
45 * define LOG_LEVEL in cfg of select module.
46 * When you set a log level, the system logs only the message that have priority
47 * egual or major that you have define, but the other logs function are not include
48 * at compile time, so all used logs function are linked, but the other no.
50 * To use logging system you should include this module in your drive and use
51 * a LOG_ERROR, LOG_WARNING and LOG_INFO macros to set the level log of the message.
52 * Then you should define a LOG_LEVEL and LOG_VERBOSE costant in your
53 * \c cfg/cfg_\<your_cfg_module_name\>.h using the follow policy:
55 * - in your file \c cfg/cfg_\<cfg_module_name\>.h, you define the logging
56 * level and verbosity mode for your specific module:
59 * /// Module logging level.
60 * #define <cfg_module_name>_LOG_LEVEL LOG_LVL_INFO
62 * /// Module logging format.
63 * #define <cfg_module_name>_LOG_FORMAT LOG_FMT_VERBOSE
66 * - then, in the module that you use a logging macros you should define
67 * a LOG_LEVEL and LOG_FORMAT using the previous value that you have define
68 * in cfg_<cfg_module_name>.h header. After this you should include the cfg/log.h
72 * // Define log settings for cfg/log.h.
73 * #define LOG_LEVEL <cfg_module_name>_LOG_LEVEL
74 * #define LOG_FORMAT <cfg_module_name>_LOG_FORMAT
75 * #include <cfg/log.h>
78 * if you include a log.h module without define the LOG_LEVEL and LOG_VERBOSE
79 * macros, the module use the default setting (see below).
81 * WARNING: when use the log.h module, and you want to set a your log level
82 * make sure to include this module after a \c cfg_<cfg_module_name>.h, because the
83 * LOG_LEVEL and LOG_VERBOSE macros must be defined before to include log module,
84 * otherwise the log module use a default settings.
86 * \author Daniele Basile <asterix@develer.com>
94 #include <cfg/debug.h>
97 // Use a default setting if nobody defined a log level
99 #define LOG_LEVEL LOG_LVL_ERR
102 // Use a default setting if nobody defined a log format
104 #define LOG_FORMAT LOG_FMT_TERSE
108 * \name Logging level definition
110 * When you choose a log level messages you choose
111 * also which print function are linked.
112 * If you choose a low level of log you link all log function (error, warning and info),
113 * but if choose a hight level you link only that have the priority egual or hight.
114 * The priority level go from error (highest) to info (lowest) (see cfg/debug.h
117 * $WIZ$ log_level = "LOG_LVL_NONE", "LOG_LVL_ERR", "LOG_LVL_WARN", "LOG_LVL_INFO"
120 #define LOG_LVL_NONE 0
121 #define LOG_LVL_ERR 1
122 #define LOG_LVL_WARN 2
123 #define LOG_LVL_INFO 3
126 * \name Logging format
128 * There are two logging format: terse and verbose. The latter prepends
129 * function names and line number information to each log entry.
131 * $WIZ$ log_format = "LOG_FMT_VERBOSE", "LOG_FMT_TERSE"
133 #define LOG_FMT_VERBOSE 1
134 #define LOG_FMT_TERSE 0
136 #if LOG_FORMAT == LOG_FMT_VERBOSE
137 #define LOG_PRINT(str_level, str,...) kprintf("%s():%d:%s: " str, __func__, __LINE__, str_level, ## __VA_ARGS__)
138 #elif LOG_FORMAT == LOG_FMT_TERSE
139 #define LOG_PRINT(str_level, str,...) kprintf("%s: " str, str_level, ## __VA_ARGS__)
141 #error No LOG_FORMAT defined
144 #if LOG_LEVEL >= LOG_LVL_ERR
145 #define LOG_ERR(str,...) LOG_PRINT("ERR", str, ## __VA_ARGS__)
146 #define LOG_ERRB(x) x
148 INLINE void LOG_ERR(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
149 #define LOG_ERRB(x) /* Nothing */
152 #if LOG_LEVEL >= LOG_LVL_WARN
153 #define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__)
154 #define LOG_WARNB(x) x
156 INLINE void LOG_WARN(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
157 #define LOG_WARNB(x) /* Nothing */
160 #if LOG_LEVEL >= LOG_LVL_INFO
161 #define LOG_INFO(str,...) LOG_PRINT("INFO", str, ## __VA_ARGS__)
162 #define LOG_INFOB(x) x
164 INLINE void LOG_INFO(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
165 #define LOG_INFOB(x) /* Nothing */
169 #endif /* CFG_LOG_H */