log.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
32 #ifndef LOG_H
33 #define LOG_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
51 enum {
64 };
65 
66 #ifndef LOG_LEVEL
67 
70 #define LOG_LEVEL LOG_INFO
71 #endif
72 
76 #ifdef __clang__ /* following pragmas required for clang 3.8.0 */
77 #define LOG(level, ...) do { \
78  _Pragma("clang diagnostic push") \
79  _Pragma("clang diagnostic ignored \"-Wtautological-compare\"") \
80  if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U) \
81  _Pragma("clang diagnostic pop")
82 #else
83 #define LOG(level, ...) do { \
84  if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
85 #endif /* __clang__ */
86 
91 #define LOG_ERROR(...) LOG(LOG_ERROR, __VA_ARGS__)
92 #define LOG_WARNING(...) LOG(LOG_WARNING, __VA_ARGS__)
93 #define LOG_INFO(...) LOG(LOG_INFO, __VA_ARGS__)
94 #define LOG_DEBUG(...) LOG(LOG_DEBUG, __VA_ARGS__)
95 
97 #ifdef MODULE_LOG
98 #include "log_module.h"
99 #else
100 #include <stdio.h>
101 
105 #define log_write(level, ...) printf(__VA_ARGS__)
106 #endif
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* LOG_H */
113 
LOG_INFO
@ LOG_INFO
Informational log level, will print purely informational messages like successful system bootup,...
Definition: log.h:58
LOG_NONE
@ LOG_NONE
Lowest log level, will output nothing.
Definition: log.h:52
LOG_ALL
@ LOG_ALL
print everything
Definition: log.h:63
LOG_WARNING
@ LOG_WARNING
Warning log level, will print warning messages for temporary errors.
Definition: log.h:56
LOG_ERROR
@ LOG_ERROR
Error log level, will print only critical, non-recoverable errors like hardware initialization failur...
Definition: log.h:53
LOG_DEBUG
@ LOG_DEBUG
Debug log level, printing developer stuff considered too verbose for production use.
Definition: log.h:61