openwsn_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 
9 #pragma once
10 
24 #include <stdio.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
42 enum {
44  LOG_ERROR,
47  LOG_WARNING,
49  LOG_INFO,
52  LOG_DEBUG,
54  LOG_ALL
55 };
56 
57 #ifndef LOG_LEVEL
61 #define LOG_LEVEL LOG_INFO
62 #endif
63 
67 #ifdef __clang__ /* following pragmas required for clang 3.8.0 */
68 #define LOG(level, ...) do { \
69  _Pragma("clang diagnostic push") \
70  _Pragma("clang diagnostic ignored \"-Wtautological-compare\"") \
71  if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U) \
72  _Pragma("clang diagnostic pop")
73 #else
74 #define LOG(level, ...) do { \
75  if ((level) <= LOG_LEVEL) log_write((level), __VA_ARGS__); } while (0U)
76 #endif /* __clang__ */
77 
82 #define LOG_RIOT_ERROR(...) LOG(LOG_ERROR, __VA_ARGS__)
83 #define LOG_RIOT_WARNING(...) LOG(LOG_WARNING, __VA_ARGS__)
84 #define LOG_RIOT_INFO(...) LOG(LOG_INFO, __VA_ARGS__)
85 #define LOG_RIOT_DEBUG(...) LOG(LOG_DEBUG, __VA_ARGS__)
91 #define log_write(level, ...) printf(__VA_ARGS__)
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
@ LOG_ERROR
Error log level, will print only critical, non-recoverable errors like hardware initialization failur...
Definition: openwsn_log.h:44
@ LOG_INFO
Informational log level, will print purely informational messages like successful system bootup,...
Definition: openwsn_log.h:49
@ LOG_NONE
Lowest log level, will output nothing.
Definition: openwsn_log.h:43
@ LOG_ALL
print everything
Definition: openwsn_log.h:54
@ LOG_WARNING
Warning log level, will print warning messages for temporary errors.
Definition: openwsn_log.h:47
@ LOG_DEBUG
Debug log level, printing developer stuff considered too verbose for production use.
Definition: openwsn_log.h:52