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 | * @{ |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 7 | /*! \file logging.h */ |
| 8 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 9 | #include <stdio.h> |
| 10 | #include <stdint.h> |
Christoph Fritz | ab7c9c7 | 2011-09-01 16:22:17 +0200 | [diff] [blame] | 11 | #include <stdarg.h> |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 12 | #include <stdbool.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 13 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 14 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 15 | /*! \brief Maximum number of logging contexts */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 16 | #define LOG_MAX_CTX 8 |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 17 | /*! \brief Maximum number of logging filters */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 18 | #define LOG_MAX_FILTERS 8 |
| 19 | |
| 20 | #define DEBUG |
| 21 | |
| 22 | #ifdef DEBUG |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 23 | /*! \brief Log a debug message through the Osmocom logging framework |
| 24 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 25 | * \param[in] fmt format string |
| 26 | * \param[in] args variable argument list |
| 27 | */ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 28 | #define DEBUGP(ss, fmt, args...) \ |
| 29 | do { \ |
| 30 | if (log_check_level(ss, LOGL_DEBUG)) \ |
Harald Welte | 3d79240 | 2016-05-10 15:23:06 +0200 | [diff] [blame] | 31 | logp(ss, __BASE_FILE__, __LINE__, 0, fmt, ## args); \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 32 | } while(0) |
| 33 | |
| 34 | #define DEBUGPC(ss, fmt, args...) \ |
| 35 | do { \ |
| 36 | if (log_check_level(ss, LOGL_DEBUG)) \ |
Harald Welte | 3d79240 | 2016-05-10 15:23:06 +0200 | [diff] [blame] | 37 | logp(ss, __BASE_FILE__, __LINE__, 1, fmt, ## args); \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 38 | } while(0) |
| 39 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 40 | #else |
| 41 | #define DEBUGP(xss, fmt, args...) |
| 42 | #define DEBUGPC(ss, fmt, args...) |
| 43 | #endif |
| 44 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 45 | |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 46 | void osmo_vlogp(int subsys, int level, const char *file, int line, |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 47 | int cont, const char *format, va_list ap); |
| 48 | |
Andreas Eversberg | 2d6563b | 2012-07-10 13:10:15 +0200 | [diff] [blame] | 49 | void logp(int subsys, const char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6))); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 50 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 51 | /*! \brief Log a new message through the Osmocom logging framework |
| 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 LOGP(ss, level, fmt, args...) \ |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 58 | LOGPSRC(ss, level, NULL, 0, fmt, ## args) |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 59 | |
| 60 | /*! \brief Continue a log message through the Osmocom logging framework |
| 61 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 62 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
| 63 | * \param[in] fmt format string |
| 64 | * \param[in] args variable argument list |
| 65 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 66 | #define LOGPC(ss, level, fmt, args...) \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 67 | do { \ |
| 68 | if (log_check_level(ss, level)) \ |
Harald Welte | 3d79240 | 2016-05-10 15:23:06 +0200 | [diff] [blame] | 69 | logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \ |
Jacob Erlbeck | a89d22c | 2015-11-17 11:52:25 +0100 | [diff] [blame] | 70 | } while(0) |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 71 | |
Neels Hofmeyr | 725698a | 2016-12-14 17:24:54 +0100 | [diff] [blame] | 72 | /*! \brief Log through the Osmocom logging framework with explicit source. |
| 73 | * If caller_file is passed as NULL, __BASE_FILE__ and __LINE__ are used |
| 74 | * instead of caller_file and caller_line (so that this macro here defines |
| 75 | * both cases in the same place, and to catch cases where callers fail to pass |
| 76 | * a non-null filename string). |
| 77 | * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL) |
| 78 | * \param[in] level logging level (e.g. \ref LOGL_NOTICE) |
| 79 | * \param[in] caller_file caller's source file string (e.g. __BASE_FILE__) |
| 80 | * \param[in] caller_line caller's source line nr (e.g. __LINE__) |
| 81 | * \param[in] fmt format string |
| 82 | * \param[in] args variable argument list |
| 83 | */ |
| 84 | #define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \ |
| 85 | do { \ |
| 86 | if (log_check_level(ss, level)) {\ |
| 87 | if (caller_file) \ |
| 88 | logp2(ss, level, caller_file, caller_line, 0, fmt, ##args); \ |
| 89 | else \ |
| 90 | logp2(ss, level, __BASE_FILE__, __LINE__, 0, fmt, ##args); \ |
| 91 | }\ |
| 92 | } while(0) |
| 93 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 94 | /*! \brief different log levels */ |
| 95 | #define LOGL_DEBUG 1 /*!< \brief debugging information */ |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 96 | #define LOGL_INFO 3 /*!< \brief general information */ |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 97 | #define LOGL_NOTICE 5 /*!< \brief abnormal/unexpected condition */ |
| 98 | #define LOGL_ERROR 7 /*!< \brief error condition, requires user action */ |
| 99 | #define LOGL_FATAL 8 /*!< \brief fatal, program aborted */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 100 | |
| 101 | #define LOG_FILTER_ALL 0x0001 |
| 102 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 103 | /* logging levels defined by the library itself */ |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 104 | #define DLGLOBAL -1 /*!< global logging */ |
| 105 | #define DLLAPD -2 /*!< LAPD implementation */ |
| 106 | #define DLINP -3 /*!< (A-bis) Input sub-system */ |
| 107 | #define DLMUX -4 /*!< Osmocom Multiplex (Osmux) */ |
| 108 | #define DLMI -5 /*!< ISDN-layer below input sub-system */ |
| 109 | #define DLMIB -6 /*!< ISDN layer B-channel */ |
| 110 | #define DLSMS -7 /*!< SMS sub-system */ |
| 111 | #define DLCTRL -8 /*!< Control Interface */ |
| 112 | #define DLGTP -9 /*!< GTP (GPRS Tunneling Protocol */ |
| 113 | #define DLSTATS -10 /*!< Statistics */ |
Neels Hofmeyr | 9795cf1 | 2016-12-10 17:01:06 +0100 | [diff] [blame] | 114 | #define DLGSUP -11 /*!< Generic Subscriber Update Protocol */ |
Harald Welte | c0f0007 | 2016-04-27 18:32:35 +0200 | [diff] [blame] | 115 | #define DLOAP -12 /*!< Osmocom Authentication Protocol */ |
| 116 | #define OSMO_NUM_DLIB 12 /*!< Number of logging sub-systems in libraries */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 117 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 118 | /*! Configuration of singgle log category / sub-system */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 119 | struct log_category { |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 120 | uint8_t loglevel; /*!< configured log-level */ |
| 121 | uint8_t enabled; /*!< is logging enabled? */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 122 | }; |
| 123 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 124 | /*! \brief Information regarding one logging category */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 125 | struct log_info_cat { |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 126 | const char *name; /*!< name of category */ |
| 127 | const char *color; /*!< color string for cateyory */ |
| 128 | const char *description; /*!< description text */ |
| 129 | uint8_t loglevel; /*!< currently selected log-level */ |
| 130 | uint8_t enabled; /*!< is this category enabled or not */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 131 | }; |
| 132 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 133 | /*! \brief Log context information, passed to filter */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 134 | struct log_context { |
| 135 | void *ctx[LOG_MAX_CTX+1]; |
| 136 | }; |
| 137 | |
| 138 | struct log_target; |
| 139 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 140 | /*! \brief Log filter function */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 141 | typedef int log_filter(const struct log_context *ctx, |
| 142 | struct log_target *target); |
| 143 | |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 144 | struct log_info; |
| 145 | struct vty; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 146 | struct gsmtap_inst; |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 147 | |
| 148 | typedef void log_print_filters(struct vty *vty, |
| 149 | const struct log_info *info, |
| 150 | const struct log_target *tgt); |
| 151 | |
| 152 | typedef void log_save_filters(struct vty *vty, |
| 153 | const struct log_info *info, |
| 154 | const struct log_target *tgt); |
| 155 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 156 | /*! \brief Logging configuration, passed to \ref log_init */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 157 | struct log_info { |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 158 | /* \brief filter callback function */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 159 | log_filter *filter_fn; |
| 160 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 161 | /*! \brief per-category information */ |
Holger Hans Peter Freyther | 06f6455 | 2012-09-11 10:31:29 +0200 | [diff] [blame] | 162 | const struct log_info_cat *cat; |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 163 | /*! \brief total number of categories */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 164 | unsigned int num_cat; |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 165 | /*! \brief total number of user categories (not library) */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 166 | unsigned int num_cat_user; |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 167 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 168 | /*! \brief filter saving function */ |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 169 | log_save_filters *save_fn; |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 170 | /*! \brief filter saving function */ |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 171 | log_print_filters *print_fn; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 172 | }; |
| 173 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 174 | /*! \brief Type of logging target */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 175 | enum log_target_type { |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 176 | LOG_TGT_TYPE_VTY, /*!< \brief VTY logging */ |
| 177 | LOG_TGT_TYPE_SYSLOG, /*!< \brief syslog based logging */ |
| 178 | LOG_TGT_TYPE_FILE, /*!< \brief text file logging */ |
| 179 | LOG_TGT_TYPE_STDERR, /*!< \brief stderr logging */ |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 180 | LOG_TGT_TYPE_STRRB, /*!< \brief osmo_strrb-backed logging */ |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 181 | LOG_TGT_TYPE_GSMTAP, /*!< \brief GSMTAP network logging */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 182 | }; |
| 183 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 184 | /*! \brief structure representing a logging target */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 185 | struct log_target { |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 186 | struct llist_head entry; /*!< \brief linked list */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 187 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 188 | /*! \brief Internal data for filtering */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 189 | int filter_map; |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 190 | /*! \brief Internal data for filtering */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 191 | void *filter_data[LOG_MAX_FILTERS+1]; |
| 192 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 193 | /*! \brief logging categories */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 194 | struct log_category *categories; |
| 195 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 196 | /*! \brief global log level */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 197 | uint8_t loglevel; |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 198 | /*! \brief should color be used when printing log messages? */ |
Harald Welte | 87dbca1 | 2011-07-16 11:57:53 +0200 | [diff] [blame] | 199 | unsigned int use_color:1; |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 200 | /*! \brief should log messages be prefixed with a timestamp? */ |
Harald Welte | 87dbca1 | 2011-07-16 11:57:53 +0200 | [diff] [blame] | 201 | unsigned int print_timestamp:1; |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 202 | /*! \brief should log messages be prefixed with a filename? */ |
| 203 | unsigned int print_filename:1; |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 204 | /*! \brief should log messages be prefixed with a category name? */ |
| 205 | unsigned int print_category:1; |
| 206 | /*! \brief should log messages be prefixed with an extended timestamp? */ |
| 207 | unsigned int print_ext_timestamp:1; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 208 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 209 | /*! \brief the type of this log taget */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 210 | enum log_target_type type; |
| 211 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 212 | union { |
| 213 | struct { |
| 214 | FILE *out; |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 215 | const char *fname; |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 216 | } tgt_file; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 217 | |
| 218 | struct { |
| 219 | int priority; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 220 | int facility; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 221 | } tgt_syslog; |
| 222 | |
| 223 | struct { |
| 224 | void *vty; |
| 225 | } tgt_vty; |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 226 | |
| 227 | struct { |
| 228 | void *rb; |
| 229 | } tgt_rb; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 230 | |
| 231 | struct { |
| 232 | struct gsmtap_inst *gsmtap_inst; |
| 233 | const char *ident; |
| 234 | const char *hostname; |
| 235 | } tgt_gsmtap; |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 236 | }; |
| 237 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 238 | /*! \brief call-back function to be called when the logging framework |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 239 | * wants to log a fully formatted string |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 240 | * \param[in] target logging target |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 241 | * \param[in] level log level of currnet message |
| 242 | * \param[in] string the string that is to be written to the log |
| 243 | */ |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 244 | void (*output) (struct log_target *target, unsigned int level, |
| 245 | const char *string); |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 246 | |
| 247 | /*! \brief alternative call-back function to which the logging |
| 248 | * framework passes the unfortmatted input arguments, |
| 249 | * i.e. bypassing the internal string formatter |
| 250 | * \param[in] target logging target |
| 251 | * \param[in] subsys logging sub-system |
| 252 | * \param[in] level logging level |
| 253 | * \param[in] file soure code file name |
| 254 | * \param[in] line source code file line number |
| 255 | * \param[in] cont continuation of previous statement? |
| 256 | * \param[in] format format string |
| 257 | * \param[in] ap vararg list of printf arguments |
| 258 | */ |
| 259 | void (*raw_output)(struct log_target *target, int subsys, |
| 260 | unsigned int level, const char *file, int line, |
| 261 | int cont, const char *format, va_list ap); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | /* use the above macros */ |
Andreas Eversberg | 2d6563b | 2012-07-10 13:10:15 +0200 | [diff] [blame] | 265 | void logp2(int subsys, unsigned int level, const char *file, |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 266 | int line, int cont, const char *format, ...) |
| 267 | __attribute__ ((format (printf, 6, 7))); |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 268 | int log_init(const struct log_info *inf, void *talloc_ctx); |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 269 | void log_fini(void); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 270 | int log_check_level(int subsys, unsigned int level); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 271 | |
| 272 | /* context management */ |
| 273 | void log_reset_context(void); |
| 274 | int log_set_context(uint8_t ctx, void *value); |
| 275 | |
| 276 | /* filter on the targets */ |
| 277 | void log_set_all_filter(struct log_target *target, int); |
| 278 | |
| 279 | void log_set_use_color(struct log_target *target, int); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 280 | void log_set_print_extended_timestamp(struct log_target *target, int); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 281 | void log_set_print_timestamp(struct log_target *target, int); |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 282 | void log_set_print_filename(struct log_target *target, int); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 283 | void log_set_print_category(struct log_target *target, int); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 284 | void log_set_log_level(struct log_target *target, int log_level); |
| 285 | void log_parse_category_mask(struct log_target *target, const char* mask); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 286 | const char* log_category_name(int subsys); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 287 | int log_parse_level(const char *lvl); |
Harald Welte | 9ac2225 | 2010-05-11 11:19:40 +0200 | [diff] [blame] | 288 | const char *log_level_str(unsigned int lvl); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 289 | int log_parse_category(const char *category); |
| 290 | void log_set_category_filter(struct log_target *target, int category, |
| 291 | int enable, int level); |
| 292 | |
| 293 | /* management of the targets */ |
| 294 | struct log_target *log_target_create(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 295 | void log_target_destroy(struct log_target *target); |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 296 | struct log_target *log_target_create_stderr(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 297 | struct log_target *log_target_create_file(const char *fname); |
Harald Welte | 46cfd77 | 2011-02-17 15:56:56 +0100 | [diff] [blame] | 298 | struct log_target *log_target_create_syslog(const char *ident, int option, |
| 299 | int facility); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 300 | struct log_target *log_target_create_gsmtap(const char *host, uint16_t port, |
| 301 | const char *ident, |
| 302 | bool ofd_wq_mode, |
| 303 | bool add_sink); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 304 | int log_target_file_reopen(struct log_target *tgt); |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 305 | int log_targets_reopen(void); |
Harald Welte | 72d0c53 | 2010-08-25 19:24:00 +0200 | [diff] [blame] | 306 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 307 | void log_add_target(struct log_target *target); |
| 308 | void log_del_target(struct log_target *target); |
| 309 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 310 | /* Generate command string for VTY use */ |
| 311 | const char *log_vty_command_string(const struct log_info *info); |
| 312 | const char *log_vty_command_description(const struct log_info *info); |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 313 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 314 | struct log_target *log_target_find(int type, const char *fname); |
| 315 | extern struct llist_head osmo_log_target_list; |
| 316 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 317 | /*! @} */ |