FD.io VPP  v21.01.1
Vector Packet Processing
log.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef included_vlib_log_h
17 #define included_vlib_log_h
18 
19 #include <vppinfra/types.h>
20 
21 #define foreach_vlib_log_level \
22  _(EMERG, emerg) \
23  _(ALERT, alert) \
24  _(CRIT, crit) \
25  _(ERR, error) \
26  _(WARNING, warn) \
27  _(NOTICE, notice) \
28  _(INFO, info) \
29  _(DEBUG, debug) \
30  _(DISABLED, disabled)
31 
32 typedef enum
33 {
35 #define _(uc,lc) VLIB_LOG_LEVEL_##uc,
37 #undef _
40 
41 typedef struct
42 {
48 
49 typedef struct
50 {
52  u8 *name;
53  // level of log messages kept for this subclass
55  // level of log messages sent to syslog for this subclass
57  // flag saying whether this subclass is logged to syslog
63 
64 typedef struct
65 {
67  u8 *name;
70 
71 typedef struct
72 {
76  char *name;
78 
79 
80 typedef struct vlib_log_registration
81 {
82  char *class_name;
87 
88  /* next */
91 
92 typedef struct
93 {
96  int size, next, count;
97 
103 
104  /* time zero */
105  struct timeval time_zero_timeval;
107 
108  /* config */
112 
113  /* registrations */
116 
118 
119 vlib_log_class_t vlib_log_register_class (char *vlass, char *subclass);
121 vlib_log_register_class_rate_limit (char *class, char *subclass,
122  u32 rate_limit);
123 void vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt,
124  ...);
125 int last_log_entry ();
126 u8 *format_vlib_log_class (u8 * s, va_list * args);
127 u8 *format_vlib_log_level (u8 * s, va_list * args);
128 
129 #define vlib_log_emerg(...) vlib_log(VLIB_LOG_LEVEL_EMERG, __VA_ARGS__)
130 #define vlib_log_alert(...) vlib_log(VLIB_LOG_LEVEL_ALERT, __VA_ARGS__)
131 #define vlib_log_crit(...) vlib_log(VLIB_LOG_LEVEL_CRIT, __VA_ARGS__)
132 #define vlib_log_err(...) vlib_log(VLIB_LOG_LEVEL_ERR, __VA_ARGS__)
133 #define vlib_log_warn(...) vlib_log(VLIB_LOG_LEVEL_WARNING, __VA_ARGS__)
134 #define vlib_log_notice(...) vlib_log(VLIB_LOG_LEVEL_NOTICE, __VA_ARGS__)
135 #define vlib_log_info(...) vlib_log(VLIB_LOG_LEVEL_INFO, __VA_ARGS__)
136 #define vlib_log_debug(...) vlib_log(VLIB_LOG_LEVEL_DEBUG, __VA_ARGS__)
137 
138 #define VLIB_REGISTER_LOG_CLASS(x,...) \
139 __VA_ARGS__ vlib_log_class_registration_t x; \
140 static void __clib_constructor \
141 __vlib_add_log_registration_##x (void) \
142  { \
143  vlib_log_main_t * lm = &log_main; \
144  x.next = lm->registrations; \
145  x.class = ~0; \
146  lm->registrations = &x; \
147  } \
148 __VA_ARGS__ vlib_log_class_registration_t x
149 
150 #endif /* included_vlib_log_h */
151 
152 /*
153  * fd.io coding-style-patch-verification: ON
154  *
155  * Local Variables:
156  * eval: (c-set-style "gnu")
157  * End:
158  */
vlib_log_entry_t * entries
Definition: log.h:94
vlib_log_level_t level
Definition: log.h:54
u8 * format_vlib_log_class(u8 *s, va_list *args)
Definition: log.c:89
vlib_log_level_t syslog_level
Definition: log.h:56
vlib_log_class_data_t * classes
Definition: log.h:95
vlib_log_class_t vlib_log_register_class(char *vlass, char *subclass)
Definition: log.c:338
f64 timestamp
Definition: log.h:45
int add_to_elog
Definition: log.h:111
vlib_log_level_t level
Definition: log.h:73
vlib_log_class_registration_t * registrations
Definition: log.h:114
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
u32 vlib_log_class_t
Definition: vlib.h:51
struct vlib_log_registration * next
Definition: log.h:89
char * subclass_name
Definition: log.h:83
unsigned int u32
Definition: types.h:88
int default_log_level
Definition: log.h:99
u8 * format_vlib_log_level(u8 *s, va_list *args)
Definition: log.c:352
struct vlib_log_registration vlib_log_class_registration_t
#define foreach_vlib_log_level
Definition: log.h:21
int default_syslog_log_level
Definition: log.h:100
int size
Definition: log.h:96
vlib_log_level_t syslog_level
Definition: log.h:74
void vlib_log(vlib_log_level_t level, vlib_log_class_t class, char *fmt,...)
Definition: log.c:131
int cJSON_bool fmt
Definition: cJSON.h:160
vlib_log_subclass_data_t * subclasses
Definition: log.h:68
vlib_log_class_t vlib_log_register_class_rate_limit(char *class, char *subclass, u32 rate_limit)
Definition: log.c:345
int default_rate_limit
Definition: log.h:98
Definition: log.h:41
vlib_log_level_t
Definition: log.h:32
vlib_log_level_t default_syslog_level
Definition: log.h:86
char * class_name
Definition: log.h:82
vlib_log_level_t level
Definition: log.h:43
f64 time_zero
Definition: log.h:106
vlib_log_class_config_t * configs
Definition: log.h:109
vlib_log_level_t default_level
Definition: log.h:85
u32 max_class_name_length
Definition: log.h:102
vlib_log_main_t log_main
Definition: log.c:23
u64 uword
Definition: types.h:112
f64 last_event_timestamp
Definition: log.h:58
int last_log_entry()
Definition: log.c:62
uword * config_index_by_name
Definition: log.h:110
u8 count
Definition: dhcp.api:208
u8 * string
Definition: log.h:46
int unthrottle_time
Definition: log.h:101