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 | #ifndef included_vlib_log_h |
| 17 | #define included_vlib_log_h |
| 18 | |
| 19 | #include <vppinfra/types.h> |
| 20 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 21 | #define foreach_vlib_log_level \ |
| 22 | _(0, EMERG, emerg) \ |
| 23 | _(1, ALERT, alert) \ |
| 24 | _(2, CRIT, crit) \ |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 25 | _(3, ERR, error) \ |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 26 | _(4, WARNING, warn) \ |
| 27 | _(5, NOTICE, notice) \ |
| 28 | _(6, INFO, info) \ |
Damjan Marion | e78fab8 | 2018-04-18 17:03:28 +0200 | [diff] [blame] | 29 | _(7, DEBUG, debug) \ |
| 30 | _(8, DISABLED, disabled) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 31 | |
| 32 | typedef enum |
| 33 | { |
| 34 | #define _(n,uc,lc) VLIB_LOG_LEVEL_##uc = n, |
| 35 | foreach_vlib_log_level |
| 36 | #undef _ |
| 37 | } vlib_log_level_t; |
| 38 | |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 39 | typedef struct |
| 40 | { |
| 41 | vlib_log_level_t level; |
| 42 | vlib_log_class_t class; |
| 43 | f64 timestamp; |
| 44 | u8 *string; |
| 45 | } vlib_log_entry_t; |
| 46 | |
| 47 | typedef struct |
| 48 | { |
| 49 | u32 index; |
| 50 | u8 *name; |
| 51 | // level of log messages kept for this subclass |
| 52 | vlib_log_level_t level; |
| 53 | // level of log messages sent to syslog for this subclass |
| 54 | vlib_log_level_t syslog_level; |
| 55 | // flag saying whether this subclass is logged to syslog |
| 56 | f64 last_event_timestamp; |
| 57 | int last_sec_count; |
| 58 | int is_throttling; |
| 59 | int rate_limit; |
| 60 | } vlib_log_subclass_data_t; |
| 61 | |
| 62 | typedef struct |
| 63 | { |
| 64 | u32 index; |
| 65 | u8 *name; |
| 66 | vlib_log_subclass_data_t *subclasses; |
| 67 | } vlib_log_class_data_t; |
| 68 | |
| 69 | typedef struct |
| 70 | { |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame^] | 71 | vlib_log_level_t level; |
| 72 | vlib_log_level_t syslog_level; |
| 73 | int rate_limit; |
| 74 | char *name; |
| 75 | } vlib_log_class_config_t; |
| 76 | |
| 77 | typedef struct |
| 78 | { |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 79 | vlib_log_entry_t *entries; |
| 80 | vlib_log_class_data_t *classes; |
| 81 | int size, next, count; |
| 82 | |
| 83 | /* our own log class */ |
| 84 | vlib_log_class_t log_class; |
| 85 | |
| 86 | int default_rate_limit; |
| 87 | int default_log_level; |
| 88 | int default_syslog_log_level; |
| 89 | int unthrottle_time; |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 90 | u32 max_class_name_length; |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 91 | |
| 92 | /* time zero */ |
| 93 | struct timeval time_zero_timeval; |
| 94 | f64 time_zero; |
| 95 | |
Damjan Marion | 055e640 | 2020-10-21 19:43:36 +0200 | [diff] [blame^] | 96 | /* config */ |
| 97 | vlib_log_class_config_t *configs; |
| 98 | uword *config_index_by_name; |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 99 | } vlib_log_main_t; |
| 100 | |
| 101 | extern vlib_log_main_t log_main; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 102 | |
| 103 | vlib_log_class_t vlib_log_register_class (char *vlass, char *subclass); |
Dave Barach | 8dc954a | 2020-02-05 17:31:09 -0500 | [diff] [blame] | 104 | vlib_log_class_t |
| 105 | vlib_log_register_class_rate_limit (char *class, char *subclass, |
| 106 | u32 rate_limit); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 107 | void vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt, |
| 108 | ...); |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 109 | int last_log_entry (); |
| 110 | u8 *format_vlib_log_class (u8 * s, va_list * args); |
Damjan Marion | 06d8226 | 2020-10-21 12:43:40 +0200 | [diff] [blame] | 111 | u8 *format_vlib_log_level (u8 * s, va_list * args); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 112 | |
| 113 | #define vlib_log_emerg(...) vlib_log(VLIB_LOG_LEVEL_EMERG, __VA_ARGS__) |
| 114 | #define vlib_log_alert(...) vlib_log(VLIB_LOG_LEVEL_ALERT, __VA_ARGS__) |
| 115 | #define vlib_log_crit(...) vlib_log(VLIB_LOG_LEVEL_CRIT, __VA_ARGS__) |
| 116 | #define vlib_log_err(...) vlib_log(VLIB_LOG_LEVEL_ERR, __VA_ARGS__) |
Mohsin Kazmi | ed984e0 | 2018-05-17 16:47:08 +0200 | [diff] [blame] | 117 | #define vlib_log_warn(...) vlib_log(VLIB_LOG_LEVEL_WARNING, __VA_ARGS__) |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 118 | #define vlib_log_notice(...) vlib_log(VLIB_LOG_LEVEL_NOTICE, __VA_ARGS__) |
| 119 | #define vlib_log_info(...) vlib_log(VLIB_LOG_LEVEL_INFO, __VA_ARGS__) |
| 120 | #define vlib_log_debug(...) vlib_log(VLIB_LOG_LEVEL_DEBUG, __VA_ARGS__) |
| 121 | |
| 122 | #endif /* included_vlib_log_h */ |
| 123 | |
| 124 | /* |
| 125 | * fd.io coding-style-patch-verification: ON |
| 126 | * |
| 127 | * Local Variables: |
| 128 | * eval: (c-set-style "gnu") |
| 129 | * End: |
| 130 | */ |