blob: 139d29169f5290fc1475818628cd27f6e58cbeeb [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welte3ae27582010-03-26 21:24:24 +08002
Harald Welte18fc4652011-08-17 14:14:17 +02003/*! \defgroup logging Osmocom logging framework
4 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02005 * \file logging.h */
Harald Welte18fc4652011-08-17 14:14:17 +02006
Harald Welte3ae27582010-03-26 21:24:24 +08007#include <stdio.h>
8#include <stdint.h>
Christoph Fritzab7c9c72011-09-01 16:22:17 +02009#include <stdarg.h>
Harald Welteaa00f992016-12-02 15:30:02 +010010#include <stdbool.h>
Maxaa1bc012017-01-13 11:01:12 +010011#include <osmocom/core/defs.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010012#include <osmocom/core/linuxlist.h>
Harald Welte3ae27582010-03-26 21:24:24 +080013
Neels Hofmeyr87e45502017-06-20 00:17:59 +020014/*! Maximum number of logging contexts */
Harald Welte3ae27582010-03-26 21:24:24 +080015#define LOG_MAX_CTX 8
Neels Hofmeyr87e45502017-06-20 00:17:59 +020016/*! Maximum number of logging filters */
Harald Welte3ae27582010-03-26 21:24:24 +080017#define LOG_MAX_FILTERS 8
18
Kévin Redond1e220f2019-06-13 13:41:00 +020019#ifndef DEBUG
Harald Welte3ae27582010-03-26 21:24:24 +080020#define DEBUG
Kévin Redond1e220f2019-06-13 13:41:00 +020021#endif
Harald Welte3ae27582010-03-26 21:24:24 +080022
23#ifdef DEBUG
Neels Hofmeyr87e45502017-06-20 00:17:59 +020024/*! Log a debug message through the Osmocom logging framework
Harald Welte2d2e2cc2016-04-25 12:11:20 +020025 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
26 * \param[in] fmt format string
27 * \param[in] args variable argument list
28 */
Maxaa1bc012017-01-13 11:01:12 +010029#define DEBUGP(ss, fmt, args...) LOGP(ss, LOGL_DEBUG, fmt, ##args)
30#define DEBUGPC(ss, fmt, args...) LOGPC(ss, LOGL_DEBUG, fmt, ##args)
Harald Welte3ae27582010-03-26 21:24:24 +080031#else
32#define DEBUGP(xss, fmt, args...)
33#define DEBUGPC(ss, fmt, args...)
34#endif
35
Harald Welte3ae27582010-03-26 21:24:24 +080036
Holger Hans Peter Freytherfb4bfc22012-07-12 09:26:25 +020037void osmo_vlogp(int subsys, int level, const char *file, int line,
Harald Welte36c5a3e2011-08-27 14:33:19 +020038 int cont, const char *format, va_list ap);
39
Maxaa1bc012017-01-13 11:01:12 +010040void logp(int subsys, const char *file, int line, int cont, const char *format, ...) OSMO_DEPRECATED("Use DEBUGP* macros instead");
Harald Welte3ae27582010-03-26 21:24:24 +080041
Neels Hofmeyr87e45502017-06-20 00:17:59 +020042/*! Log a new message through the Osmocom logging framework
Harald Weltebd598e32011-08-16 23:26:52 +020043 * \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 Welte3ae27582010-03-26 21:24:24 +080048#define LOGP(ss, level, fmt, args...) \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010049 LOGPSRC(ss, level, NULL, 0, fmt, ## args)
Harald Weltebd598e32011-08-16 23:26:52 +020050
Neels Hofmeyr87e45502017-06-20 00:17:59 +020051/*! Continue a log message through the Osmocom logging framework
Harald Weltebd598e32011-08-16 23:26:52 +020052 * \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 Welte3ae27582010-03-26 21:24:24 +080057#define LOGPC(ss, level, fmt, args...) \
Jacob Erlbecka89d22c2015-11-17 11:52:25 +010058 do { \
59 if (log_check_level(ss, level)) \
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020060 logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
Jacob Erlbecka89d22c2015-11-17 11:52:25 +010061 } while(0)
Harald Welte3ae27582010-03-26 21:24:24 +080062
Neels Hofmeyr87e45502017-06-20 00:17:59 +020063/*! Log through the Osmocom logging framework with explicit source.
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020064 * If caller_file is passed as NULL, __FILE__ and __LINE__ are used
Neels Hofmeyr725698a2016-12-14 17:24:54 +010065 * 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 Hofmeyr983dcb92018-08-20 12:33:22 +020070 * \param[in] caller_file caller's source file string (e.g. __FILE__)
Neels Hofmeyr725698a2016-12-14 17:24:54 +010071 * \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 Freyther37a83402017-11-29 11:46:39 +080076 LOGPSRCC(ss, level, caller_file, caller_line, 0, fmt, ##args)
77
78/*! Log through the Osmocom logging framework with explicit source.
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020079 * If caller_file is passed as NULL, __FILE__ and __LINE__ are used
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080080 * 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 Hofmeyr983dcb92018-08-20 12:33:22 +020085 * \param[in] caller_file caller's source file string (e.g. __FILE__)
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080086 * \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 Hofmeyr725698a2016-12-14 17:24:54 +010092 do { \
93 if (log_check_level(ss, level)) {\
94 if (caller_file) \
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080095 logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010096 else \
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020097 logp2(ss, level, __FILE__, __LINE__, cont, fmt, ##args); \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010098 }\
99 } while(0)
100
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200101/*! 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 Welte3ae27582010-03-26 21:24:24 +0800107
Harald Welteb43bc042011-06-27 10:29:17 +0200108/* logging levels defined by the library itself */
Harald Welte2d2e2cc2016-04-25 12:11:20 +0200109#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 Hofmeyr9795cf12016-12-10 17:01:06 +0100119#define DLGSUP -11 /*!< Generic Subscriber Update Protocol */
Harald Weltec0f00072016-04-27 18:32:35 +0200120#define DLOAP -12 /*!< Osmocom Authentication Protocol */
Harald Welte62d32962017-04-03 19:37:11 +0200121#define DLSS7 -13 /*!< Osmocom SS7 */
122#define DLSCCP -14 /*!< Osmocom SCCP */
123#define DLSUA -15 /*!< Osmocom SUA */
124#define DLM3UA -16 /*!< Osmocom M3UA */
Neels Hofmeyra7ccf612017-07-11 18:43:09 +0200125#define DLMGCP -17 /*!< Osmocom MGCP */
Pau Espin Pedrol8fd85572018-02-27 19:43:10 +0100126#define DLJIBUF -18 /*!< Osmocom Jitter Buffer */
Harald Welteb99ed7f2018-08-13 20:54:44 +0200127#define DLRSPRO -19 /*!< Osmocom Remote SIM Protocol */
128#define OSMO_NUM_DLIB 19 /*!< Number of logging sub-systems in libraries */
Harald Welteb43bc042011-06-27 10:29:17 +0200129
Neels Hofmeyrfc47b032017-06-20 04:29:38 +0200130/*! Configuration of single log category / sub-system */
Harald Welte3ae27582010-03-26 21:24:24 +0800131struct log_category {
Harald Welte2d2e2cc2016-04-25 12:11:20 +0200132 uint8_t loglevel; /*!< configured log-level */
133 uint8_t enabled; /*!< is logging enabled? */
Harald Welte3ae27582010-03-26 21:24:24 +0800134};
135
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200136/*! Information regarding one logging category */
Harald Welte3ae27582010-03-26 21:24:24 +0800137struct log_info_cat {
Harald Welte18fc4652011-08-17 14:14:17 +0200138 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 Welte3ae27582010-03-26 21:24:24 +0800143};
144
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200145/*! Log context information, passed to filter */
Harald Welte3ae27582010-03-26 21:24:24 +0800146struct log_context {
147 void *ctx[LOG_MAX_CTX+1];
148};
149
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200150/*! Indexes to indicate the object currently acted upon.
Neels Hofmeyr492e1802017-02-23 17:45:26 +0100151 * Array indexes for the global \a log_context array. */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100152enum log_ctx_index {
153 LOG_CTX_GB_NSVC,
154 LOG_CTX_GB_BVC,
155 LOG_CTX_BSC_SUBSCR,
156 LOG_CTX_VLR_SUBSCR,
Oliver Smith210acc62019-09-12 17:13:34 +0200157 LOG_CTX_L1_SAPI,
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100158 _LOG_CTX_COUNT
Neels Hofmeyr812ba6d2017-02-17 16:35:27 +0100159};
160
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200161/*! Indexes to indicate objects that should be logged.
Neels Hofmeyr492e1802017-02-23 17:45:26 +0100162 * Array indexes to log_target->filter_data and bit indexes for
163 * log_target->filter_map. */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100164enum log_filter_index {
165 LOG_FLT_ALL,
166 LOG_FLT_GB_NSVC,
167 LOG_FLT_GB_BVC,
168 LOG_FLT_BSC_SUBSCR,
169 LOG_FLT_VLR_SUBSCR,
Oliver Smith210acc62019-09-12 17:13:34 +0200170 LOG_FLT_L1_SAPI,
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100171 _LOG_FLT_COUNT
Neels Hofmeyr812ba6d2017-02-17 16:35:27 +0100172};
173
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200174/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100175#define LOG_FILTER_ALL (1<<LOG_FLT_ALL)
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200176/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100177#define GPRS_CTX_NSVC LOG_CTX_GB_NSVC
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200178/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100179#define GPRS_CTX_BVC LOG_CTX_GB_BVC
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200180/*! Indexes to indicate the object currently acted upon.
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100181 * Array indexes for the global \a log_context array. */
Neels Hofmeyr0d6420b2017-02-23 17:34:35 +0100182
Harald Welte3ae27582010-03-26 21:24:24 +0800183struct log_target;
184
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200185/*! Log filter function */
Harald Welte3ae27582010-03-26 21:24:24 +0800186typedef int log_filter(const struct log_context *ctx,
187 struct log_target *target);
188
Harald Weltefb84f322013-06-06 07:33:54 +0200189struct log_info;
190struct vty;
Harald Welteaa00f992016-12-02 15:30:02 +0100191struct gsmtap_inst;
Harald Weltefb84f322013-06-06 07:33:54 +0200192
193typedef void log_print_filters(struct vty *vty,
194 const struct log_info *info,
195 const struct log_target *tgt);
196
197typedef void log_save_filters(struct vty *vty,
198 const struct log_info *info,
199 const struct log_target *tgt);
200
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200201/*! Logging configuration, passed to \ref log_init */
Harald Welte3ae27582010-03-26 21:24:24 +0800202struct log_info {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200203 /* filter callback function */
Harald Welte3ae27582010-03-26 21:24:24 +0800204 log_filter *filter_fn;
205
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200206 /*! per-category information */
Holger Hans Peter Freyther06f64552012-09-11 10:31:29 +0200207 const struct log_info_cat *cat;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200208 /*! total number of categories */
Harald Welte3ae27582010-03-26 21:24:24 +0800209 unsigned int num_cat;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200210 /*! total number of user categories (not library) */
Harald Welteb43bc042011-06-27 10:29:17 +0200211 unsigned int num_cat_user;
Harald Weltefb84f322013-06-06 07:33:54 +0200212
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200213 /*! filter saving function */
Harald Weltefb84f322013-06-06 07:33:54 +0200214 log_save_filters *save_fn;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200215 /*! filter saving function */
Harald Weltefb84f322013-06-06 07:33:54 +0200216 log_print_filters *print_fn;
Harald Welte3ae27582010-03-26 21:24:24 +0800217};
218
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200219/*! Type of logging target */
Harald Welte28222962011-02-18 20:37:04 +0100220enum log_target_type {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200221 LOG_TGT_TYPE_VTY, /*!< VTY logging */
222 LOG_TGT_TYPE_SYSLOG, /*!< syslog based logging */
223 LOG_TGT_TYPE_FILE, /*!< text file logging */
224 LOG_TGT_TYPE_STDERR, /*!< stderr logging */
225 LOG_TGT_TYPE_STRRB, /*!< osmo_strrb-backed logging */
226 LOG_TGT_TYPE_GSMTAP, /*!< GSMTAP network logging */
Harald Welte28222962011-02-18 20:37:04 +0100227};
228
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100229/*! Whether/how to log the source filename (and line number). */
230enum log_filename_type {
231 LOG_FILENAME_NONE,
232 LOG_FILENAME_PATH,
Neels Hofmeyr0e2a9432018-01-16 02:49:48 +0100233 LOG_FILENAME_BASENAME,
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100234};
235
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200236/*! Where on a log line source file and line should be logged. */
237enum log_filename_pos {
238 LOG_FILENAME_POS_HEADER_END,
239 LOG_FILENAME_POS_LINE_END,
240};
241
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200242/*! structure representing a logging target */
Harald Welte3ae27582010-03-26 21:24:24 +0800243struct log_target {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200244 struct llist_head entry; /*!< linked list */
Harald Welte3ae27582010-03-26 21:24:24 +0800245
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200246 /*! Internal data for filtering */
Harald Welte3ae27582010-03-26 21:24:24 +0800247 int filter_map;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200248 /*! Internal data for filtering */
Harald Welte3ae27582010-03-26 21:24:24 +0800249 void *filter_data[LOG_MAX_FILTERS+1];
250
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200251 /*! logging categories */
Harald Welteb43bc042011-06-27 10:29:17 +0200252 struct log_category *categories;
253
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200254 /*! global log level */
Harald Welte3ae27582010-03-26 21:24:24 +0800255 uint8_t loglevel;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200256 /*! should color be used when printing log messages? */
Harald Welte87dbca12011-07-16 11:57:53 +0200257 unsigned int use_color:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200258 /*! should log messages be prefixed with a timestamp? */
Harald Welte87dbca12011-07-16 11:57:53 +0200259 unsigned int print_timestamp:1;
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100260 /*! DEPRECATED: use print_filename2 instead. */
Holger Hans Peter Freytherdb153362012-09-11 11:24:51 +0200261 unsigned int print_filename:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200262 /*! should log messages be prefixed with a category name? */
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100263 unsigned int print_category:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200264 /*! should log messages be prefixed with an extended timestamp? */
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100265 unsigned int print_ext_timestamp:1;
Harald Welte3ae27582010-03-26 21:24:24 +0800266
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200267 /*! the type of this log taget */
Harald Welte28222962011-02-18 20:37:04 +0100268 enum log_target_type type;
269
Harald Welte3ae27582010-03-26 21:24:24 +0800270 union {
271 struct {
272 FILE *out;
Harald Welte72d0c532010-08-25 19:24:00 +0200273 const char *fname;
Harald Welte0083cd32010-08-25 14:55:44 +0200274 } tgt_file;
Harald Welte3ae27582010-03-26 21:24:24 +0800275
276 struct {
277 int priority;
Harald Welte28222962011-02-18 20:37:04 +0100278 int facility;
Harald Welte3ae27582010-03-26 21:24:24 +0800279 } tgt_syslog;
280
281 struct {
282 void *vty;
283 } tgt_vty;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000284
285 struct {
286 void *rb;
287 } tgt_rb;
Harald Welteaa00f992016-12-02 15:30:02 +0100288
289 struct {
290 struct gsmtap_inst *gsmtap_inst;
291 const char *ident;
292 const char *hostname;
293 } tgt_gsmtap;
Harald Welte3ae27582010-03-26 21:24:24 +0800294 };
295
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200296 /*! call-back function to be called when the logging framework
Harald Welted7c0a372016-12-02 13:52:59 +0100297 * wants to log a fully formatted string
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +0100298 * \param[in] target logging target
Harald Welte18fc4652011-08-17 14:14:17 +0200299 * \param[in] level log level of currnet message
300 * \param[in] string the string that is to be written to the log
301 */
Harald Welte76e72ab2011-02-17 15:52:39 +0100302 void (*output) (struct log_target *target, unsigned int level,
303 const char *string);
Harald Welted7c0a372016-12-02 13:52:59 +0100304
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200305 /*! alternative call-back function to which the logging
Harald Welted7c0a372016-12-02 13:52:59 +0100306 * framework passes the unfortmatted input arguments,
307 * i.e. bypassing the internal string formatter
308 * \param[in] target logging target
309 * \param[in] subsys logging sub-system
310 * \param[in] level logging level
311 * \param[in] file soure code file name
312 * \param[in] line source code file line number
313 * \param[in] cont continuation of previous statement?
314 * \param[in] format format string
315 * \param[in] ap vararg list of printf arguments
316 */
317 void (*raw_output)(struct log_target *target, int subsys,
318 unsigned int level, const char *file, int line,
319 int cont, const char *format, va_list ap);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100320
321 /* Should the log level be printed? */
322 bool print_level;
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100323 /* Should we print the subsys in hex like '<000b>'? */
324 bool print_category_hex;
325 /* Should we print the source file and line, and in which way? */
326 enum log_filename_type print_filename2;
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200327 /* Where on a log line to put the source file info. */
328 enum log_filename_pos print_filename_pos;
Harald Welte3ae27582010-03-26 21:24:24 +0800329};
330
331/* use the above macros */
Andreas Eversberg2d6563b2012-07-10 13:10:15 +0200332void logp2(int subsys, unsigned int level, const char *file,
Harald Welte3ae27582010-03-26 21:24:24 +0800333 int line, int cont, const char *format, ...)
334 __attribute__ ((format (printf, 6, 7)));
Harald Welteb43bc042011-06-27 10:29:17 +0200335int log_init(const struct log_info *inf, void *talloc_ctx);
Harald Welte69e6c3c2016-04-20 10:41:27 +0200336void log_fini(void);
Jacob Erlbeckde6dd722015-11-17 11:52:24 +0100337int log_check_level(int subsys, unsigned int level);
Harald Welte3ae27582010-03-26 21:24:24 +0800338
339/* context management */
340void log_reset_context(void);
341int log_set_context(uint8_t ctx, void *value);
342
343/* filter on the targets */
344void log_set_all_filter(struct log_target *target, int);
345
346void log_set_use_color(struct log_target *target, int);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100347void log_set_print_extended_timestamp(struct log_target *target, int);
Harald Welte3ae27582010-03-26 21:24:24 +0800348void log_set_print_timestamp(struct log_target *target, int);
Holger Hans Peter Freytherdb153362012-09-11 11:24:51 +0200349void log_set_print_filename(struct log_target *target, int);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100350void log_set_print_filename2(struct log_target *target, enum log_filename_type lft);
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200351void log_set_print_filename_pos(struct log_target *target, enum log_filename_pos pos);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100352void log_set_print_category(struct log_target *target, int);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100353void log_set_print_category_hex(struct log_target *target, int);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100354void log_set_print_level(struct log_target *target, int);
Harald Welte3ae27582010-03-26 21:24:24 +0800355void log_set_log_level(struct log_target *target, int log_level);
356void log_parse_category_mask(struct log_target *target, const char* mask);
Harald Welteaa00f992016-12-02 15:30:02 +0100357const char* log_category_name(int subsys);
Max15b6d412017-07-06 16:57:15 +0200358int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
359const char *log_level_str(unsigned int lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
Harald Welte3ae27582010-03-26 21:24:24 +0800360int log_parse_category(const char *category);
361void log_set_category_filter(struct log_target *target, int category,
362 int enable, int level);
363
364/* management of the targets */
365struct log_target *log_target_create(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200366void log_target_destroy(struct log_target *target);
Harald Welte3ae27582010-03-26 21:24:24 +0800367struct log_target *log_target_create_stderr(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200368struct log_target *log_target_create_file(const char *fname);
Harald Welte46cfd772011-02-17 15:56:56 +0100369struct log_target *log_target_create_syslog(const char *ident, int option,
370 int facility);
Harald Welteaa00f992016-12-02 15:30:02 +0100371struct log_target *log_target_create_gsmtap(const char *host, uint16_t port,
372 const char *ident,
373 bool ofd_wq_mode,
374 bool add_sink);
Harald Welte72d0c532010-08-25 19:24:00 +0200375int log_target_file_reopen(struct log_target *tgt);
Harald Welte4de854d2013-03-18 19:01:40 +0100376int log_targets_reopen(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200377
Harald Welte3ae27582010-03-26 21:24:24 +0800378void log_add_target(struct log_target *target);
379void log_del_target(struct log_target *target);
380
Harald Welte28222962011-02-18 20:37:04 +0100381struct log_target *log_target_find(int type, const char *fname);
Harald Welte28222962011-02-18 20:37:04 +0100382
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200383void log_enable_multithread(void);
384
385void log_tgt_mutex_lock_impl(void);
386void log_tgt_mutex_unlock_impl(void);
387#define LOG_MTX_DEBUG 0
388#if LOG_MTX_DEBUG
389 #include <pthread.h>
390 #define log_tgt_mutex_lock() do { fprintf(stderr, "[%lu] %s:%d [%s] lock\n", pthread_self(), __FILE__, __LINE__, __func__); log_tgt_mutex_lock_impl(); } while (0)
391 #define log_tgt_mutex_unlock() do { fprintf(stderr, "[%lu] %s:%d [%s] unlock\n", pthread_self(), __FILE__, __LINE__, __func__); log_tgt_mutex_unlock_impl(); } while (0)
392#else
393 #define log_tgt_mutex_lock() log_tgt_mutex_lock_impl()
394 #define log_tgt_mutex_unlock() log_tgt_mutex_unlock_impl()
395#endif
396
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200397/*! @} */