csnip  0.1
log.h
Go to the documentation of this file.
1 #ifndef CSNIP_LOG_H
2 #define CSNIP_LOG_H
3 
23 #include <stdio.h>
24 
30 #define CSNIP_LOG_PRIO_DEBUGV 0
31 
37 #define CSNIP_LOG_PRIO_DEBUG 10
38 
40 #define CSNIP_LOG_PRIO_INFO 20
41 
43 #define CSNIP_LOG_PRIO_NOTICE 30
44 
46 #define CSNIP_LOG_PRIO_WARN 40
47 
49 #define CSNIP_LOG_PRIO_ERR 50
50 
51 #ifndef CSNIP_LOG_PRIO_MIN
63 #define CSNIP_LOG_PRIO_MIN 0
64 #endif
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
92 void csnip_log_config0(const char* filters_expr,
93  FILE* log_out);
94 
96 void csnip_log__mesg_trailer(FILE* fp);
97 void csnip_log__perror_trailer(FILE* fp);
98 void csnip_log__print(
99  void (*print_trailer)(FILE*),
100  int prio,
101  const char* src_file,
102  int src_line,
103  const char* src_func,
104  const char* component,
105  const char* format,
106  ...);
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #ifndef csnip_log_Mesg
133 #define csnip_log_Mesg(prio, ...) \
134  csnip_log_MesgForComp(CSNIP_LOG_COMPONENT, prio, __VA_ARGS__)
135 #endif
136 
137 #ifndef csnip_log_MesgForComp
153 #define csnip_log_MesgForComp(comp, prio, ...) \
154  do { \
155  if ((prio) >= CSNIP_LOG_PRIO_MIN) { \
156  csnip_log__print( \
157  csnip_log__mesg_trailer, \
158  (prio), \
159  __FILE__, __LINE__, __func__, \
160  (comp), __VA_ARGS__); \
161  } \
162  } while (0)
163 #endif
164 
165 #ifndef csnip_log_Perror
178 #define csnip_log_Perror(prio, ...) \
179  csnip_log_PerrorForComp(CSNIP_LOG_COMPONENT, prio, __VA_ARGS__)
180 #endif
181 
182 #ifndef csnip_log
198 #define csnip_log_PerrorForComp(comp, prio, ...) \
199  do { \
200  if ((prio) >= CSNIP_LOG_PRIO_MIN) { \
201  csnip_log__print( \
202  csnip_log__perror_trailer, \
203  (prio), \
204  __FILE__, __LINE__, __func__, \
205  (comp), __VA_ARGS__); \
206  } \
207  } while (0)
208 #endif
209 
212 #endif /* CSNIP_LOG_H */
213 
214 /* Short names */
215 #if defined(CSNIP_SHORT_NAMES) && !defined(CSNIP_LOG_HAVE_SHORT_NAMES)
216 #define LOG_PRIO_DEBUGV CSNIP_LOG_PRIO_DEBUGV
217 #define LOG_PRIO_DEBUG CSNIP_LOG_PRIO_DEBUG
218 #define LOG_PRIO_INFO CSNIP_LOG_PRIO_INFO
219 #define LOG_PRIO_NOTICE CSNIP_LOG_PRIO_NOTICE
220 #define LOG_PRIO_WARN CSNIP_LOG_PRIO_WARN
221 #define LOG_PRIO_ERR CSNIP_LOG_PRIO_ERR
222 #define log_config0 csnip_log_config0
223 #define log_Mesg csnip_log_Mesg
224 #define log_MesgForComp csnip_log_MesgForComp
225 #define log_Perror csnip_log_Perror
226 #define log_PerrorForComp csnip_log_PerrorForComp
227 #define CSNIP_LOG_HAVE_SHORT_NAMES
228 #endif /* CSNIP_SHORT_NAMES */
void csnip_log_config0(const char *filters_expr, FILE *log_out)
Simple logger configuration.
Definition: log.c:181