FD.io VPP  v21.10.1-2-g0a485f517
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 <sys/time.h>
20 #include <vppinfra/types.h>
21 
22 #define foreach_vlib_log_level \
23  _(EMERG, emerg) \
24  _(ALERT, alert) \
25  _(CRIT, crit) \
26  _(ERR, error) \
27  _(WARNING, warn) \
28  _(NOTICE, notice) \
29  _(INFO, info) \
30  _(DEBUG, debug) \
31  _(DISABLED, disabled)
32 
33 typedef enum
34 {
36 #define _(uc,lc) VLIB_LOG_LEVEL_##uc,
38 #undef _
41 
42 typedef struct
43 {
49 
50 typedef struct
51 {
53  u8 *name;
54  // level of log messages kept for this subclass
56  // level of log messages sent to syslog for this subclass
58  // flag saying whether this subclass is logged to syslog
64 
65 typedef struct
66 {
68  u8 *name;
71 
72 typedef struct
73 {
77  char *name;
79 
80 
81 typedef struct vlib_log_registration
82 {
83  char *class_name;
88 
89  /* next */
92 
93 typedef struct
94 {
97  int size, next, count;
98 
104 
105  /* time zero */
106  struct timeval time_zero_timeval;
108 
109  /* config */
113 
114  /* registrations */
117 
119 
120 vlib_log_class_t vlib_log_register_class (char *vlass, char *subclass);
122 vlib_log_register_class_rate_limit (char *class, char *subclass,
123  u32 rate_limit);
124 void vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt,
125  ...);
126 int last_log_entry ();
127 u8 *format_vlib_log_class (u8 * s, va_list * args);
128 u8 *format_vlib_log_level (u8 * s, va_list * args);
129 
130 #define vlib_log_emerg(...) vlib_log(VLIB_LOG_LEVEL_EMERG, __VA_ARGS__)
131 #define vlib_log_alert(...) vlib_log(VLIB_LOG_LEVEL_ALERT, __VA_ARGS__)
132 #define vlib_log_crit(...) vlib_log(VLIB_LOG_LEVEL_CRIT, __VA_ARGS__)
133 #define vlib_log_err(...) vlib_log(VLIB_LOG_LEVEL_ERR, __VA_ARGS__)
134 #define vlib_log_warn(...) vlib_log(VLIB_LOG_LEVEL_WARNING, __VA_ARGS__)
135 #define vlib_log_notice(...) vlib_log(VLIB_LOG_LEVEL_NOTICE, __VA_ARGS__)
136 #define vlib_log_info(...) vlib_log(VLIB_LOG_LEVEL_INFO, __VA_ARGS__)
137 #define vlib_log_debug(...) vlib_log(VLIB_LOG_LEVEL_DEBUG, __VA_ARGS__)
138 
139 #define VLIB_REGISTER_LOG_CLASS(x,...) \
140 __VA_ARGS__ vlib_log_class_registration_t x; \
141 static void __clib_constructor \
142 __vlib_add_log_registration_##x (void) \
143  { \
144  vlib_log_main_t * lm = &log_main; \
145  x.next = lm->registrations; \
146  x.class = ~0; \
147  lm->registrations = &x; \
148  } \
149 __VA_ARGS__ vlib_log_class_registration_t x
150 
151 #endif /* included_vlib_log_h */
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
vlib_log_entry_t::level
vlib_log_level_t level
Definition: log.h:44
vlib_log_subclass_data_t
Definition: log.h:50
vlib_log_main_t::entries
vlib_log_entry_t * entries
Definition: log.h:95
types.h
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
next
u16 * next
Definition: nat44_ei_out2in.c:718
vlib_log_registration::subclass_name
char * subclass_name
Definition: log.h:84
vlib_log_subclass_data_t::syslog_level
vlib_log_level_t syslog_level
Definition: log.h:57
vlib_log_class_config_t::level
vlib_log_level_t level
Definition: log.h:74
vlib_log_main_t::unthrottle_time
int unthrottle_time
Definition: log.h:102
vlib_log_class_data_t::subclasses
vlib_log_subclass_data_t * subclasses
Definition: log.h:69
count
u8 count
Definition: dhcp.api:208
vlib_log_registration::next
struct vlib_log_registration * next
Definition: log.h:90
vlib_log_main_t::registrations
vlib_log_class_registration_t * registrations
Definition: log.h:115
vlib_log_main_t::max_class_name_length
u32 max_class_name_length
Definition: log.h:103
VLIB_LOG_N_LEVELS
@ VLIB_LOG_N_LEVELS
Definition: log.h:39
log_main
vlib_log_main_t log_main
Definition: log.c:23
uword
u64 uword
Definition: types.h:112
vlib_log_subclass_data_t::name
u8 * name
Definition: log.h:53
vlib_log_registration::default_syslog_level
vlib_log_level_t default_syslog_level
Definition: log.h:87
vlib_log_subclass_data_t::is_throttling
int is_throttling
Definition: log.h:61
vlib_log_entry_t
Definition: log.h:42
vlib_log_class_config_t::rate_limit
int rate_limit
Definition: log.h:76
f64
double f64
Definition: types.h:142
vlib_log_main_t::size
int size
Definition: log.h:97
vlib_log_class_data_t::name
u8 * name
Definition: log.h:68
vlib_log_level_t
vlib_log_level_t
Definition: log.h:33
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
vlib_log_main_t::config_index_by_name
uword * config_index_by_name
Definition: log.h:111
vlib_log_main_t::classes
vlib_log_class_data_t * classes
Definition: log.h:96
vlib_log_main_t::time_zero
f64 time_zero
Definition: log.h:107
VLIB_LOG_LEVEL_UNKNOWN
@ VLIB_LOG_LEVEL_UNKNOWN
Definition: log.h:35
vlib_log
void vlib_log(vlib_log_level_t level, vlib_log_class_t class, char *fmt,...)
Definition: log.c:131
vlib_log_register_class
vlib_log_class_t vlib_log_register_class(char *vlass, char *subclass)
Definition: log.c:339
u32
unsigned int u32
Definition: types.h:88
vlib_log_class_data_t::index
u32 index
Definition: log.h:67
vlib_log_registration::class_name
char * class_name
Definition: log.h:83
vlib_log_subclass_data_t::last_event_timestamp
f64 last_event_timestamp
Definition: log.h:59
vlib_log_entry_t::string
u8 * string
Definition: log.h:47
vlib_log_class_config_t::syslog_level
vlib_log_level_t syslog_level
Definition: log.h:75
vlib_log_subclass_data_t::index
u32 index
Definition: log.h:52
vlib_log_main_t::default_syslog_log_level
int default_syslog_log_level
Definition: log.h:101
vlib_log_class_config_t::name
char * name
Definition: log.h:77
vlib_log_register_class_rate_limit
vlib_log_class_t vlib_log_register_class_rate_limit(char *class, char *subclass, u32 rate_limit)
Definition: log.c:346
vlib_log_class_data_t
Definition: log.h:65
vlib_log_main_t::default_log_level
int default_log_level
Definition: log.h:100
vlib_log_entry_t::timestamp
f64 timestamp
Definition: log.h:46
u8
unsigned char u8
Definition: types.h:56
vlib_log_subclass_data_t::rate_limit
int rate_limit
Definition: log.h:62
vlib_log_main_t
Definition: log.h:93
vlib_log_registration
Definition: log.h:81
vlib_log_class_registration_t
struct vlib_log_registration vlib_log_class_registration_t
last_log_entry
int last_log_entry()
Definition: log.c:62
vlib_log_subclass_data_t::last_sec_count
int last_sec_count
Definition: log.h:60
foreach_vlib_log_level
#define foreach_vlib_log_level
Definition: log.h:22
vlib_log_class_config_t
Definition: log.h:72
vlib_log_registration::default_level
vlib_log_level_t default_level
Definition: log.h:86
vlib_log_subclass_data_t::level
vlib_log_level_t level
Definition: log.h:55
vlib_log_main_t::configs
vlib_log_class_config_t * configs
Definition: log.h:110
format_vlib_log_class
u8 * format_vlib_log_class(u8 *s, va_list *args)
Definition: log.c:89
format_vlib_log_level
u8 * format_vlib_log_level(u8 *s, va_list *args)
Definition: log.c:353
vlib_log_main_t::add_to_elog
int add_to_elog
Definition: log.h:112
vlib_log_main_t::default_rate_limit
int default_rate_limit
Definition: log.h:99