Libevhtp  1.2.13
log.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdio.h>
4 #include <errno.h>
5 #include <string.h>
6 
7 #define __FILENAME__ \
8  (strrchr(__FILE__, '/') ? \
9  strrchr(__FILE__, '/') + 1 : __FILE__)
10 
11 #define clean_errno() \
12  (errno == 0 ? "None" : strerror(errno))
13 
14 
15 #if !defined(EVHTP_DEBUG)
16 /* compile with all debug messages removed */
17 #define log_debug(M, ...)
18 #else
19 #define log_debug(M, ...) \
20  fprintf(stderr, "\33[34mDEBUG\33[39m "M " \33[90m at %s (%s:%d) \33[39m\n", ## \
21  __VA_ARGS__, \
22  __func__, \
23  __FILE__, \
24  __LINE__)
25 #endif
26 
27 
28 #define log_error(M, ...) \
29  fprintf(stderr, "\33[31mERR\33[39m " M " \33[90m at %s (%s:%d) \33[94merrno: %s\33[39m\n", ## \
30  __VA_ARGS__, \
31  __func__, \
32  __FILE__, \
33  __LINE__, \
34  clean_errno())
35 
36 #define log_warn(M, ...) \
37  fprintf(stderr, "\33[91mWARN\33[39m " M " \33[90m at %s (%s:%d) \33[94merrno: %s\33[39m\n", ## \
38  __VA_ARGS__, \
39  __func__, \
40  __FILE__, \
41  __LINE__, \
42  clean_errno())
43 
44 #define log_info(M, ...) \
45  fprintf(stderr, "\33[32mINFO\33[39m " M " \33[90m at %s (%s:%d) \33[39m\n", ## \
46  __VA_ARGS__, \
47  __func__, \
48  __FILENAME__, \
49  __LINE__)