log.h

Go to the documentation of this file.
00001 
00092 #ifndef CFG_LOG_H
00093 #define CFG_LOG_H
00094 
00095 #include <cfg/debug.h>
00096 
00097 
00098 // Use a default setting if nobody defined a log level
00099 #ifndef LOG_LEVEL
00100 #define LOG_LEVEL       LOG_LVL_ERR
00101 #endif
00102 
00103 // Use a default setting if nobody defined a log format
00104 #ifndef LOG_FORMAT
00105 #define LOG_FORMAT      LOG_FMT_TERSE
00106 #endif
00107 
00121 #define LOG_LVL_NONE      0
00122 #define LOG_LVL_ERR       1
00123 #define LOG_LVL_WARN      2
00124 #define LOG_LVL_INFO      3
00125 
00134 #define LOG_FMT_VERBOSE   1
00135 #define LOG_FMT_TERSE     0
00136 
00137 #if LOG_FORMAT == LOG_FMT_VERBOSE
00138     #define LOG_PRINT(str_level, str,...)    kprintf("%s():%d:%s: " str, __func__, __LINE__, str_level, ## __VA_ARGS__)
00139 #elif LOG_FORMAT == LOG_FMT_TERSE
00140     #define LOG_PRINT(str_level, str,...)    kprintf("%s: " str, str_level, ## __VA_ARGS__)
00141 #else
00142     #error No LOG_FORMAT defined
00143 #endif
00144 
00145 #if LOG_LEVEL >= LOG_LVL_ERR
00146     #define LOG_ERR(str,...)       LOG_PRINT("ERR", str, ## __VA_ARGS__)
00147     #define LOG_ERRB(x)            x
00148 #else
00149     INLINE void LOG_ERR(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00150     #define LOG_ERRB(x)            /* Nothing */
00151 #endif
00152 
00153 #if LOG_LEVEL >= LOG_LVL_WARN
00154     #define LOG_WARN(str,...)       LOG_PRINT("WARN", str, ## __VA_ARGS__)
00155     #define LOG_WARNB(x)            x
00156 #else
00157     INLINE void LOG_WARN(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00158     #define LOG_WARNB(x)            /* Nothing */
00159 #endif
00160 
00161 #if LOG_LEVEL >= LOG_LVL_INFO
00162     #define LOG_INFO(str,...)       LOG_PRINT("INFO", str, ## __VA_ARGS__)
00163     #define LOG_INFOB(x)            x
00164 #else
00165     INLINE void LOG_INFO(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00166     #define LOG_INFOB(x)            /* Nothing */
00167 #endif
00168 
00169 
00170 #endif /* CFG_LOG_H */