Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 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 | #include <stdbool.h> |
| 17 | #include <vlib/vlib.h> |
| 18 | #include <vlib/log.h> |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 19 | #include <vlib/unix/unix.h> |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 20 | #include <syslog.h> |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 21 | #include <vppinfra/elog.h> |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 22 | |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 23 | vlib_log_main_t log_main = { |
| 24 | .default_log_level = VLIB_LOG_LEVEL_NOTICE, |
| 25 | .default_syslog_log_level = VLIB_LOG_LEVEL_WARNING, |
| 26 | .unthrottle_time = 3, |
| 27 | .size = 512, |
Florin Coras | 6bec05b | 2023-04-10 20:44:26 -0700 | [diff] [blame] | 28 | .add_to_elog = 0, |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 29 | .default_rate_limit = 50, |
| 30 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 31 | |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 32 | VLIB_REGISTER_LOG_CLASS (log_log, static) = { |
| 33 | .class_name = "log", |
| 34 | }; |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 35 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 36 | static const int colors[] = { |
| 37 | [VLIB_LOG_LEVEL_EMERG] = 1, /* red */ |
| 38 | [VLIB_LOG_LEVEL_ALERT] = 1, /* red */ |
| 39 | [VLIB_LOG_LEVEL_CRIT] = 1, /* red */ |
| 40 | [VLIB_LOG_LEVEL_ERR] = 1, /* red */ |
| 41 | [VLIB_LOG_LEVEL_WARNING] = 3, /* yellow */ |
| 42 | [VLIB_LOG_LEVEL_NOTICE] = 2, /* green */ |
| 43 | [VLIB_LOG_LEVEL_INFO] = 4, /* blue */ |
| 44 | [VLIB_LOG_LEVEL_DEBUG] = 6, /* cyan */ |
| 45 | }; |
| 46 | |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 47 | static const int log_level_to_syslog_priority[] = { |
| 48 | [VLIB_LOG_LEVEL_EMERG] = LOG_EMERG, |
| 49 | [VLIB_LOG_LEVEL_ALERT] = LOG_ALERT, |
| 50 | [VLIB_LOG_LEVEL_CRIT] = LOG_CRIT, |
| 51 | [VLIB_LOG_LEVEL_ERR] = LOG_ERR, |
| 52 | [VLIB_LOG_LEVEL_WARNING] = LOG_WARNING, |
| 53 | [VLIB_LOG_LEVEL_NOTICE] = LOG_NOTICE, |
| 54 | [VLIB_LOG_LEVEL_INFO] = LOG_INFO, |
| 55 | [VLIB_LOG_LEVEL_DEBUG] = LOG_DEBUG, |
| 56 | [VLIB_LOG_LEVEL_DISABLED] = LOG_DEBUG, |
| 57 | }; |
| 58 | |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 59 | int |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 60 | last_log_entry () |
| 61 | { |
| 62 | vlib_log_main_t *lm = &log_main; |
| 63 | int i; |
| 64 | |
| 65 | i = lm->next - lm->count; |
| 66 | |
| 67 | if (i < 0) |
| 68 | i += lm->size; |
| 69 | return i; |
| 70 | } |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 71 | u8 * |
| 72 | format_vlib_log_class (u8 * s, va_list * args) |
| 73 | { |
| 74 | vlib_log_class_t ci = va_arg (*args, vlib_log_class_t); |
Vratko Polak | e9ea7d5 | 2023-07-26 13:48:20 +0200 | [diff] [blame] | 75 | vlib_log_class_data_t *c = vlib_log_get_class_data (ci); |
Damjan Marion | bf179a9 | 2023-05-26 19:06:10 +0000 | [diff] [blame] | 76 | vlib_log_subclass_data_t *sc = vlib_log_get_subclass_data (ci); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 77 | |
| 78 | if (sc->name) |
| 79 | return format (s, "%v/%v", c->name, sc->name); |
| 80 | else |
| 81 | return format (s, "%v", c->name, 0); |
| 82 | } |
| 83 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 84 | u8 * |
| 85 | format_indent (u8 * s, va_list * args) |
| 86 | { |
| 87 | u8 *v = va_arg (*args, u8 *); |
| 88 | u32 indent = va_arg (*args, u32); |
| 89 | u8 *c; |
| 90 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 91 | vec_foreach (c, v) |
| 92 | { |
| 93 | vec_add (s, c, 1); |
| 94 | if (c[0] == '\n') |
| 95 | for (u32 i = 0; i < indent; i++) |
| 96 | vec_add1 (s, (u8) ' '); |
| 97 | } |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 98 | return s; |
| 99 | } |
| 100 | |
| 101 | static int |
| 102 | log_level_is_enabled (vlib_log_level_t level, vlib_log_level_t configured) |
| 103 | { |
| 104 | if (configured == VLIB_LOG_LEVEL_DISABLED) |
| 105 | return 0; |
| 106 | if (level > configured) |
| 107 | return 0; |
| 108 | return 1; |
| 109 | } |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 110 | |
| 111 | void |
| 112 | vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt, ...) |
| 113 | { |
| 114 | vlib_main_t *vm = vlib_get_main (); |
| 115 | vlib_log_main_t *lm = &log_main; |
| 116 | vlib_log_entry_t *e; |
Damjan Marion | bf179a9 | 2023-05-26 19:06:10 +0000 | [diff] [blame] | 117 | vlib_log_subclass_data_t *sc = vlib_log_get_subclass_data (class); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 118 | va_list va; |
| 119 | f64 t = vlib_time_now (vm); |
| 120 | f64 delta = t - sc->last_event_timestamp; |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 121 | int log_enabled = log_level_is_enabled (level, sc->level); |
| 122 | int syslog_enabled = log_level_is_enabled (level, sc->syslog_level); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 123 | u8 *s = 0; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 124 | |
| 125 | /* make sure we are running on the main thread to avoid use in dataplane |
| 126 | code, for dataplane logging consider use of event-logger */ |
| 127 | ASSERT (vlib_get_thread_index () == 0); |
| 128 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 129 | if ((log_enabled || syslog_enabled) == 0) |
| 130 | return; |
| 131 | |
| 132 | vec_validate (lm->entries, lm->size); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 133 | |
| 134 | if ((delta > lm->unthrottle_time) || |
| 135 | (sc->is_throttling == 0 && (delta > 1))) |
| 136 | { |
| 137 | sc->last_event_timestamp = t; |
| 138 | sc->last_sec_count = 0; |
| 139 | sc->is_throttling = 0; |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | sc->last_sec_count++; |
| 144 | if (sc->last_sec_count > sc->rate_limit) |
| 145 | return; |
| 146 | else if (sc->last_sec_count == sc->rate_limit) |
| 147 | { |
| 148 | vec_reset_length (s); |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 149 | s = format (s, "--- message(s) throttled ---"); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 150 | sc->is_throttling = 1; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if (s == 0) |
| 155 | { |
| 156 | va_start (va, fmt); |
| 157 | s = va_format (s, fmt, &va); |
| 158 | va_end (va); |
| 159 | } |
| 160 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 161 | if (syslog_enabled) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 162 | { |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 163 | u8 *l = 0; |
| 164 | if (unix_main.flags & (UNIX_FLAG_INTERACTIVE | UNIX_FLAG_NOSYSLOG)) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 165 | { |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 166 | int indent = 0; |
| 167 | int with_colors = (unix_main.flags & UNIX_FLAG_NOCOLOR) == 0; |
| 168 | u8 *fmt; |
| 169 | if (with_colors) |
| 170 | { |
| 171 | l = format (l, "\x1b[%um", 90 + colors[level]); |
| 172 | indent = vec_len (l); |
| 173 | } |
| 174 | fmt = format (0, "%%-%uU [%%-6U]: ", lm->max_class_name_length); |
jiangxiaoming | 94a92aa | 2020-10-22 10:08:36 +0800 | [diff] [blame] | 175 | vec_terminate_c_string (fmt); |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 176 | l = format (l, (char *) fmt, format_vlib_log_class, class, |
| 177 | format_vlib_log_level, level); |
| 178 | vec_free (fmt); |
| 179 | indent = vec_len (l) - indent; |
| 180 | if (with_colors) |
| 181 | l = format (l, "\x1b[0m"); |
| 182 | l = format (l, "%U", format_indent, s, indent); |
| 183 | fformat (stderr, "%v\n", l); |
| 184 | fflush (stderr); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 185 | } |
| 186 | else |
| 187 | { |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 188 | l = format (l, "%U", format_vlib_log_class, class); |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 189 | int prio = log_level_to_syslog_priority[level]; |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 190 | int is_term = vec_c_string_is_terminated (l) ? 1 : 0; |
| 191 | |
| 192 | syslog (prio, "%.*s: %.*s", (int) vec_len (l), l, |
| 193 | (int) vec_len (s) - is_term, s); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 194 | } |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 195 | vec_free (l); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 198 | if (log_enabled) |
| 199 | { |
| 200 | e = vec_elt_at_index (lm->entries, lm->next); |
| 201 | vec_free (e->string); |
| 202 | e->level = level; |
| 203 | e->class = class; |
| 204 | e->string = s; |
| 205 | e->timestamp = t; |
| 206 | s = 0; |
| 207 | |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 208 | if (lm->add_to_elog) |
| 209 | { |
luoyaozu | 2d3da80 | 2022-11-23 15:59:17 +0800 | [diff] [blame] | 210 | ELOG_TYPE_DECLARE(ee) = |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 211 | { |
| 212 | .format = "log-%s: %s", |
| 213 | .format_args = "t4T4", |
luoyaozu | 2d3da80 | 2022-11-23 15:59:17 +0800 | [diff] [blame] | 214 | .n_enum_strings = VLIB_LOG_N_LEVELS, |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 215 | .enum_strings = { |
luoyaozu | 2d3da80 | 2022-11-23 15:59:17 +0800 | [diff] [blame] | 216 | "unknown", |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 217 | "emerg", |
| 218 | "alert", |
| 219 | "crit", |
| 220 | "err", |
| 221 | "warn", |
| 222 | "notice", |
| 223 | "info", |
| 224 | "debug", |
| 225 | "disabled", |
| 226 | }, |
| 227 | }; |
luoyaozu | 2d3da80 | 2022-11-23 15:59:17 +0800 | [diff] [blame] | 228 | struct |
| 229 | { |
| 230 | u32 log_level; |
| 231 | u32 string_index; |
| 232 | } * ed; |
Damjan Marion | f553a2c | 2021-03-26 13:45:37 +0100 | [diff] [blame] | 233 | ed = ELOG_DATA (&vlib_global_main.elog_main, ee); |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 234 | ed->log_level = level; |
Damjan Marion | f553a2c | 2021-03-26 13:45:37 +0100 | [diff] [blame] | 235 | ed->string_index = |
Damjan Marion | 4926cdd | 2021-12-22 12:25:49 +0100 | [diff] [blame] | 236 | elog_string (&vlib_global_main.elog_main, "%v%c", e->string, 0); |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 239 | lm->next = (lm->next + 1) % lm->size; |
| 240 | if (lm->size > lm->count) |
| 241 | lm->count++; |
| 242 | } |
| 243 | |
| 244 | vec_free (s); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Dave Barach | 8dc954a | 2020-02-05 17:31:09 -0500 | [diff] [blame] | 247 | static vlib_log_class_t |
| 248 | vlib_log_register_class_internal (char *class, char *subclass, u32 limit) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 249 | { |
| 250 | vlib_log_main_t *lm = &log_main; |
| 251 | vlib_log_class_data_t *c = NULL; |
| 252 | vlib_log_subclass_data_t *s; |
| 253 | vlib_log_class_data_t *tmp; |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 254 | vlib_log_class_config_t *cc = 0, *scc = 0; |
| 255 | uword *p; |
| 256 | u8 *str; |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 257 | u32 length = 0; |
| 258 | |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 259 | if ((p = hash_get_mem (lm->config_index_by_name, class))) |
| 260 | cc = vec_elt_at_index (lm->configs, p[0]); |
| 261 | |
| 262 | str = format (0, "%s/%s%c", class, subclass, 0); |
| 263 | if ((p = hash_get_mem (lm->config_index_by_name, (char *) str))) |
| 264 | scc = vec_elt_at_index (lm->configs, p[0]); |
| 265 | vec_free (str); |
| 266 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 267 | vec_foreach (tmp, lm->classes) |
| 268 | { |
Su Wang | 34321b3 | 2019-01-11 12:46:05 -0500 | [diff] [blame] | 269 | if (vec_len (tmp->name) != strlen (class)) |
| 270 | continue; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 271 | if (!memcmp (class, tmp->name, vec_len (tmp->name))) |
| 272 | { |
| 273 | c = tmp; |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | if (!c) |
| 278 | { |
| 279 | vec_add2 (lm->classes, c, 1); |
| 280 | c->index = c - lm->classes; |
| 281 | c->name = format (0, "%s", class); |
| 282 | } |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 283 | length = vec_len (c->name); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 284 | |
| 285 | vec_add2 (c->subclasses, s, 1); |
| 286 | s->index = s - c->subclasses; |
| 287 | s->name = subclass ? format (0, "%s", subclass) : 0; |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 288 | |
| 289 | if (scc && scc->rate_limit != ~0) |
| 290 | s->rate_limit = scc->rate_limit; |
| 291 | else if (cc && cc->rate_limit != ~0) |
| 292 | s->rate_limit = cc->rate_limit; |
| 293 | else if (limit) |
| 294 | s->rate_limit = limit; |
| 295 | else |
| 296 | s->rate_limit = lm->default_rate_limit; |
| 297 | |
| 298 | if (scc && scc->level != ~0) |
| 299 | s->level = scc->level; |
| 300 | else if (cc && cc->level != ~0) |
| 301 | s->level = cc->level; |
| 302 | else |
| 303 | s->level = lm->default_log_level; |
| 304 | |
| 305 | if (scc && scc->syslog_level != ~0) |
| 306 | s->syslog_level = scc->syslog_level; |
| 307 | else if (cc && cc->syslog_level != ~0) |
| 308 | s->syslog_level = cc->syslog_level; |
| 309 | else |
| 310 | s->syslog_level = lm->default_syslog_log_level; |
| 311 | |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 312 | if (subclass) |
| 313 | length += 1 + vec_len (s->name); |
| 314 | if (length > lm->max_class_name_length) |
| 315 | lm->max_class_name_length = length; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 316 | return (c->index << 16) | (s->index); |
| 317 | } |
| 318 | |
Dave Barach | 8dc954a | 2020-02-05 17:31:09 -0500 | [diff] [blame] | 319 | vlib_log_class_t |
| 320 | vlib_log_register_class (char *class, char *subclass) |
| 321 | { |
| 322 | return vlib_log_register_class_internal (class, subclass, |
| 323 | 0 /* default rate limit */ ); |
| 324 | } |
| 325 | |
| 326 | vlib_log_class_t |
| 327 | vlib_log_register_class_rate_limit (char *class, char *subclass, u32 limit) |
| 328 | { |
| 329 | return vlib_log_register_class_internal (class, subclass, limit); |
| 330 | } |
| 331 | |
| 332 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 333 | u8 * |
| 334 | format_vlib_log_level (u8 * s, va_list * args) |
| 335 | { |
| 336 | vlib_log_level_t i = va_arg (*args, vlib_log_level_t); |
| 337 | char *t = 0; |
| 338 | |
| 339 | switch (i) |
| 340 | { |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 341 | #define _(uc,lc) case VLIB_LOG_LEVEL_##uc: t = #lc; break; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 342 | foreach_vlib_log_level |
| 343 | #undef _ |
| 344 | default: |
| 345 | return format (s, "unknown"); |
| 346 | } |
| 347 | return format (s, "%s", t); |
| 348 | } |
| 349 | |
Damjan Marion | 62d656a | 2022-03-09 16:10:54 +0100 | [diff] [blame] | 350 | clib_error_t * |
| 351 | vlib_log_init (vlib_main_t *vm) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 352 | { |
| 353 | vlib_log_main_t *lm = &log_main; |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 354 | vlib_log_class_registration_t *r = lm->registrations; |
Dave Barach | 10a690b | 2018-09-27 08:46:15 -0400 | [diff] [blame] | 355 | |
| 356 | gettimeofday (&lm->time_zero_timeval, 0); |
| 357 | lm->time_zero = vlib_time_now (vm); |
| 358 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 359 | vec_validate (lm->entries, lm->size); |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 360 | |
| 361 | while (r) |
| 362 | { |
| 363 | r->class = vlib_log_register_class (r->class_name, r->subclass_name); |
| 364 | if (r->default_level) |
Damjan Marion | bf179a9 | 2023-05-26 19:06:10 +0000 | [diff] [blame] | 365 | vlib_log_get_subclass_data (r->class)->level = r->default_level; |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 366 | if (r->default_syslog_level) |
Damjan Marion | bf179a9 | 2023-05-26 19:06:10 +0000 | [diff] [blame] | 367 | vlib_log_get_subclass_data (r->class)->syslog_level = |
| 368 | r->default_syslog_level; |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 369 | r = r->next; |
| 370 | } |
| 371 | |
| 372 | r = lm->registrations; |
| 373 | while (r) |
| 374 | { |
| 375 | vlib_log_debug (r->class, "initialized"); |
| 376 | r = r->next; |
| 377 | } |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 381 | static clib_error_t * |
| 382 | show_log (vlib_main_t * vm, |
| 383 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 384 | { |
| 385 | clib_error_t *error = 0; |
| 386 | vlib_log_main_t *lm = &log_main; |
| 387 | vlib_log_entry_t *e; |
| 388 | int i = last_log_entry (); |
| 389 | int count = lm->count; |
Dave Barach | 10a690b | 2018-09-27 08:46:15 -0400 | [diff] [blame] | 390 | f64 time_offset; |
| 391 | |
| 392 | time_offset = (f64) lm->time_zero_timeval.tv_sec |
| 393 | + (((f64) lm->time_zero_timeval.tv_usec) * 1e-6) - lm->time_zero; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 394 | |
| 395 | while (count--) |
| 396 | { |
| 397 | e = vec_elt_at_index (lm->entries, i); |
Andreas Schultz | 972dc17 | 2020-05-15 11:50:07 +0200 | [diff] [blame] | 398 | vlib_cli_output (vm, "%U %-10U %-14U %v", format_time_float, NULL, |
| 399 | e->timestamp + time_offset, format_vlib_log_level, |
| 400 | e->level, format_vlib_log_class, e->class, e->string); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 401 | i = (i + 1) % lm->size; |
| 402 | } |
| 403 | |
| 404 | return error; |
| 405 | } |
| 406 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 407 | VLIB_CLI_COMMAND (cli_show_log, static) = { |
| 408 | .path = "show logging", |
| 409 | .short_help = "show logging", |
| 410 | .function = show_log, |
| 411 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 412 | |
| 413 | static clib_error_t * |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 414 | show_log_config (vlib_main_t * vm, |
| 415 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 416 | { |
| 417 | clib_error_t *error = 0; |
| 418 | vlib_log_main_t *lm = &log_main; |
| 419 | vlib_log_class_data_t *c; |
| 420 | vlib_log_subclass_data_t *sc; |
| 421 | |
| 422 | vlib_cli_output (vm, "%-20s %u entries", "Buffer Size:", lm->size); |
| 423 | vlib_cli_output (vm, "Defaults:\n"); |
| 424 | vlib_cli_output (vm, "%-20s %U", " Log Level:", |
| 425 | format_vlib_log_level, lm->default_log_level); |
| 426 | vlib_cli_output (vm, "%-20s %U", " Syslog Log Level:", |
| 427 | format_vlib_log_level, lm->default_syslog_log_level); |
| 428 | vlib_cli_output (vm, "%-20s %u msgs/sec", " Rate Limit:", |
| 429 | lm->default_rate_limit); |
| 430 | vlib_cli_output (vm, "\n"); |
| 431 | vlib_cli_output (vm, "%-22s %-14s %-14s %s", |
| 432 | "Class/Subclass", "Level", "Syslog Level", "Rate Limit"); |
| 433 | |
Jerome Tollet | e4db803 | 2018-10-02 22:54:30 +0200 | [diff] [blame] | 434 | |
| 435 | u8 *defstr = format (0, "default"); |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 436 | vec_foreach (c, lm->classes) |
| 437 | { |
Jerome Tollet | e4db803 | 2018-10-02 22:54:30 +0200 | [diff] [blame] | 438 | vlib_cli_output (vm, "%v", c->name); |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 439 | vec_foreach (sc, c->subclasses) |
| 440 | { |
Jerome Tollet | e4db803 | 2018-10-02 22:54:30 +0200 | [diff] [blame] | 441 | vlib_cli_output (vm, " %-20v %-14U %-14U %d", |
| 442 | sc->name ? sc->name : defstr, |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 443 | format_vlib_log_level, sc->level, |
| 444 | format_vlib_log_level, sc->syslog_level, |
| 445 | sc->rate_limit); |
| 446 | } |
| 447 | } |
Jerome Tollet | e4db803 | 2018-10-02 22:54:30 +0200 | [diff] [blame] | 448 | vec_free (defstr); |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 449 | |
| 450 | return error; |
| 451 | } |
| 452 | |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 453 | VLIB_CLI_COMMAND (cli_show_log_config, static) = { |
| 454 | .path = "show logging configuration", |
| 455 | .short_help = "show logging configuration", |
| 456 | .function = show_log_config, |
| 457 | }; |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 458 | |
| 459 | static clib_error_t * |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 460 | clear_log (vlib_main_t * vm, |
| 461 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 462 | { |
| 463 | clib_error_t *error = 0; |
| 464 | vlib_log_main_t *lm = &log_main; |
| 465 | vlib_log_entry_t *e; |
| 466 | int i = last_log_entry (); |
| 467 | int count = lm->count; |
| 468 | |
| 469 | while (count--) |
| 470 | { |
| 471 | e = vec_elt_at_index (lm->entries, i); |
| 472 | vec_free (e->string); |
| 473 | i = (i + 1) % lm->size; |
| 474 | } |
| 475 | |
| 476 | lm->count = 0; |
| 477 | lm->next = 0; |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 478 | vlib_log_info (log_log.class, "log cleared"); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 479 | return error; |
| 480 | } |
| 481 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 482 | VLIB_CLI_COMMAND (cli_clear_log, static) = { |
| 483 | .path = "clear logging", |
| 484 | .short_help = "clear logging", |
| 485 | .function = clear_log, |
| 486 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 487 | |
| 488 | static uword |
| 489 | unformat_vlib_log_level (unformat_input_t * input, va_list * args) |
| 490 | { |
| 491 | vlib_log_level_t *level = va_arg (*args, vlib_log_level_t *); |
| 492 | u8 *level_str = NULL; |
| 493 | uword rv = 1; |
Steven | 526ea3e | 2018-04-25 11:29:00 -0700 | [diff] [blame] | 494 | if (unformat (input, "%s", &level_str)) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 495 | { |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 496 | #define _(uc, lc) \ |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 497 | const char __##uc[] = #lc; \ |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 498 | if (!strcmp ((const char *) level_str, __##uc)) \ |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 499 | { \ |
Damjan Marion | 4d7ad4a | 2020-10-23 21:52:50 +0200 | [diff] [blame] | 500 | *level = VLIB_LOG_LEVEL_##uc; \ |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 501 | rv = 1; \ |
| 502 | goto done; \ |
| 503 | } |
| 504 | foreach_vlib_log_level; |
| 505 | rv = 0; |
| 506 | #undef _ |
| 507 | } |
| 508 | done: |
| 509 | vec_free (level_str); |
| 510 | return rv; |
| 511 | } |
| 512 | |
| 513 | static uword |
| 514 | unformat_vlib_log_class (unformat_input_t * input, va_list * args) |
| 515 | { |
| 516 | vlib_log_class_data_t **class = va_arg (*args, vlib_log_class_data_t **); |
| 517 | uword rv = 0; |
| 518 | u8 *class_str = NULL; |
| 519 | vlib_log_main_t *lm = &log_main; |
| 520 | if (unformat (input, "%v", &class_str)) |
| 521 | { |
| 522 | vlib_log_class_data_t *cdata; |
| 523 | vec_foreach (cdata, lm->classes) |
| 524 | { |
| 525 | if (vec_is_equal (cdata->name, class_str)) |
| 526 | { |
| 527 | *class = cdata; |
| 528 | rv = 1; |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | vec_free (class_str); |
| 534 | return rv; |
| 535 | } |
| 536 | |
| 537 | static clib_error_t * |
| 538 | set_log_class (vlib_main_t * vm, |
| 539 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 540 | { |
| 541 | unformat_input_t _line_input, *line_input = &_line_input; |
| 542 | clib_error_t *rv = NULL; |
| 543 | int rate_limit; |
| 544 | bool set_rate_limit = false; |
| 545 | bool set_level = false; |
| 546 | bool set_syslog_level = false; |
| 547 | vlib_log_level_t level; |
| 548 | vlib_log_level_t syslog_level; |
| 549 | |
| 550 | /* Get a line of input. */ |
| 551 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 552 | return 0; |
| 553 | |
| 554 | vlib_log_class_data_t *class = NULL; |
| 555 | if (!unformat (line_input, "%U", unformat_vlib_log_class, &class)) |
| 556 | { |
| 557 | return clib_error_return (0, "unknown log class `%U'", |
| 558 | format_unformat_error, line_input); |
| 559 | } |
| 560 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 561 | { |
| 562 | if (unformat (line_input, "rate-limit %d", &rate_limit)) |
| 563 | { |
| 564 | set_rate_limit = true; |
| 565 | } |
| 566 | else |
| 567 | if (unformat |
| 568 | (line_input, "level %U", unformat_vlib_log_level, &level)) |
| 569 | { |
| 570 | set_level = true; |
| 571 | } |
| 572 | else |
| 573 | if (unformat |
| 574 | (line_input, "syslog-level %U", unformat_vlib_log_level, |
| 575 | &syslog_level)) |
| 576 | { |
| 577 | set_syslog_level = true; |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | return clib_error_return (0, "unknown input `%U'", |
| 582 | format_unformat_error, line_input); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | if (set_level) |
| 587 | { |
| 588 | vlib_log_subclass_data_t *subclass; |
| 589 | vec_foreach (subclass, class->subclasses) |
| 590 | { |
| 591 | subclass->level = level; |
| 592 | } |
| 593 | } |
| 594 | if (set_syslog_level) |
| 595 | { |
| 596 | vlib_log_subclass_data_t *subclass; |
| 597 | vec_foreach (subclass, class->subclasses) |
| 598 | { |
| 599 | subclass->syslog_level = syslog_level; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | if (set_rate_limit) |
| 603 | { |
| 604 | vlib_log_subclass_data_t *subclass; |
| 605 | vec_foreach (subclass, class->subclasses) |
| 606 | { |
| 607 | subclass->rate_limit = rate_limit; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | return rv; |
| 612 | } |
| 613 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 614 | VLIB_CLI_COMMAND (cli_set_log, static) = { |
| 615 | .path = "set logging class", |
Paul Vinciguerra | 43d8cf6 | 2019-10-30 11:14:58 -0400 | [diff] [blame] | 616 | .short_help = "set logging class <class> [rate-limit <int>] " |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 617 | "[level <level>] [syslog-level <level>]", |
| 618 | .function = set_log_class, |
| 619 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 620 | |
| 621 | static clib_error_t * |
| 622 | set_log_unth_time (vlib_main_t * vm, |
| 623 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 624 | { |
| 625 | unformat_input_t _line_input, *line_input = &_line_input; |
| 626 | clib_error_t *rv = NULL; |
| 627 | int unthrottle_time; |
| 628 | vlib_log_main_t *lm = &log_main; |
| 629 | |
| 630 | /* Get a line of input. */ |
| 631 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 632 | return 0; |
| 633 | |
| 634 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 635 | { |
| 636 | if (unformat (line_input, "%d", &unthrottle_time)) |
| 637 | lm->unthrottle_time = unthrottle_time; |
| 638 | else |
| 639 | return clib_error_return (0, "unknown input `%U'", |
| 640 | format_unformat_error, line_input); |
| 641 | } |
| 642 | |
| 643 | return rv; |
| 644 | } |
| 645 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 646 | VLIB_CLI_COMMAND (cli_set_log_params, static) = { |
| 647 | .path = "set logging unthrottle-time", |
| 648 | .short_help = "set logging unthrottle-time <int>", |
| 649 | .function = set_log_unth_time, |
| 650 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 651 | |
| 652 | static clib_error_t * |
| 653 | set_log_size (vlib_main_t * vm, |
| 654 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 655 | { |
| 656 | unformat_input_t _line_input, *line_input = &_line_input; |
| 657 | clib_error_t *rv = NULL; |
| 658 | int size; |
| 659 | vlib_log_main_t *lm = &log_main; |
| 660 | |
| 661 | /* Get a line of input. */ |
| 662 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 663 | return 0; |
| 664 | |
| 665 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 666 | { |
| 667 | if (unformat (line_input, "%d", &size)) |
| 668 | { |
| 669 | lm->size = size; |
| 670 | vec_validate (lm->entries, lm->size); |
| 671 | } |
| 672 | else |
| 673 | return clib_error_return (0, "unknown input `%U'", |
| 674 | format_unformat_error, line_input); |
| 675 | } |
| 676 | |
| 677 | return rv; |
| 678 | } |
| 679 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 680 | VLIB_CLI_COMMAND (cli_set_log_size, static) = { |
| 681 | .path = "set logging size", |
| 682 | .short_help = "set logging size <int>", |
| 683 | .function = set_log_size, |
| 684 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 685 | |
| 686 | static uword |
| 687 | unformat_vlib_log_subclass (unformat_input_t * input, va_list * args) |
| 688 | { |
| 689 | vlib_log_class_data_t *class = va_arg (*args, vlib_log_class_data_t *); |
| 690 | vlib_log_subclass_data_t **subclass = |
| 691 | va_arg (*args, vlib_log_subclass_data_t **); |
| 692 | uword rv = 0; |
| 693 | u8 *subclass_str = NULL; |
| 694 | if (unformat (input, "%v", &subclass_str)) |
| 695 | { |
| 696 | vlib_log_subclass_data_t *scdata; |
| 697 | vec_foreach (scdata, class->subclasses) |
| 698 | { |
| 699 | if (vec_is_equal (scdata->name, subclass_str)) |
| 700 | { |
| 701 | rv = 1; |
| 702 | *subclass = scdata; |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | vec_free (subclass_str); |
| 708 | return rv; |
| 709 | } |
| 710 | |
| 711 | static clib_error_t * |
| 712 | test_log_class_subclass (vlib_main_t * vm, |
| 713 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 714 | { |
| 715 | unformat_input_t _line_input, *line_input = &_line_input; |
| 716 | /* Get a line of input. */ |
| 717 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 718 | return 0; |
| 719 | |
| 720 | vlib_log_class_data_t *class = NULL; |
| 721 | vlib_log_subclass_data_t *subclass = NULL; |
| 722 | vlib_log_level_t level; |
| 723 | if (unformat (line_input, "%U", unformat_vlib_log_level, &level)) |
| 724 | { |
| 725 | if (unformat (line_input, "%U", unformat_vlib_log_class, &class)) |
| 726 | { |
| 727 | if (unformat |
| 728 | (line_input, "%U", unformat_vlib_log_subclass, class, |
| 729 | &subclass)) |
| 730 | { |
| 731 | vlib_log (level, |
| 732 | (class->index << 16) | (subclass->index), "%U", |
| 733 | format_unformat_input, line_input); |
| 734 | } |
| 735 | else |
| 736 | { |
| 737 | return clib_error_return (0, |
| 738 | "unknown log subclass near beginning of `%U'", |
| 739 | format_unformat_error, line_input); |
| 740 | } |
| 741 | } |
| 742 | else |
| 743 | { |
| 744 | return clib_error_return (0, |
| 745 | "unknown log class near beginning of `%U'", |
| 746 | format_unformat_error, line_input); |
| 747 | } |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | return clib_error_return (0, "unknown log level near beginning of `%U'", |
| 752 | format_unformat_error, line_input); |
| 753 | } |
| 754 | return 0; |
| 755 | } |
| 756 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 757 | VLIB_CLI_COMMAND (cli_test_log, static) = { |
| 758 | .path = "test log", |
Su Wang | 34321b3 | 2019-01-11 12:46:05 -0500 | [diff] [blame] | 759 | .short_help = "test log <level> <class> <subclass> <message>", |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 760 | .function = test_log_class_subclass, |
| 761 | }; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 762 | |
| 763 | static clib_error_t * |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 764 | log_config_class (vlib_main_t * vm, char *name, unformat_input_t * input) |
| 765 | { |
| 766 | vlib_log_main_t *lm = &log_main; |
| 767 | vlib_log_class_config_t *cc, tmp; |
| 768 | uword *p; |
| 769 | |
| 770 | if (lm->config_index_by_name == 0) |
| 771 | lm->config_index_by_name = hash_create_string (0, sizeof (uword)); |
| 772 | |
| 773 | p = hash_get_mem (lm->config_index_by_name, name); |
| 774 | |
| 775 | if (p) |
| 776 | return clib_error_return (0, "logging class '%s' already configured", |
| 777 | name); |
| 778 | |
| 779 | clib_memset_u8 (&tmp, 0xff, sizeof (vlib_log_class_config_t)); |
| 780 | |
| 781 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 782 | { |
| 783 | if (unformat (input, "level %U", unformat_vlib_log_level, &tmp.level)) |
| 784 | ; |
| 785 | else if (unformat (input, "syslog-level %U", unformat_vlib_log_level, |
| 786 | &tmp.syslog_level)) |
| 787 | ; |
| 788 | else if (unformat (input, "rate-limit %u", &tmp.rate_limit)) |
| 789 | ; |
| 790 | else |
| 791 | return clib_error_return (0, "unknown input '%U'", |
| 792 | format_unformat_error, input); |
| 793 | } |
| 794 | |
| 795 | vec_add2 (lm->configs, cc, 1); |
| 796 | clib_memcpy_fast (cc, &tmp, sizeof (vlib_log_class_config_t)); |
| 797 | cc->name = name; |
| 798 | hash_set_mem (lm->config_index_by_name, name, cc - lm->configs); |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static clib_error_t * |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 803 | log_config (vlib_main_t * vm, unformat_input_t * input) |
| 804 | { |
| 805 | vlib_log_main_t *lm = &log_main; |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 806 | unformat_input_t sub_input; |
| 807 | u8 *class = 0; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 808 | |
| 809 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 810 | { |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 811 | if (unformat (input, "size %d", &lm->size)) |
| 812 | vec_validate (lm->entries, lm->size); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 813 | else if (unformat (input, "unthrottle-time %d", &lm->unthrottle_time)) |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 814 | ; |
| 815 | else if (unformat (input, "default-log-level %U", |
| 816 | unformat_vlib_log_level, &lm->default_log_level)) |
| 817 | ; |
| 818 | else if (unformat (input, "default-syslog-log-level %U", |
| 819 | unformat_vlib_log_level, |
| 820 | &lm->default_syslog_log_level)) |
| 821 | ; |
Dave Barach | bc867c3 | 2020-11-25 10:07:09 -0500 | [diff] [blame] | 822 | else if (unformat (input, "add-to-elog")) |
| 823 | lm->add_to_elog = 1; |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame] | 824 | else if (unformat (input, "class %s %U", &class, |
| 825 | unformat_vlib_cli_sub_input, &sub_input)) |
| 826 | { |
| 827 | clib_error_t *err; |
| 828 | err = log_config_class (vm, (char *) class, &sub_input); |
| 829 | class = 0; |
| 830 | unformat_free (&sub_input); |
| 831 | if (err) |
| 832 | return err; |
| 833 | } |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 834 | else |
| 835 | { |
| 836 | return unformat_parse_error (input); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | VLIB_EARLY_CONFIG_FUNCTION (log_config, "logging"); |
| 844 | |
| 845 | /* |
| 846 | * fd.io coding-style-patch-verification: ON |
| 847 | * |
| 848 | * Local Variables: |
| 849 | * eval: (c-set-style "gnu") |
| 850 | * End: |
| 851 | */ |