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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vlib_log_h
17 #define included_vlib_log_h
19 #include <vppinfra/types.h>
21 #define foreach_vlib_log_level \
34 VLIB_LOG_LEVEL_UNKNOWN = 0,
35 #define _(uc,lc) VLIB_LOG_LEVEL_##uc,
36 foreach_vlib_log_level
43 vlib_log_level_t level;
44 vlib_log_class_t class;
53 // level of log messages kept for this subclass
54 vlib_log_level_t level;
55 // level of log messages sent to syslog for this subclass
56 vlib_log_level_t syslog_level;
57 // flag saying whether this subclass is logged to syslog
58 f64 last_event_timestamp;
62 } vlib_log_subclass_data_t;
68 vlib_log_subclass_data_t *subclasses;
69 } vlib_log_class_data_t;
73 vlib_log_level_t level;
74 vlib_log_level_t syslog_level;
77 } vlib_log_class_config_t;
80 typedef struct vlib_log_registration
84 vlib_log_class_t class;
85 vlib_log_level_t default_level;
86 vlib_log_level_t default_syslog_level;
89 struct vlib_log_registration *next;
90 } vlib_log_class_registration_t;
94 vlib_log_entry_t *entries;
95 vlib_log_class_data_t *classes;
96 int size, next, count;
98 int default_rate_limit;
99 int default_log_level;
100 int default_syslog_log_level;
102 u32 max_class_name_length;
105 struct timeval time_zero_timeval;
109 vlib_log_class_config_t *configs;
110 uword *config_index_by_name;
113 vlib_log_class_registration_t *registrations;
116 extern vlib_log_main_t log_main;
118 vlib_log_class_t vlib_log_register_class (char *vlass, char *subclass);
120 vlib_log_register_class_rate_limit (char *class, char *subclass,
122 void vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt,
124 int last_log_entry ();
125 u8 *format_vlib_log_class (u8 * s, va_list * args);
126 u8 *format_vlib_log_level (u8 * s, va_list * args);
128 #define vlib_log_emerg(...) vlib_log(VLIB_LOG_LEVEL_EMERG, __VA_ARGS__)
129 #define vlib_log_alert(...) vlib_log(VLIB_LOG_LEVEL_ALERT, __VA_ARGS__)
130 #define vlib_log_crit(...) vlib_log(VLIB_LOG_LEVEL_CRIT, __VA_ARGS__)
131 #define vlib_log_err(...) vlib_log(VLIB_LOG_LEVEL_ERR, __VA_ARGS__)
132 #define vlib_log_warn(...) vlib_log(VLIB_LOG_LEVEL_WARNING, __VA_ARGS__)
133 #define vlib_log_notice(...) vlib_log(VLIB_LOG_LEVEL_NOTICE, __VA_ARGS__)
134 #define vlib_log_info(...) vlib_log(VLIB_LOG_LEVEL_INFO, __VA_ARGS__)
135 #define vlib_log_debug(...) vlib_log(VLIB_LOG_LEVEL_DEBUG, __VA_ARGS__)
137 #define VLIB_REGISTER_LOG_CLASS(x,...) \
138 __VA_ARGS__ vlib_log_class_registration_t x; \
139 static void __clib_constructor \
140 __vlib_add_log_registration_##x (void) \
142 vlib_log_main_t * lm = &log_main; \
143 x.next = lm->registrations; \
145 lm->registrations = &x; \
147 __VA_ARGS__ vlib_log_class_registration_t x
149 #endif /* included_vlib_log_h */
152 * fd.io coding-style-patch-verification: ON
155 * eval: (c-set-style "gnu")