bslsink.h (3905B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 6 * 7 * Broadcom System Log Sinks 8 * 9 * The BSL sink structure control how log messages are presented on a 10 * particular sink. A sink can be a console, a file, or some other 11 * output devices. 12 * 13 * The sink will prefix each log message according to a preconfigured 14 * setting configured via a printf-like format string. Please consult 15 * the format_prefix function in bslsink.c for a complete list of 16 * format specifiers. 17 * 18 * A number of options can be configured to control the sink behavior: 19 * 20 * BSLSINK_OPT_NO_ECHO 21 * This option suppresses all log messages from the ECHO source 22 * (bslSourceEcho). It is used for console sinks to avoid duplicating 23 * the console echo of CLI input functions such as readline. The CLI 24 * will log the input string to allow it to be captured in a log file. 25 * 26 * BSLSINK_OPT_SHELL_PREFIX 27 * Normally the prefix string is suppressed for log messages from the 28 * SHELL sources (bslSourceShell and bslSourceEcho). If this option 29 * is set, the prefix string (if configured) will also be shown for 30 * SHELL output. 31 */ 32 33 #ifndef _DIAG_BSLSINK_H 34 #define _DIAG_BSLSINK_H 35 36 #include <stdarg.h> 37 #include <shared/bslext.h> 38 #include <bcm/types.h> 39 40 #define BSLSINK_SINK_NAME_MAX 32 41 #define BSLSINK_PREFIX_FORMAT_MAX 32 42 43 #ifndef BSLSINK_PREFIX_MAX 44 #define BSLSINK_PREFIX_MAX 144 45 #endif 46 47 #define BSLSINK_MAX_NUM_UNITS (BCM_UNITS_MAX + 1) 48 #define BSLSINK_MAX_NUM_PORTS BCM_PBMP_PORT_MAX 49 50 /* Pseudo-unit to allow separate control of BSL_UNIT_UNKNOWN messages */ 51 #define BSLSINK_UNIT_UNKNOWN (BSLSINK_MAX_NUM_UNITS - 1) 52 53 /* Sink options */ 54 #define BSLSINK_OPT_NO_ECHO (1L << 0) 55 #define BSLSINK_OPT_SHELL_PREFIX (1L << 1) 56 57 typedef struct bslsink_severity_range_s { 58 bsl_severity_t min; 59 bsl_severity_t max; 60 } bslsink_severity_range_t; 61 62 typedef struct bslsink_sink_s { 63 64 /* Next sink */ 65 struct bslsink_sink_s *next; 66 67 /* Sink name */ 68 char name[BSLSINK_SINK_NAME_MAX]; 69 70 /* Unique ID for retrieval and removal */ 71 int sink_id; 72 73 /* Options for controlling sink behavior (BSLSINK_OPT_xxx */ 74 uint32 options; 75 76 /* Low-level output function */ 77 int (*vfprintf)(void *, const char *, va_list); 78 79 /* Optional function for custom filtering */ 80 int (*check)(bsl_meta_t *); 81 82 /* Optional function for cleaning up dynamic resources */ 83 int (*cleanup)(struct bslsink_sink_s *); 84 85 /* Opaque file handle */ 86 void *file; 87 88 /* Messages within this severity range will be printed */ 89 bslsink_severity_range_t enable_range; 90 91 /* Messages within this severity range will be prefixed */ 92 bslsink_severity_range_t prefix_range; 93 94 /* Messages with these units will be printed (use -1 to skip check) */ 95 SHR_BITDCLNAME(units, BSLSINK_MAX_NUM_UNITS); 96 97 /* Messages with these ports will be printed (use -1 to skip check) */ 98 SHR_BITDCLNAME(ports, BSLSINK_MAX_NUM_PORTS); 99 100 /* Messages with this parameter will be printed (-1 to ignore) */ 101 int xtra; 102 103 /* Skip this many characters of the BSL_FILE path */ 104 int path_offset; 105 106 /* Prefix configuration */ 107 char prefix_format[BSLSINK_PREFIX_FORMAT_MAX+1]; 108 109 } bslsink_sink_t; 110 111 extern int 112 bslsink_out(bslsink_sink_t *sink, bsl_meta_t *meta, 113 const char *format, va_list args); 114 115 extern void 116 bslsink_sink_t_init(bslsink_sink_t *sink); 117 118 extern int 119 bslsink_sink_cleanup(bslsink_sink_t *sink); 120 121 extern int 122 bslsink_sink_add(bslsink_sink_t *new_sink); 123 124 extern bslsink_sink_t * 125 bslsink_sink_find(const char *name); 126 127 extern bslsink_sink_t * 128 bslsink_sink_find_by_id(int sink_id); 129 130 extern int 131 bslsink_cleanup(void); 132 133 extern int 134 bslsink_init(void); 135 136 #endif /* !_DIAG_BSLSINK_H */