ROFL-pipeline  v0.6.0dev
logging.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef ROFL_PIPELINE_LOG_H_
6 #define ROFL_PIPELINE_LOG_H_
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "rofl.h"
11 
16 //If DEBUG is not defined, set pipeline to NOT log
17 #ifdef DEBUG
18  #define ROFL_PIPELINE_LOGGING_ENABLED
19 #endif
20 
21 //Define debug levels
22 enum rofl_pipeline_debug_levels {
23  PIPELINE_UNDEF_DEBUG_LEVEL = -1, /* Undefined debug level */
24  //PIPELINE_EMERGENCY, /* system is unusable */
25  //PIPELINE_ALERT, /* action must be taken immediately */
26  //PIPELINE_CRITICAL, /* critical conditions */
27  PIPELINE_ERROR, /* error conditions */
28  PIPELINE_WARN, /* warning conditions */
29  //PIPELINE_NOTICE, /* normal but significant condition */
30  PIPELINE_INFO, /* informational */
31  PIPELINE_DBG, /* debug-level messages */
32  PIPELINE_MAX_DEBUG_LEVEL /* DO NOT USE */
33 
34  /* do not put anything beyond MAX_DEBUG_LEVEL! */
35 };
36 
37 //Debug classes (not used currently)
38 enum rofl_pipeline_debug_class {
39  PIPELINE_UNDEF_DEBUG_CLASS = -1, /* Undefined debug level */
40  PIPELINE_DEFAULT = 0, /* todo name it correct */
41  PIPELINE_MAX_DEBUG_CLASS /* DO NOT USE */
42 
43  /* do not put anything beyond MAX_DEBUG_CLASS! */
44 };
45 
46 //Default value DBG
47 #define ROFL_PIPELINE_DBG_DEFAULT { PIPELINE_DBG } /* default for each class */
48 
49 //Fwd declarations
50 extern enum rofl_pipeline_debug_levels rofl_pipeline_debug_level[PIPELINE_MAX_DEBUG_CLASS];
51 extern int (*rofl_pipeline_debug_print)(FILE *stream, const char *format, ...);
52 
53 //Define macros
54 #ifdef ROFL_PIPELINE_LOGGING_ENABLED
55  #define ROFL_PIPELINE_DEBUG_CHECK(cn, level) \
56  ( rofl_pipeline_debug_level[cn] >= level )
57  #define ROFL_PIPELINE_DEBUG_PRINT(fd, cn, level, stuff, ...) \
58  do{\
59  if (ROFL_PIPELINE_DEBUG_CHECK(cn, level) && *rofl_pipeline_debug_print != NULL){ \
60  rofl_pipeline_debug_print(fd,"[rofl-pipeline] "stuff, ##__VA_ARGS__);\
61  }\
62  }while(0)
63 
64  #define ROFL_PIPELINE_DEBUG_PRINT_NO_PREFIX(fd, cn, level, stuff, ...) \
65  do{\
66  if (ROFL_PIPELINE_DEBUG_CHECK(cn, level) && *rofl_pipeline_debug_print != NULL){ \
67  rofl_pipeline_debug_print(fd,stuff, ##__VA_ARGS__);\
68  }\
69  }while(0)
70 
71 
72  #define ROFL_PIPELINE_WARN(stuff,...) \
73  ROFL_PIPELINE_DEBUG_PRINT(stderr, PIPELINE_DEFAULT, PIPELINE_WARN, stuff, ##__VA_ARGS__)
74 
75  #define ROFL_PIPELINE_ERR(stuff, ...) \
76  ROFL_PIPELINE_DEBUG_PRINT(stderr, PIPELINE_DEFAULT, PIPELINE_ERROR, stuff, ##__VA_ARGS__)
77 
78  #define ROFL_PIPELINE_INFO(stuff,...) \
79  ROFL_PIPELINE_DEBUG_PRINT(stderr, PIPELINE_DEFAULT, PIPELINE_INFO, stuff, ##__VA_ARGS__)
80 
81  #define ROFL_PIPELINE_INFO_NO_PREFIX(stuff,...) \
82  ROFL_PIPELINE_DEBUG_PRINT_NO_PREFIX(stderr, PIPELINE_DEFAULT, PIPELINE_INFO, stuff, ##__VA_ARGS__)
83 
84  #define ROFL_PIPELINE_DEBUG(stuff, ...) \
85  ROFL_PIPELINE_DEBUG_PRINT(stderr, PIPELINE_DEFAULT, PIPELINE_DBG, stuff, ##__VA_ARGS__)
86 
87  #define ROFL_PIPELINE_DEBUG_NO_PREFIX(stuff, ...) \
88  ROFL_PIPELINE_DEBUG_PRINT_NO_PREFIX(stderr, PIPELINE_DEFAULT, PIPELINE_DBG, stuff, ##__VA_ARGS__)
89 #else
90  //No logging
91  #define ROFL_PIPELINE_DEBUG_CHECK(stuff, ...) do{}while(0)
92  #define ROFL_PIPELINE_DEBUG_PRINT(stuff, ...) do{}while(0) /* ROFL_PIPELINE_DEBUG_CHECK */
93  #define ROFL_PIPELINE_WARN(stuff, ...) do{}while(0)
94  #define ROFL_PIPELINE_ERR(stuff, ...) do{}while(0)
95  #define ROFL_PIPELINE_INFO(stuff,...) do{}while(0)
96  #define ROFL_PIPELINE_INFO_NO_PREFIX(stuff,...) do{}while(0)
97  #define ROFL_PIPELINE_DEBUG(stuff, ...) do{}while(0)
98  #define ROFL_PIPELINE_DEBUG_NO_PREFIX(stuff, ...) do{}while(0)
99 #endif //ROFL_PIPELINE_NO_LOGGING
100 
101 //C++ extern C
102 ROFL_BEGIN_DECLS
103 
104 //API to capture logging events in the pipeline
105 void rofl_pipeline_set_logging_function(int (*logging_func)(FILE *stream, const char *format, ...));
106 
107 //API to set level
108 void rofl_pipeline_set_logging_level(/*cn,*/ enum rofl_pipeline_debug_levels level);
109 
110 //C++ extern C
111 ROFL_END_DECLS
112 
113 #endif /* ROFL_PIPELINE_LOG_H_ */