Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 2 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 3 | /*! \defgroup logging Osmocom logging framework |
| 4 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 5 | * \file logging.h */ |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 6 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | #include <stdint.h> |
Christoph Fritz | ab7c9c7 | 2011-09-01 16:22:17 +0200 | [diff] [blame] | 9 | #include <stdarg.h> |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Max | aa1bc01 | 2017-01-13 11:01:12 +0100 | [diff] [blame] | 11 | #include <osmocom/core/defs.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 12 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 13 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 14 | /*! Maximum number of logging contexts */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 15 | #define LOG_MAX_CTX 8 |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 16 | /*! Maximum number of logging filters */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 17 | #define LOG_MAX_FILTERS 8 |
| 18 | |
Kévin Redon | d1e220f | 2019-06-13 13:41:00 +0200 | [diff] [blame] | 19 | #ifndef DEBUG |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 20 | #define DEBUG |
Kévin Redon | d1e220f | 2019-06-13 13:41:00 +0200 | [diff] [blame] | 21 | #endif |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 22 | |
| 23 | #ifdef DEBUG |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 24 | /*! Log a debug message through the Osmocom logging framework |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 25 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 26 | * \param[in] fmt format string |
| 27 | * \param[in] args variable argument list |
| 28 | */ |
Max | aa1bc01 | 2017-01-13 11:01:12 +0100 | [diff] [blame] | 29 | #define DEBUGP(ss, fmt, args...) LOGP(ss, LOGL_DEBUG, fmt, ##args) |
| 30 | #define DEBUGPC(ss, fmt, args...) LOGPC(ss, LOGL_DEBUG, fmt, ##args) |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 31 | #else |
| 32 | #define DEBUGP(xss, fmt, args...) |
| 33 | #define DEBUGPC(ss, fmt, args...) |
| 34 | #endif |
| 35 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 37 | void osmo_vlogp(int subsys, int level, const char *file, int line, |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 38 | int cont, const char *format, va_list ap); |
| 39 | |
Max | aa1bc01 | 2017-01-13 11:01:12 +0100 | [diff] [blame] | 40 | void logp(int subsys, const char *file, int line, int cont, const char *format, ...) OSMO_DEPRECATED("Use DEBUGP* macros instead"); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 41 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 42 | /*! Log a new message through the Osmocom logging framework |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 43 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 44 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
| 45 | * \param[in] fmt format string |
| 46 | * \param[in] args variable argument list |
| 47 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 48 | #define LOGP(ss, level, fmt, args...) \ |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 49 | LOGPSRC(ss, level, NULL, 0, fmt, ## args) |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 50 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 51 | /*! Continue a log message through the Osmocom logging framework |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 52 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 53 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
| 54 | * \param[in] fmt format string |
| 55 | * \param[in] args variable argument list |
| 56 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 57 | #define LOGPC(ss, level, fmt, args...) \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 58 | do { \ |
| 59 | if (log_check_level(ss, level)) \ |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 60 | logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 61 | } while(0) |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 62 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 63 | /*! Log through the Osmocom logging framework with explicit source. |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 64 | * If caller_file is passed as NULL, __FILE__ and __LINE__ are used |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 65 | * instead of caller_file and caller_line (so that this macro here defines |
| 66 | * both cases in the same place, and to catch cases where callers fail to pass |
| 67 | * a non-null filename string). |
| 68 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 69 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 70 | * \param[in] caller_file caller's source file string (e.g. __FILE__) |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 71 | * \param[in] caller_line caller's source line nr (e.g. __LINE__) |
| 72 | * \param[in] fmt format string |
| 73 | * \param[in] args variable argument list |
| 74 | */ |
| 75 | #define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \ |
Holger Hans Peter Freyther | 37a8340 | 2017-11-29 11:46:39 +0800 | [diff] [blame] | 76 | LOGPSRCC(ss, level, caller_file, caller_line, 0, fmt, ##args) |
| 77 | |
| 78 | /*! Log through the Osmocom logging framework with explicit source. |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 79 | * If caller_file is passed as NULL, __FILE__ and __LINE__ are used |
Holger Hans Peter Freyther | 37a8340 | 2017-11-29 11:46:39 +0800 | [diff] [blame] | 80 | * instead of caller_file and caller_line (so that this macro here defines |
| 81 | * both cases in the same place, and to catch cases where callers fail to pass |
| 82 | * a non-null filename string). |
| 83 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 84 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 85 | * \param[in] caller_file caller's source file string (e.g. __FILE__) |
Holger Hans Peter Freyther | 37a8340 | 2017-11-29 11:46:39 +0800 | [diff] [blame] | 86 | * \param[in] caller_line caller's source line nr (e.g. __LINE__) |
| 87 | * \param[in] cont continuation (1) or new line (0) |
| 88 | * \param[in] fmt format string |
| 89 | * \param[in] args variable argument list |
| 90 | */ |
| 91 | #define LOGPSRCC(ss, level, caller_file, caller_line, cont, fmt, args...) \ |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 92 | do { \ |
| 93 | if (log_check_level(ss, level)) {\ |
| 94 | if (caller_file) \ |
Holger Hans Peter Freyther | 37a8340 | 2017-11-29 11:46:39 +0800 | [diff] [blame] | 95 | logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \ |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 96 | else \ |
Neels Hofmeyr | 983dcb9 | 2018-08-20 12:33:22 +0200 | [diff] [blame] | 97 | logp2(ss, level, __FILE__, __LINE__, cont, fmt, ##args); \ |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 98 | }\ |
| 99 | } while(0) |
| 100 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 101 | /*! different log levels */ |
| 102 | #define LOGL_DEBUG 1 /*!< debugging information */ |
| 103 | #define LOGL_INFO 3 /*!< general information */ |
| 104 | #define LOGL_NOTICE 5 /*!< abnormal/unexpected condition */ |
| 105 | #define LOGL_ERROR 7 /*!< error condition, requires user action */ |
| 106 | #define LOGL_FATAL 8 /*!< fatal, program aborted */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 107 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 108 | /* logging levels defined by the library itself */ |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 109 | #define DLGLOBAL -1 /*!< global logging */ |
| 110 | #define DLLAPD -2 /*!< LAPD implementation */ |
| 111 | #define DLINP -3 /*!< (A-bis) Input sub-system */ |
| 112 | #define DLMUX -4 /*!< Osmocom Multiplex (Osmux) */ |
| 113 | #define DLMI -5 /*!< ISDN-layer below input sub-system */ |
| 114 | #define DLMIB -6 /*!< ISDN layer B-channel */ |
| 115 | #define DLSMS -7 /*!< SMS sub-system */ |
| 116 | #define DLCTRL -8 /*!< Control Interface */ |
| 117 | #define DLGTP -9 /*!< GTP (GPRS Tunneling Protocol */ |
| 118 | #define DLSTATS -10 /*!< Statistics */ |
Neels Hofmeyr | 9795cf1 | 2016-12-10 17:01:06 +0100 | [diff] [blame] | 119 | #define DLGSUP -11 /*!< Generic Subscriber Update Protocol */ |
Harald Welte | c0f0007 | 2016-04-27 18:32:35 +0200 | [diff] [blame] | 120 | #define DLOAP -12 /*!< Osmocom Authentication Protocol */ |
Harald Welte | 62d3296 | 2017-04-03 19:37:11 +0200 | [diff] [blame] | 121 | #define DLSS7 -13 /*!< Osmocom SS7 */ |
| 122 | #define DLSCCP -14 /*!< Osmocom SCCP */ |
| 123 | #define DLSUA -15 /*!< Osmocom SUA */ |
| 124 | #define DLM3UA -16 /*!< Osmocom M3UA */ |
Neels Hofmeyr | a7ccf61 | 2017-07-11 18:43:09 +0200 | [diff] [blame] | 125 | #define DLMGCP -17 /*!< Osmocom MGCP */ |
Pau Espin Pedrol | 8fd8557 | 2018-02-27 19:43:10 +0100 | [diff] [blame] | 126 | #define DLJIBUF -18 /*!< Osmocom Jitter Buffer */ |
Harald Welte | b99ed7f | 2018-08-13 20:54:44 +0200 | [diff] [blame] | 127 | #define DLRSPRO -19 /*!< Osmocom Remote SIM Protocol */ |
| 128 | #define OSMO_NUM_DLIB 19 /*!< Number of logging sub-systems in libraries */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 129 | |
Neels Hofmeyr | fc47b03 | 2017-06-20 04:29:38 +0200 | [diff] [blame] | 130 | /*! Configuration of single log category / sub-system */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 131 | struct log_category { |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 132 | uint8_t loglevel; /*!< configured log-level */ |
| 133 | uint8_t enabled; /*!< is logging enabled? */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 134 | }; |
| 135 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 136 | /*! Information regarding one logging category */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 137 | struct log_info_cat { |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 138 | const char *name; /*!< name of category */ |
| 139 | const char *color; /*!< color string for cateyory */ |
| 140 | const char *description; /*!< description text */ |
| 141 | uint8_t loglevel; /*!< currently selected log-level */ |
| 142 | uint8_t enabled; /*!< is this category enabled or not */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 143 | }; |
| 144 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 145 | /*! Log context information, passed to filter */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 146 | struct log_context { |
| 147 | void *ctx[LOG_MAX_CTX+1]; |
| 148 | }; |
| 149 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 150 | /*! Indexes to indicate the object currently acted upon. |
Neels Hofmeyr | 492e180 | 2017-02-23 17:45:26 +0100 | [diff] [blame] | 151 | * Array indexes for the global \a log_context array. */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 152 | enum log_ctx_index { |
| 153 | LOG_CTX_GB_NSVC, |
| 154 | LOG_CTX_GB_BVC, |
| 155 | LOG_CTX_BSC_SUBSCR, |
| 156 | LOG_CTX_VLR_SUBSCR, |
| 157 | _LOG_CTX_COUNT |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 160 | /*! Indexes to indicate objects that should be logged. |
Neels Hofmeyr | 492e180 | 2017-02-23 17:45:26 +0100 | [diff] [blame] | 161 | * Array indexes to log_target->filter_data and bit indexes for |
| 162 | * log_target->filter_map. */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 163 | enum log_filter_index { |
| 164 | LOG_FLT_ALL, |
| 165 | LOG_FLT_GB_NSVC, |
| 166 | LOG_FLT_GB_BVC, |
| 167 | LOG_FLT_BSC_SUBSCR, |
| 168 | LOG_FLT_VLR_SUBSCR, |
| 169 | _LOG_FLT_COUNT |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 172 | /*! Compatibility with older libosmocore versions */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 173 | #define LOG_FILTER_ALL (1<<LOG_FLT_ALL) |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 174 | /*! Compatibility with older libosmocore versions */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 175 | #define GPRS_CTX_NSVC LOG_CTX_GB_NSVC |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 176 | /*! Compatibility with older libosmocore versions */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 177 | #define GPRS_CTX_BVC LOG_CTX_GB_BVC |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 178 | /*! Indexes to indicate the object currently acted upon. |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 179 | * Array indexes for the global \a log_context array. */ |
Neels Hofmeyr | 0d6420b | 2017-02-23 17:34:35 +0100 | [diff] [blame] | 180 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 181 | struct log_target; |
| 182 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 183 | /*! Log filter function */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 184 | typedef int log_filter(const struct log_context *ctx, |
| 185 | struct log_target *target); |
| 186 | |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 187 | struct log_info; |
| 188 | struct vty; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 189 | struct gsmtap_inst; |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 190 | |
| 191 | typedef void log_print_filters(struct vty *vty, |
| 192 | const struct log_info *info, |
| 193 | const struct log_target *tgt); |
| 194 | |
| 195 | typedef void log_save_filters(struct vty *vty, |
| 196 | const struct log_info *info, |
| 197 | const struct log_target *tgt); |
| 198 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 199 | /*! Logging configuration, passed to \ref log_init */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 200 | struct log_info { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 201 | /* filter callback function */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 202 | log_filter *filter_fn; |
| 203 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 204 | /*! per-category information */ |
Holger Hans Peter Freyther | 06f6455 | 2012-09-11 10:31:29 +0200 | [diff] [blame] | 205 | const struct log_info_cat *cat; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 206 | /*! total number of categories */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 207 | unsigned int num_cat; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 208 | /*! total number of user categories (not library) */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 209 | unsigned int num_cat_user; |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 210 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 211 | /*! filter saving function */ |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 212 | log_save_filters *save_fn; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 213 | /*! filter saving function */ |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 214 | log_print_filters *print_fn; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 215 | }; |
| 216 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 217 | /*! Type of logging target */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 218 | enum log_target_type { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 219 | LOG_TGT_TYPE_VTY, /*!< VTY logging */ |
| 220 | LOG_TGT_TYPE_SYSLOG, /*!< syslog based logging */ |
| 221 | LOG_TGT_TYPE_FILE, /*!< text file logging */ |
| 222 | LOG_TGT_TYPE_STDERR, /*!< stderr logging */ |
| 223 | LOG_TGT_TYPE_STRRB, /*!< osmo_strrb-backed logging */ |
| 224 | LOG_TGT_TYPE_GSMTAP, /*!< GSMTAP network logging */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 227 | /*! Whether/how to log the source filename (and line number). */ |
| 228 | enum log_filename_type { |
| 229 | LOG_FILENAME_NONE, |
| 230 | LOG_FILENAME_PATH, |
Neels Hofmeyr | 0e2a943 | 2018-01-16 02:49:48 +0100 | [diff] [blame] | 231 | LOG_FILENAME_BASENAME, |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 234 | /*! Where on a log line source file and line should be logged. */ |
| 235 | enum log_filename_pos { |
| 236 | LOG_FILENAME_POS_HEADER_END, |
| 237 | LOG_FILENAME_POS_LINE_END, |
| 238 | }; |
| 239 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 240 | /*! structure representing a logging target */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 241 | struct log_target { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 242 | struct llist_head entry; /*!< linked list */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 243 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 244 | /*! Internal data for filtering */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 245 | int filter_map; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 246 | /*! Internal data for filtering */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 247 | void *filter_data[LOG_MAX_FILTERS+1]; |
| 248 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 249 | /*! logging categories */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 250 | struct log_category *categories; |
| 251 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 252 | /*! global log level */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 253 | uint8_t loglevel; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 254 | /*! should color be used when printing log messages? */ |
Harald Welte | 87dbca1 | 2011-07-16 11:57:53 +0200 | [diff] [blame] | 255 | unsigned int use_color:1; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 256 | /*! should log messages be prefixed with a timestamp? */ |
Harald Welte | 87dbca1 | 2011-07-16 11:57:53 +0200 | [diff] [blame] | 257 | unsigned int print_timestamp:1; |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 258 | /*! DEPRECATED: use print_filename2 instead. */ |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 259 | unsigned int print_filename:1; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 260 | /*! should log messages be prefixed with a category name? */ |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 261 | unsigned int print_category:1; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 262 | /*! should log messages be prefixed with an extended timestamp? */ |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 263 | unsigned int print_ext_timestamp:1; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 264 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 265 | /*! the type of this log taget */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 266 | enum log_target_type type; |
| 267 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 268 | union { |
| 269 | struct { |
| 270 | FILE *out; |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 271 | const char *fname; |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 272 | } tgt_file; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 273 | |
| 274 | struct { |
| 275 | int priority; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 276 | int facility; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 277 | } tgt_syslog; |
| 278 | |
| 279 | struct { |
| 280 | void *vty; |
| 281 | } tgt_vty; |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 282 | |
| 283 | struct { |
| 284 | void *rb; |
| 285 | } tgt_rb; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 286 | |
| 287 | struct { |
| 288 | struct gsmtap_inst *gsmtap_inst; |
| 289 | const char *ident; |
| 290 | const char *hostname; |
| 291 | } tgt_gsmtap; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 292 | }; |
| 293 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 294 | /*! call-back function to be called when the logging framework |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 295 | * wants to log a fully formatted string |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 296 | * \param[in] target logging target |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 297 | * \param[in] level log level of currnet message |
| 298 | * \param[in] string the string that is to be written to the log |
| 299 | */ |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 300 | void (*output) (struct log_target *target, unsigned int level, |
| 301 | const char *string); |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 302 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 303 | /*! alternative call-back function to which the logging |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 304 | * framework passes the unfortmatted input arguments, |
| 305 | * i.e. bypassing the internal string formatter |
| 306 | * \param[in] target logging target |
| 307 | * \param[in] subsys logging sub-system |
| 308 | * \param[in] level logging level |
| 309 | * \param[in] file soure code file name |
| 310 | * \param[in] line source code file line number |
| 311 | * \param[in] cont continuation of previous statement? |
| 312 | * \param[in] format format string |
| 313 | * \param[in] ap vararg list of printf arguments |
| 314 | */ |
| 315 | void (*raw_output)(struct log_target *target, int subsys, |
| 316 | unsigned int level, const char *file, int line, |
| 317 | int cont, const char *format, va_list ap); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 318 | |
| 319 | /* Should the log level be printed? */ |
| 320 | bool print_level; |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 321 | /* Should we print the subsys in hex like '<000b>'? */ |
| 322 | bool print_category_hex; |
| 323 | /* Should we print the source file and line, and in which way? */ |
| 324 | enum log_filename_type print_filename2; |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 325 | /* Where on a log line to put the source file info. */ |
| 326 | enum log_filename_pos print_filename_pos; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | /* use the above macros */ |
Andreas Eversberg | 2d6563b | 2012-07-10 13:10:15 +0200 | [diff] [blame] | 330 | void logp2(int subsys, unsigned int level, const char *file, |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 331 | int line, int cont, const char *format, ...) |
| 332 | __attribute__ ((format (printf, 6, 7))); |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 333 | int log_init(const struct log_info *inf, void *talloc_ctx); |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 334 | void log_fini(void); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 335 | int log_check_level(int subsys, unsigned int level); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 336 | |
| 337 | /* context management */ |
| 338 | void log_reset_context(void); |
| 339 | int log_set_context(uint8_t ctx, void *value); |
| 340 | |
| 341 | /* filter on the targets */ |
| 342 | void log_set_all_filter(struct log_target *target, int); |
| 343 | |
| 344 | void log_set_use_color(struct log_target *target, int); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 345 | void log_set_print_extended_timestamp(struct log_target *target, int); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 346 | void log_set_print_timestamp(struct log_target *target, int); |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 347 | void log_set_print_filename(struct log_target *target, int); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 348 | void log_set_print_filename2(struct log_target *target, enum log_filename_type lft); |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 349 | void log_set_print_filename_pos(struct log_target *target, enum log_filename_pos pos); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 350 | void log_set_print_category(struct log_target *target, int); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 351 | void log_set_print_category_hex(struct log_target *target, int); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 352 | void log_set_print_level(struct log_target *target, int); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 353 | void log_set_log_level(struct log_target *target, int log_level); |
| 354 | void log_parse_category_mask(struct log_target *target, const char* mask); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 355 | const char* log_category_name(int subsys); |
Max | 15b6d41 | 2017-07-06 16:57:15 +0200 | [diff] [blame] | 356 | int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE; |
| 357 | const char *log_level_str(unsigned int lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 358 | int log_parse_category(const char *category); |
| 359 | void log_set_category_filter(struct log_target *target, int category, |
| 360 | int enable, int level); |
| 361 | |
| 362 | /* management of the targets */ |
| 363 | struct log_target *log_target_create(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 364 | void log_target_destroy(struct log_target *target); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 365 | struct log_target *log_target_create_stderr(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 366 | struct log_target *log_target_create_file(const char *fname); |
Harald Welte | 46cfd77 | 2011-02-17 15:56:56 +0100 | [diff] [blame] | 367 | struct log_target *log_target_create_syslog(const char *ident, int option, |
| 368 | int facility); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 369 | struct log_target *log_target_create_gsmtap(const char *host, uint16_t port, |
| 370 | const char *ident, |
| 371 | bool ofd_wq_mode, |
| 372 | bool add_sink); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 373 | int log_target_file_reopen(struct log_target *tgt); |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 374 | int log_targets_reopen(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 375 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 376 | void log_add_target(struct log_target *target); |
| 377 | void log_del_target(struct log_target *target); |
| 378 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 379 | struct log_target *log_target_find(int type, const char *fname); |
| 380 | extern struct llist_head osmo_log_target_list; |
| 381 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 382 | /*! @} */ |