No Matches
log.h File Reference

System logging header . More...

Detailed Description

System logging header .

This header offers a bunch of "LOG_*" functions that, with the default implementation, just use printf, but honour a verbosity level.

If desired, it is possible to implement a log module which then will be used instead the default printf-based implementation. In order to do so, the log module has to

  1. provide "log_module.h"
  2. have a name starting with "log_" or depend on the pseudo-module LOG,
  3. implement log_write()

See "sys/log/log_printfnoformat" for an example.

Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file log.h.

#include <stdio.h>
+ Include dependency graph for log.h:

Go to the source code of this file.


#define log_write(level, ...)   printf(__VA_ARGS__)
 Default log_write function, just maps to printf.
 Default log level define.
#define LOG(level, ...)
 Log message if level <= LOG_LEVEL.
enum  {
 defined log levels More...

Logging convenience defines

#define LOG_ERROR(...)   LOG(LOG_ERROR, __VA_ARGS__)
 log an error
 log a warning
#define LOG_INFO(...)   LOG(LOG_INFO, __VA_ARGS__)
 for the curious
#define LOG_DEBUG(...)   LOG(LOG_DEBUG, __VA_ARGS__)
 teach some ignorance

Macro Definition Documentation


#define LOG (   level,
do { \
if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
#define LOG_LEVEL
Default log level define.
Definition log.h:71
#define log_write(level,...)
Default log_write function, just maps to printf.
Definition log.h:106

Log message if level <= LOG_LEVEL.

Definition at line 84 of file log.h.


#define LOG_DEBUG (   ...)    LOG(LOG_DEBUG, __VA_ARGS__)

teach some ignorance

Definition at line 95 of file log.h.


#define LOG_ERROR (   ...)    LOG(LOG_ERROR, __VA_ARGS__)

log an error

Definition at line 92 of file log.h.


#define LOG_INFO (   ...)    LOG(LOG_INFO, __VA_ARGS__)

for the curious

Definition at line 94 of file log.h.



Default log level define.

Definition at line 71 of file log.h.


#define LOG_WARNING (   ...)    LOG(LOG_WARNING, __VA_ARGS__)

log a warning

Definition at line 93 of file log.h.

◆ log_write

#define log_write (   level,
)    printf(__VA_ARGS__)

Default log_write function, just maps to printf.

Definition at line 106 of file log.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

defined log levels

These are the logging levels a user can choose. The idea is to set LOG_LEVEL to one of these values in the application's Makefile. That will restrict output of log statements to those with equal or lower log level.

The default log level is LOG_INFO, which will print every message.

The log function calls of filtered messages will be optimized out at compile time, so a lower log level might result in smaller code size.


Lowest log level, will output nothing.


Error log level, will print only critical, non-recoverable errors like hardware initialization failures.


Warning log level, will print warning messages for temporary errors.


Informational log level, will print purely informational messages like successful system bootup, network link state, ...


Debug log level, printing developer stuff considered too verbose for production use.


print everything

Definition at line 52 of file log.h.