diff options
author | Damjan Marion <damarion@cisco.com> | 2020-10-23 21:52:50 +0200 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2020-10-26 10:45:49 +0000 |
commit | 4d7ad4a6cc08e316d78de5ac7ce3ead4e9bfcb66 (patch) | |
tree | ef4158573a6aea024be7260ef7ebe4f12dfc64a8 /src/vlib/log.h | |
parent | 340b10a38ed84600ed3336657ef3a104d9ebe877 (diff) |
vlib: add VLIB_REGISTER_LOG_CLASS macro
Type: improvement
Change-Id: Iafcaeb88fa3569e042fb9cb270cf062b145416e2
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/log.h')
-rw-r--r-- | src/vlib/log.h | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/src/vlib/log.h b/src/vlib/log.h index 4cceb4b962a..75bdceb806e 100644 --- a/src/vlib/log.h +++ b/src/vlib/log.h @@ -18,22 +18,24 @@ #include <vppinfra/types.h> -#define foreach_vlib_log_level \ - _(0, EMERG, emerg) \ - _(1, ALERT, alert) \ - _(2, CRIT, crit) \ - _(3, ERR, error) \ - _(4, WARNING, warn) \ - _(5, NOTICE, notice) \ - _(6, INFO, info) \ - _(7, DEBUG, debug) \ - _(8, DISABLED, disabled) +#define foreach_vlib_log_level \ + _(EMERG, emerg) \ + _(ALERT, alert) \ + _(CRIT, crit) \ + _(ERR, error) \ + _(WARNING, warn) \ + _(NOTICE, notice) \ + _(INFO, info) \ + _(DEBUG, debug) \ + _(DISABLED, disabled) typedef enum { -#define _(n,uc,lc) VLIB_LOG_LEVEL_##uc = n, + VLIB_LOG_LEVEL_UNKNOWN = 0, +#define _(uc,lc) VLIB_LOG_LEVEL_##uc, foreach_vlib_log_level #undef _ + VLIB_LOG_N_LEVELS, } vlib_log_level_t; typedef struct @@ -74,15 +76,25 @@ typedef struct char *name; } vlib_log_class_config_t; + +typedef struct vlib_log_registration +{ + char *class_name; + char *subclass_name; + vlib_log_class_t class; + vlib_log_level_t default_level; + vlib_log_level_t default_syslog_level; + + /* next */ + struct vlib_log_registration *next; +} vlib_log_class_registration_t; + typedef struct { vlib_log_entry_t *entries; vlib_log_class_data_t *classes; int size, next, count; - /* our own log class */ - vlib_log_class_t log_class; - int default_rate_limit; int default_log_level; int default_syslog_log_level; @@ -96,6 +108,9 @@ typedef struct /* config */ vlib_log_class_config_t *configs; uword *config_index_by_name; + + /* registrations */ + vlib_log_class_registration_t *registrations; } vlib_log_main_t; extern vlib_log_main_t log_main; @@ -119,6 +134,18 @@ u8 *format_vlib_log_level (u8 * s, va_list * args); #define vlib_log_info(...) vlib_log(VLIB_LOG_LEVEL_INFO, __VA_ARGS__) #define vlib_log_debug(...) vlib_log(VLIB_LOG_LEVEL_DEBUG, __VA_ARGS__) +#define VLIB_REGISTER_LOG_CLASS(x,...) \ +__VA_ARGS__ vlib_log_class_registration_t x; \ +static void __clib_constructor \ +__vlib_add_log_registration_##x (void) \ + { \ + vlib_log_main_t * lm = &log_main; \ + x.next = lm->registrations; \ + x.class = ~0; \ + lm->registrations = &x; \ + } \ +__VA_ARGS__ vlib_log_class_registration_t x + #endif /* included_vlib_log_h */ /* |