log.h File Reference

Logging system module. More...

#include <cfg/debug.h>

Go to the source code of this file.


Defines

Logging level definition
When you choose a log level messages you choose 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 (highest) to info (lowest) (see cfg/debug.h for more detail).

}

#define LOG_LVL_NONE   0
#define LOG_LVL_ERR   1
#define LOG_LVL_WARN   2
#define LOG_LVL_INFO   3
Logging format
There are two logging format: terse and verbose.

The latter prepends function names and line number information to each log entry.

#define LOG_FMT_VERBOSE   1
#define LOG_FMT_TERSE   0
#define LOG_PRINT(str_level, str,...)   kprintf("%s: " str, str_level, ## __VA_ARGS__)
#define LOG_ERR(str,...)   LOG_PRINT("ERR", str, ## __VA_ARGS__)
#define LOG_ERRB(x)   x
#define LOG_WARN(str,...)
#define LOG_WARNB(x)
#define LOG_INFO(str,...)
#define LOG_INFOB(x)

Detailed Description

Logging system module.

This module implement a simple interface to use the multi level logging system. The log message have the priority order, like this:

  • error message (highest)
  • warning message
  • info message (lowest)

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 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 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_<your_cfg_module_name>.h using the follow policy:

  • in your file cfg/cfg_<cfg_module_name>.h, you define the logging level and verbosity mode for your specific module:

    #define <cfg_module_name>_LOG_LEVEL    LOG_LVL_INFO

    #define <cfg_module_name>_LOG_FORMAT   LOG_FMT_VERBOSE

  • then, in the module that you use a logging macros you should define a LOG_LEVEL and LOG_FORMAT using the previous value that you have define in cfg_<cfg_module_name>.h header. After this you should include the cfg/log.h module:

    // Define log settings for cfg/log.h.
    #define LOG_LEVEL   <cfg_module_name>_LOG_LEVEL
    #define LOG_FORMAT  <cfg_module_name>_LOG_FORMAT
    #include <cfg/log.h>

if you include a log.h module without define the LOG_LEVEL and LOG_VERBOSE macros, the module use the default setting (see below).

WARNING: when use the log.h module, and you want to set a your log level make sure to include this module after a cfg_<cfg_module_name>.h, because the LOG_LEVEL and LOG_VERBOSE macros must be defined before to include log module, otherwise the log module use a default settings.

Version:
Id
log.h 2774 2009-08-20 14:33:21Z
Author:
Daniele Basile <asterix@develer.com>

Definition in file log.h.