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/)
30 * All Rights Reserved.
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 (most hight)
40 * - #info message (most low)
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_module_name>.h using the follow police:
55 * - in your file \c cfg/cfg_<module_name>.h, you define the logging
56 * level and verbosity mode for your specific module:
61 * * Logging level definition.
63 * * Use 0 to log only the error messages
64 * * Use 1 to log the error and warning messages
65 * * Use 2 to log all messages
67 * #define <module_name>_LOG_LEVEL 2
70 * * Set logging verbosity.
72 * * If verbose is zero print short log messages.
74 * #define <module_name>_LOG_VERBOSE 1
78 * - then, in the module that you use a logging macros you should define
79 * a LOG_LEVEL and LOG_VERBOSE using the previous value that you have define
80 * in cfg_<module_name>.h header. After this you should include the cfg/log.h
85 * // Define logging setting (for cfg/log.h module).
86 * #define LOG_LEVEL <module_name>_LOG_LEVEL
87 * #define LOG_VERBOSE <module_name>_LOG_VERBOSE
88 * #include <cfg/log.h>
92 * if you include a log.h module without define the LOG_LEVEL and LOG_VERBOSE
93 * macros, the module use the default setting (see below).
95 * WARNING: when use the log.h module, and you want to set a your log level
96 * make sure to include this module after a \c cfg_<module_name>.h, because the
97 * LOG_LEVEL and LOG_VERBOSE macros must be define before to include log module,
98 * otherwise the log module use a default settings.
102 * \author Daniele Basile <asterix@develer.com>
108 #include <cfg/debug.h>
111 // Use a default setting if nobody have define a log level
113 #define LOG_LEVEL LOG_LVL_ERR
116 // Use a default setting if nobody have define a log verbosity
117 #ifndef LOG_VERBOSITY
118 #define LOG_VERBOSITY LOG_SILENT
122 * Multi level logging system.
124 * You can use these macro directy or using the cfg/log.h module
125 * that provide a simple interface for using the logging multilevel system.
126 * The priority level is order form error messages (hight priority) to info messages
127 * (low priority), so if you choose a low level log message you can see also all message
128 * that have a hight priority.
132 /// Logging level definition
133 #define LOG_LVL_ERR 0
134 #define LOG_LVL_WARN 1
135 #define LOG_LVL_INFO 2
137 /// Logging verbose mode
138 #define LOG_VERBOSE 1
142 #if LOG_VERBOSITY == LOG_VERBOSE
143 #define LOG_PRINT(str_level, str,...) kprintf("%s(%s():%d): "str, str_level, __func__, __LINE__, ## __VA_ARGS__)
145 #elif LOG_VERBOSITY == LOG_SILENT
146 #define LOG_PRINT(str_level, str,...) kprintf("%s: "str, str_level, ## __VA_ARGS__)
149 #error No log verbosity defined
154 * Log message level select.
155 * When you choose a log level messages you choose
156 * also which print function are linked.
157 * If you choose a low level of log you link all log function (error, warning and info),
158 * but if choose a hight level you link only that have the priority egual or hight.
159 * The priority level go from error (most hight) to info (most low) (see cfg/debug.h
163 #define LOG_ERR(str,...) LOG_PRINT("ERR", str, ## __VA_ARGS__)
165 #if (LOG_LEVEL <= LOG_LVL_INFO)
166 #define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__)
167 #define LOG_INFO(str,...) LOG_PRINT("INFO", str, ## __VA_ARGS__)
169 #elif (LOG_LEVEL <= LOG_LVL_WARN)
170 #define LOG_WARN(str,...) LOG_PRINT("WARN", str, ## __VA_ARGS__)
171 #define LOG_INFO(str,...) /* Nothing */
173 #else /* LOG_LEVEL <= LOG_LVL_ERR */
174 #define LOG_WARN(str,...) /* Nothing */
175 #define LOG_INFO(str,...) /* Nothing */
179 #endif /* CFG_LOG_H */