log.h
Go to the documentation of this file.
00001
00102 #ifndef CFG_LOG_H
00103 #define CFG_LOG_H
00104 
00105 #include <cfg/debug.h>
00106
00107 // Use a default setting if nobody defined a log level
00108 #ifndef LOG_LEVEL
00109 #define LOG_LEVEL       LOG_LVL_ERR
00110 #endif
00111 
00112 // Use a default setting if nobody defined a log format
00113 #ifndef LOG_FORMAT
00114 #define LOG_FORMAT      LOG_FMT_TERSE
00115 #endif
00116 
00129 #define LOG_LVL_NONE      0
00130 #define LOG_LVL_ERR       1
00131 #define LOG_LVL_WARN      2
00132 #define LOG_LVL_INFO      3
00133 
00144 #define LOG_FMT_VERBOSE   1
00145 #define LOG_FMT_TERSE     0
00146 
00148 #include "cfg/cfg_syslog.h"
00149
00150 /* For backward compatibility */
00151 #ifndef CONFIG_SYSLOG_NET
00152     #define CONFIG_SYSLOG_NET 0
00153 #endif
00154 
00155 #if (CONFIG_SYSLOG_NET && (!defined(ARCH_NIGHTTEST) || !(ARCH & ARCH_NIGHTTEST)))
00156     #include <net/syslog.h>
00157
00158     #if LOG_FORMAT == LOG_FMT_VERBOSE
00159         #define LOG_PRINT(str_level, str,...)    syslog_printf("<182>%d-%s():%d:%s: " str, syslog_count(), __func__, __LINE__, str_level, ## __VA_ARGS__)
00160     #elif LOG_FORMAT == LOG_FMT_TERSE
00161         #define LOG_PRINT(str_level, str,...)    syslog_printf("<182>%d-%s: " str, syslog_count(), str_level, ## __VA_ARGS__)
00162     #else
00163         #error No LOG_FORMAT defined
00164     #endif
00165 
00166 #else
00167     #if LOG_FORMAT == LOG_FMT_VERBOSE
00168         #define LOG_PRINT(str_level, str,...)    kprintf("%s():%d:%s: " str, __func__, __LINE__, str_level, ## __VA_ARGS__)
00169     #elif LOG_FORMAT == LOG_FMT_TERSE
00170         #define LOG_PRINT(str_level, str,...)    kprintf("%s: " str, str_level, ## __VA_ARGS__)
00171     #else
00172         #error No LOG_FORMAT defined
00173     #endif
00174 
00175 #endif
00176 
00177 #if LOG_LEVEL >= LOG_LVL_ERR
00178 
00181     #define LOG_ERR(str,...)       LOG_PRINT("ERR", str, ## __VA_ARGS__)
00182 
00185     #define LOG_ERRB(x)            x
00186 #else
00187     INLINE void LOG_ERR(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00188     #define LOG_ERRB(x)            /* Nothing */
00189 #endif
00190 
00191 #if LOG_LEVEL >= LOG_LVL_WARN
00192 
00195     #define LOG_WARN(str,...)       LOG_PRINT("WARN", str, ## __VA_ARGS__)
00196 
00199     #define LOG_WARNB(x)            x
00200 #else
00201     INLINE void LOG_WARN(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00202     #define LOG_WARNB(x)            /* Nothing */
00203 #endif
00204 
00205 #if LOG_LEVEL >= LOG_LVL_INFO
00206 
00209     #define LOG_INFO(str,...)       LOG_PRINT("INFO", str, ## __VA_ARGS__)
00210 
00213     #define LOG_INFOB(x)            x
00214 #else
00215     INLINE void LOG_INFO(UNUSED_ARG(const char *, fmt), ...) { /* nop */ }
00216     #define LOG_INFOB(x)            /* Nothing */
00217 #endif
00218 
00221 #endif /* CFG_LOG_H */