Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
c_logger.h
Go to the documentation of this file.
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_LOG_H_
6 #define ROFL_LOG_H_
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <rofl.h>
11 
18 //Define debug levels
19 enum rofl_debug_levels {
20  UNDEF_DEBUG_LEVEL = -1, /* Undefined debug level */
21  //EMERGENCY_LEVEL, /* system is unusable */
22  //ALERT_LEVEL, /* action must be taken immediately */
23  //CRITICAL_LEVEL, /* critical conditions */
24  ERROR_LEVEL, /* error conditions */
25  WARN_LEVEL, /* warning conditions */
26  //NOTICE_LEVEL, /* normal but significant condition */
27  INFO_LEVEL, /* informational */
28  DBG_LEVEL, /* debug-level messages */
29  DBG_VERBOSE_LEVEL, /* debug-level messages */
30  MAX_DEBUG_LEVEL /* DO NOT USE */
31 
32  /* do not put anything beyond MAX_DEBUG_LEVEL! */
33 };
34 
35 //Debug classes (not used currently)
36 enum rofl_debug_class {
37  UNDEF_DEBUG_CLASS = -1, /* Undefined debug level */
38  DEFAULT = 0, /* todo name it correct */
39  MAX_DEBUG_CLASS /* DO NOT USE */
40 
41  /* do not put anything beyond MAX_DEBUG_CLASS! */
42 };
43 
44 //Todo if ever use groups/classes modify this
45 #ifndef LOGGING_LEVEL
46  //If not defined default value DBG
47  #define ROFL_DEFAULT_LEVELS { DBG_LEVEL } /* default for each class */
48 #else
49  #define ROFL_DEFAULT_LEVELS { LOGGING_LEVEL }
50 #endif
51 
52 //Fwd declarations
53 extern enum rofl_debug_levels rofl_debug_level[MAX_DEBUG_CLASS];
54 extern int (*rofl_debug_print)(FILE *stream, const char *format, ...);
55 
56 //Define macros
57 #define ROFL_DEBUG_CHECK(cn, level) \
58  ( rofl_debug_level[cn] >= level )
59 #define ROFL_DEBUG_PRINT(fd, cn, level, stuff, ...) \
60  do{\
61  if (ROFL_DEBUG_CHECK(cn, level) && *rofl_debug_print != NULL){ \
62  rofl_debug_print(fd,stuff, ##__VA_ARGS__);\
63  }\
64  }while(0)
65 
66 #define ROFL_WARN(stuff,...) \
67  ROFL_DEBUG_PRINT(stderr, DEFAULT, WARN_LEVEL, stuff, ##__VA_ARGS__)
68 
69 #define ROFL_ERR(stuff, ...) \
70  ROFL_DEBUG_PRINT(stderr, DEFAULT, ERROR_LEVEL, stuff, ##__VA_ARGS__)
71 
72 #define ROFL_INFO(stuff,...) \
73  ROFL_DEBUG_PRINT(stderr, DEFAULT, INFO_LEVEL, stuff, ##__VA_ARGS__)
74 
75 
76 #ifdef DEBUG
77  #define ROFL_DEBUG(stuff, ...) \
78  ROFL_DEBUG_PRINT(stderr, DEFAULT, DBG_LEVEL, stuff, ##__VA_ARGS__)
79 
80  #define ROFL_DEBUG_VERBOSE(stuff, ...) \
81  ROFL_DEBUG_PRINT(stderr, DEFAULT, DBG_VERBOSE_LEVEL, stuff, ##__VA_ARGS__)
82 #else
83  //No logging
84  //#define ROFL_DEBUG_CHECK(stuff, ...) do{}while(0)
85  //#define ROFL_DEBUG_PRINT(stuff, ...) do{}while(0) /* ROFL_DEBUG_CHECK */
86  //#define ROFL_WARN(stuff, ...) do{}while(0)
87  //#define ROFL_ERR(stuff, ...) do{}while(0)
88  //#define ROFL_INFO(stuff,...) do{}while(0)
89  #define ROFL_DEBUG(stuff, ...) do{}while(0)
90  #define ROFL_DEBUG_VERBOSE(stuff, ...) do{}while(0)
91 #endif //ROFL_NO_LOGGING
92 
93 //C++ extern C
94 ROFL_BEGIN_DECLS
95 
96 //API to capture logging events of the logger
97 void rofl_set_logging_function(int (*logging_func)(FILE *stream, const char *format, ...));
98 
99 //API to capture logging events of the logger
100 void rofl_set_logging_level(/*cn,*/ enum rofl_debug_levels level);
101 
102 
103 //C++ extern C
104 ROFL_END_DECLS
105 
106 #endif /* ROFL_LOG_H_ */