Factor learning switch out of controller into library.
[sliver-openvswitch.git] / include / vlog.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  * 
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  * 
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #ifndef VLOG_H
35 #define VLOG_H 1
36
37 #include <stdbool.h>
38
39 /* Logging importance levels. */
40 enum vlog_level {
41     VLL_EMER,
42     VLL_ERR,
43     VLL_WARN,
44     VLL_DBG,
45     VLL_N_LEVELS
46 };
47
48 const char *vlog_get_level_name(enum vlog_level);
49 enum vlog_level vlog_get_level_val(const char *name);
50
51 /* Facilities that we can log to. */
52 enum vlog_facility {
53     VLF_SYSLOG,
54     VLF_CONSOLE,
55     VLF_N_FACILITIES,
56     VLF_ANY_FACILITY = -1
57 };
58
59 const char *vlog_get_facility_name(enum vlog_facility);
60 enum vlog_facility vlog_get_facility_val(const char *name);
61
62 /* Modules that can emit log messages. */
63 #define VLOG_MODULES                            \
64         VLOG_MODULE(chain)                      \
65         VLOG_MODULE(controller)                 \
66         VLOG_MODULE(ctlpath)                    \
67         VLOG_MODULE(datapath)                   \
68         VLOG_MODULE(dpif)                       \
69         VLOG_MODULE(dpctl)                      \
70         VLOG_MODULE(fault)                      \
71         VLOG_MODULE(flow)                       \
72         VLOG_MODULE(learning_switch)            \
73         VLOG_MODULE(mac_learning)               \
74         VLOG_MODULE(netdev)                     \
75         VLOG_MODULE(netlink)                    \
76         VLOG_MODULE(poll_loop)                  \
77         VLOG_MODULE(secchan)                    \
78         VLOG_MODULE(rconn)                      \
79         VLOG_MODULE(switch)                     \
80         VLOG_MODULE(socket_util)                \
81         VLOG_MODULE(vconn_netlink)              \
82         VLOG_MODULE(vconn_tcp)                  \
83         VLOG_MODULE(vconn_ssl)                  \
84         VLOG_MODULE(vconn)                      \
85
86 /* VLM_ constant for each vlog module. */
87 enum vlog_module {
88 #define VLOG_MODULE(NAME) VLM_##NAME,
89     VLOG_MODULES
90 #undef VLOG_MODULE
91     VLM_N_MODULES,
92     VLM_ANY_MODULE = -1
93 };
94
95 const char *vlog_get_module_name(enum vlog_module);
96 enum vlog_module vlog_get_module_val(const char *name);
97
98 /* Configuring how each module logs messages. */
99 enum vlog_level vlog_get_level(enum vlog_module, enum vlog_facility);
100 void vlog_set_levels(enum vlog_module, enum vlog_facility, enum vlog_level);
101 char *vlog_set_levels_from_string(const char *);
102 char *vlog_get_levels(void);
103 bool vlog_is_enabled(enum vlog_module, enum vlog_level);
104 void vlog_set_verbosity(const char *arg);
105
106 /* Function for actual logging. */
107 void vlog_init(void);
108 void vlog_exit(void);
109 void vlog(enum vlog_module, enum vlog_level, const char *format, ...)
110     __attribute__((format(printf, 3, 4)));
111
112 /* Convenience macros.  To use these, define THIS_MODULE as a macro that
113  * expands to the module used by the current source file, e.g.
114  *      #include "vlog.h"
115  *      #define THIS_MODULE VLM_NETLINK
116  * Guaranteed to preserve errno.
117  */
118 #define VLOG_EMER(...) vlog(THIS_MODULE, VLL_EMER, __VA_ARGS__)
119 #define VLOG_ERR(...) vlog(THIS_MODULE, VLL_ERR, __VA_ARGS__)
120 #define VLOG_WARN(...) vlog(THIS_MODULE, VLL_WARN, __VA_ARGS__)
121 #define VLOG_DBG(...) vlog(THIS_MODULE, VLL_DBG, __VA_ARGS__)
122
123 /* More convenience macros, for testing whether a given level is enabled in
124  * THIS_MODULE.  When constructing a log message is expensive, this enables it
125  * to be skipped. */
126 #define VLOG_IS_EMER_ENABLED() true
127 #define VLOG_IS_ERR_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_EMER)
128 #define VLOG_IS_WARN_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_WARN)
129 #define VLOG_IS_DBG_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_DBG)
130
131 #endif /* vlog.h */