9be199c8b978099863d9afab1276f8182923607c
[openvswitch] / include / vlog.h
1 /* Copyright (C) 2007 Board of Trustees, Leland Stanford Jr. University.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21
22 #ifndef VLOG_H
23 #define VLOG_H 1
24
25 #include <stdbool.h>
26
27 /* Logging importance levels. */
28 enum vlog_level {
29     VLL_EMER,
30     VLL_ERR,
31     VLL_WARN,
32     VLL_DBG,
33     VLL_N_LEVELS
34 };
35
36 const char *vlog_get_level_name(enum vlog_level);
37 enum vlog_level vlog_get_level_val(const char *name);
38
39 /* Facilities that we can log to. */
40 enum vlog_facility {
41     VLF_SYSLOG,
42     VLF_CONSOLE,
43     VLF_N_FACILITIES,
44     VLF_ANY_FACILITY = -1
45 };
46
47 const char *vlog_get_facility_name(enum vlog_facility);
48 enum vlog_facility vlog_get_facility_val(const char *name);
49
50 /* Modules that can emit log messages. */
51 #define VLOG_MODULES                            \
52         VLOG_MODULE(chain)                      \
53         VLOG_MODULE(controller)                 \
54         VLOG_MODULE(controller_connection)      \
55         VLOG_MODULE(ctlpath)                    \
56         VLOG_MODULE(datapath)                   \
57         VLOG_MODULE(dpif)                       \
58         VLOG_MODULE(dpctl)                      \
59         VLOG_MODULE(fault)                      \
60         VLOG_MODULE(flow)                       \
61         VLOG_MODULE(netdev)                     \
62         VLOG_MODULE(netlink)                    \
63         VLOG_MODULE(poll_loop)                  \
64         VLOG_MODULE(secchan)                    \
65         VLOG_MODULE(switch)                     \
66         VLOG_MODULE(socket_util)                \
67         VLOG_MODULE(vconn_netlink)              \
68         VLOG_MODULE(vconn_tcp)                  \
69         VLOG_MODULE(vconn_ssl)                  \
70         VLOG_MODULE(vconn)                      \
71
72 /* VLM_ constant for each vlog module. */
73 enum vlog_module {
74 #define VLOG_MODULE(NAME) VLM_##NAME,
75     VLOG_MODULES
76 #undef VLOG_MODULE
77     VLM_N_MODULES,
78     VLM_ANY_MODULE = -1
79 };
80
81 const char *vlog_get_module_name(enum vlog_module);
82 enum vlog_module vlog_get_module_val(const char *name);
83
84 /* Configuring how each module logs messages. */
85 enum vlog_level vlog_get_level(enum vlog_module, enum vlog_facility);
86 void vlog_set_levels(enum vlog_module, enum vlog_facility, enum vlog_level);
87 char *vlog_set_levels_from_string(const char *);
88 char *vlog_get_levels(void);
89 void vlog_set_verbosity(const char *arg);
90
91 /* Function for actual logging. */
92 void vlog_init(void);
93 void vlog_exit(void);
94 void vlog(enum vlog_module, enum vlog_level, const char *format, ...)
95     __attribute__((format(printf, 3, 4)));
96
97 /* Convenience macros.  To use these, define THIS_MODULE as a macro that
98  * expands to the module used by the current source file, e.g.
99  *      #include "vlog.h"
100  *      #define THIS_MODULE VLM_NETLINK
101  * Guaranteed to preserve errno.
102  */
103 #define VLOG_EMER(...) vlog(THIS_MODULE, VLL_EMER, __VA_ARGS__)
104 #define VLOG_ERR(...) vlog(THIS_MODULE, VLL_ERR, __VA_ARGS__)
105 #define VLOG_WARN(...) vlog(THIS_MODULE, VLL_WARN, __VA_ARGS__)
106 #define VLOG_DBG(...) vlog(THIS_MODULE, VLL_DBG, __VA_ARGS__)
107
108 #endif /* vlog.h */