blob: a95c478dbecd838967656a734c9e59d6baac80f1 [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
Kévin Redond1e220f2019-06-13 13:41:00 +020014#ifndef DEBUG
Harald Welte3ae27582010-03-26 21:24:24 +080015#define DEBUG
Kévin Redond1e220f2019-06-13 13:41:00 +020016#endif
Harald Welte3ae27582010-03-26 21:24:24 +080017
Ericd02090b2021-11-24 20:24:46 +010018#ifdef LIBOSMOCORE_NO_LOGGING
19#undef DEBUG
20#endif
21
Harald Welte3ae27582010-03-26 21:24:24 +080022#ifdef DEBUG
Neels Hofmeyr87e45502017-06-20 00:17:59 +020023/*! Log a debug message through the Osmocom logging framework
Harald Welte2d2e2cc2016-04-25 12:11:20 +020024 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
25 * \param[in] fmt format string
26 * \param[in] args variable argument list
27 */
Maxaa1bc012017-01-13 11:01:12 +010028#define DEBUGP(ss, fmt, args...) LOGP(ss, LOGL_DEBUG, fmt, ##args)
29#define DEBUGPC(ss, fmt, args...) LOGPC(ss, LOGL_DEBUG, fmt, ##args)
Harald Welte3ae27582010-03-26 21:24:24 +080030#else
31#define DEBUGP(xss, fmt, args...)
32#define DEBUGPC(ss, fmt, args...)
33#endif
34
Harald Welte3ae27582010-03-26 21:24:24 +080035
Holger Hans Peter Freytherfb4bfc22012-07-12 09:26:25 +020036void osmo_vlogp(int subsys, int level, const char *file, int line,
Harald Welte36c5a3e2011-08-27 14:33:19 +020037 int cont, const char *format, va_list ap);
38
Maxaa1bc012017-01-13 11:01:12 +010039void 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 +080040
Neels Hofmeyr87e45502017-06-20 00:17:59 +020041/*! Log a new message through the Osmocom logging framework
Harald Weltebd598e32011-08-16 23:26:52 +020042 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
43 * \param[in] level logging level (e.g. \ref LOGL_NOTICE)
44 * \param[in] fmt format string
45 * \param[in] args variable argument list
46 */
Harald Welte3ae27582010-03-26 21:24:24 +080047#define LOGP(ss, level, fmt, args...) \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010048 LOGPSRC(ss, level, NULL, 0, fmt, ## args)
Harald Weltebd598e32011-08-16 23:26:52 +020049
Neels Hofmeyr87e45502017-06-20 00:17:59 +020050/*! Continue a log message through the Osmocom logging framework
Harald Weltebd598e32011-08-16 23:26:52 +020051 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
52 * \param[in] level logging level (e.g. \ref LOGL_NOTICE)
53 * \param[in] fmt format string
54 * \param[in] args variable argument list
55 */
Harald Welte3ae27582010-03-26 21:24:24 +080056#define LOGPC(ss, level, fmt, args...) \
Jacob Erlbecka89d22c2015-11-17 11:52:25 +010057 do { \
58 if (log_check_level(ss, level)) \
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020059 logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
Jacob Erlbecka89d22c2015-11-17 11:52:25 +010060 } while(0)
Harald Welte3ae27582010-03-26 21:24:24 +080061
Neels Hofmeyr87e45502017-06-20 00:17:59 +020062/*! Log through the Osmocom logging framework with explicit source.
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020063 * If caller_file is passed as NULL, __FILE__ and __LINE__ are used
Neels Hofmeyr725698a2016-12-14 17:24:54 +010064 * instead of caller_file and caller_line (so that this macro here defines
65 * both cases in the same place, and to catch cases where callers fail to pass
66 * a non-null filename string).
67 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
68 * \param[in] level logging level (e.g. \ref LOGL_NOTICE)
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020069 * \param[in] caller_file caller's source file string (e.g. __FILE__)
Neels Hofmeyr725698a2016-12-14 17:24:54 +010070 * \param[in] caller_line caller's source line nr (e.g. __LINE__)
71 * \param[in] fmt format string
72 * \param[in] args variable argument list
73 */
74#define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080075 LOGPSRCC(ss, level, caller_file, caller_line, 0, fmt, ##args)
76
77/*! Log through the Osmocom logging framework with explicit source.
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020078 * If caller_file is passed as NULL, __FILE__ and __LINE__ are used
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080079 * instead of caller_file and caller_line (so that this macro here defines
80 * both cases in the same place, and to catch cases where callers fail to pass
81 * a non-null filename string).
82 * \param[in] ss logging subsystem (e.g. \ref DLGLOBAL)
83 * \param[in] level logging level (e.g. \ref LOGL_NOTICE)
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020084 * \param[in] caller_file caller's source file string (e.g. __FILE__)
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080085 * \param[in] caller_line caller's source line nr (e.g. __LINE__)
86 * \param[in] cont continuation (1) or new line (0)
87 * \param[in] fmt format string
88 * \param[in] args variable argument list
89 */
90#define LOGPSRCC(ss, level, caller_file, caller_line, cont, fmt, args...) \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010091 do { \
92 if (log_check_level(ss, level)) {\
93 if (caller_file) \
Holger Hans Peter Freyther37a83402017-11-29 11:46:39 +080094 logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010095 else \
Neels Hofmeyr983dcb92018-08-20 12:33:22 +020096 logp2(ss, level, __FILE__, __LINE__, cont, fmt, ##args); \
Neels Hofmeyr725698a2016-12-14 17:24:54 +010097 }\
98 } while(0)
99
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200100/*! different log levels */
101#define LOGL_DEBUG 1 /*!< debugging information */
102#define LOGL_INFO 3 /*!< general information */
103#define LOGL_NOTICE 5 /*!< abnormal/unexpected condition */
104#define LOGL_ERROR 7 /*!< error condition, requires user action */
105#define LOGL_FATAL 8 /*!< fatal, program aborted */
Harald Welte3ae27582010-03-26 21:24:24 +0800106
Neels Hofmeyre883de52019-11-20 04:28:52 +0100107/* logging subsystems defined by the library itself */
Harald Welte2d2e2cc2016-04-25 12:11:20 +0200108#define DLGLOBAL -1 /*!< global logging */
109#define DLLAPD -2 /*!< LAPD implementation */
110#define DLINP -3 /*!< (A-bis) Input sub-system */
111#define DLMUX -4 /*!< Osmocom Multiplex (Osmux) */
112#define DLMI -5 /*!< ISDN-layer below input sub-system */
113#define DLMIB -6 /*!< ISDN layer B-channel */
114#define DLSMS -7 /*!< SMS sub-system */
115#define DLCTRL -8 /*!< Control Interface */
116#define DLGTP -9 /*!< GTP (GPRS Tunneling Protocol */
117#define DLSTATS -10 /*!< Statistics */
Neels Hofmeyr9795cf12016-12-10 17:01:06 +0100118#define DLGSUP -11 /*!< Generic Subscriber Update Protocol */
Harald Weltec0f00072016-04-27 18:32:35 +0200119#define DLOAP -12 /*!< Osmocom Authentication Protocol */
Harald Welte62d32962017-04-03 19:37:11 +0200120#define DLSS7 -13 /*!< Osmocom SS7 */
121#define DLSCCP -14 /*!< Osmocom SCCP */
122#define DLSUA -15 /*!< Osmocom SUA */
123#define DLM3UA -16 /*!< Osmocom M3UA */
Neels Hofmeyra7ccf612017-07-11 18:43:09 +0200124#define DLMGCP -17 /*!< Osmocom MGCP */
Pau Espin Pedrol8fd85572018-02-27 19:43:10 +0100125#define DLJIBUF -18 /*!< Osmocom Jitter Buffer */
Harald Welteb99ed7f2018-08-13 20:54:44 +0200126#define DLRSPRO -19 /*!< Osmocom Remote SIM Protocol */
Alexander Couzens6a161492020-07-12 13:45:50 +0200127#define DLNS -20 /*!< Osmocom NS layer */
Harald Weltefde19ed2020-12-07 21:43:51 +0100128#define DLBSSGP -21 /*!< Osmocom BSSGP layer */
Alexander Couzens6cf65d92021-01-18 17:55:35 +0100129#define DLNSDATA -22 /*!< Osmocom NS layer data pdus */
130#define DLNSSIGNAL -23 /*!< Osmocom NS layer signal pdus */
131#define OSMO_NUM_DLIB 23 /*!< Number of logging sub-systems in libraries */
Harald Welteb43bc042011-06-27 10:29:17 +0200132
Neels Hofmeyrf2644ae2019-11-20 04:00:29 +0100133/* Colors that can be used in log_info_cat.color */
134#define OSMO_LOGCOLOR_NORMAL NULL
135#define OSMO_LOGCOLOR_RED "\033[1;31m"
136#define OSMO_LOGCOLOR_GREEN "\033[1;32m"
137#define OSMO_LOGCOLOR_YELLOW "\033[1;33m"
138#define OSMO_LOGCOLOR_BLUE "\033[1;34m"
139#define OSMO_LOGCOLOR_PURPLE "\033[1;35m"
140#define OSMO_LOGCOLOR_CYAN "\033[1;36m"
141#define OSMO_LOGCOLOR_DARKRED "\033[31m"
142#define OSMO_LOGCOLOR_DARKGREEN "\033[32m"
143#define OSMO_LOGCOLOR_DARKYELLOW "\033[33m"
144#define OSMO_LOGCOLOR_DARKBLUE "\033[34m"
145#define OSMO_LOGCOLOR_DARKPURPLE "\033[35m"
146#define OSMO_LOGCOLOR_DARKCYAN "\033[36m"
147#define OSMO_LOGCOLOR_DARKGREY "\033[1;30m"
148#define OSMO_LOGCOLOR_GREY "\033[37m"
149#define OSMO_LOGCOLOR_BRIGHTWHITE "\033[1;37m"
150#define OSMO_LOGCOLOR_END "\033[0;m"
151
Neels Hofmeyrfc47b032017-06-20 04:29:38 +0200152/*! Configuration of single log category / sub-system */
Harald Welte3ae27582010-03-26 21:24:24 +0800153struct log_category {
Harald Welte2d2e2cc2016-04-25 12:11:20 +0200154 uint8_t loglevel; /*!< configured log-level */
155 uint8_t enabled; /*!< is logging enabled? */
Harald Welte3ae27582010-03-26 21:24:24 +0800156};
157
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200158/*! Information regarding one logging category */
Harald Welte3ae27582010-03-26 21:24:24 +0800159struct log_info_cat {
Harald Welte18fc4652011-08-17 14:14:17 +0200160 const char *name; /*!< name of category */
161 const char *color; /*!< color string for cateyory */
162 const char *description; /*!< description text */
163 uint8_t loglevel; /*!< currently selected log-level */
164 uint8_t enabled; /*!< is this category enabled or not */
Harald Welte3ae27582010-03-26 21:24:24 +0800165};
166
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200167/*! Indexes to indicate the object currently acted upon.
Neels Hofmeyr492e1802017-02-23 17:45:26 +0100168 * Array indexes for the global \a log_context array. */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100169enum log_ctx_index {
170 LOG_CTX_GB_NSVC,
171 LOG_CTX_GB_BVC,
172 LOG_CTX_BSC_SUBSCR,
173 LOG_CTX_VLR_SUBSCR,
Oliver Smith210acc62019-09-12 17:13:34 +0200174 LOG_CTX_L1_SAPI,
Daniel Willmann751977b2020-12-02 18:59:44 +0100175 LOG_CTX_GB_NSE,
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100176 _LOG_CTX_COUNT
Neels Hofmeyr812ba6d2017-02-17 16:35:27 +0100177};
178
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200179/*! Indexes to indicate objects that should be logged.
Neels Hofmeyr492e1802017-02-23 17:45:26 +0100180 * Array indexes to log_target->filter_data and bit indexes for
181 * log_target->filter_map. */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100182enum log_filter_index {
183 LOG_FLT_ALL,
184 LOG_FLT_GB_NSVC,
185 LOG_FLT_GB_BVC,
186 LOG_FLT_BSC_SUBSCR,
187 LOG_FLT_VLR_SUBSCR,
Oliver Smith210acc62019-09-12 17:13:34 +0200188 LOG_FLT_L1_SAPI,
Daniel Willmann751977b2020-12-02 18:59:44 +0100189 LOG_FLT_GB_NSE,
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100190 _LOG_FLT_COUNT
Neels Hofmeyr812ba6d2017-02-17 16:35:27 +0100191};
192
Daniel Willmannfd3478c2020-12-02 18:14:17 +0100193/*! Maximum number of logging contexts */
194#define LOG_MAX_CTX _LOG_CTX_COUNT
195/*! Maximum number of logging filters */
196#define LOG_MAX_FILTERS _LOG_FLT_COUNT
197
198/*! Log context information, passed to filter */
199struct log_context {
200 void *ctx[LOG_MAX_CTX+1];
201};
202
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200203/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100204#define LOG_FILTER_ALL (1<<LOG_FLT_ALL)
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200205/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100206#define GPRS_CTX_NSVC LOG_CTX_GB_NSVC
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200207/*! Compatibility with older libosmocore versions */
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100208#define GPRS_CTX_BVC LOG_CTX_GB_BVC
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200209/*! Indexes to indicate the object currently acted upon.
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100210 * Array indexes for the global \a log_context array. */
Neels Hofmeyr0d6420b2017-02-23 17:34:35 +0100211
Harald Welte3ae27582010-03-26 21:24:24 +0800212struct log_target;
213
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200214/*! Log filter function */
Harald Welte3ae27582010-03-26 21:24:24 +0800215typedef int log_filter(const struct log_context *ctx,
216 struct log_target *target);
217
Harald Weltefb84f322013-06-06 07:33:54 +0200218struct log_info;
219struct vty;
Harald Welteaa00f992016-12-02 15:30:02 +0100220struct gsmtap_inst;
Harald Weltefb84f322013-06-06 07:33:54 +0200221
222typedef void log_print_filters(struct vty *vty,
223 const struct log_info *info,
224 const struct log_target *tgt);
225
226typedef void log_save_filters(struct vty *vty,
227 const struct log_info *info,
228 const struct log_target *tgt);
229
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200230/*! Logging configuration, passed to \ref log_init */
Harald Welte3ae27582010-03-26 21:24:24 +0800231struct log_info {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200232 /* filter callback function */
Harald Welte3ae27582010-03-26 21:24:24 +0800233 log_filter *filter_fn;
234
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200235 /*! per-category information */
Holger Hans Peter Freyther06f64552012-09-11 10:31:29 +0200236 const struct log_info_cat *cat;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200237 /*! total number of categories */
Harald Welte3ae27582010-03-26 21:24:24 +0800238 unsigned int num_cat;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200239 /*! total number of user categories (not library) */
Harald Welteb43bc042011-06-27 10:29:17 +0200240 unsigned int num_cat_user;
Harald Weltefb84f322013-06-06 07:33:54 +0200241
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200242 /*! filter saving function */
Harald Weltefb84f322013-06-06 07:33:54 +0200243 log_save_filters *save_fn;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200244 /*! filter saving function */
Harald Weltefb84f322013-06-06 07:33:54 +0200245 log_print_filters *print_fn;
Harald Welte3ae27582010-03-26 21:24:24 +0800246};
247
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200248/*! Type of logging target */
Harald Welte28222962011-02-18 20:37:04 +0100249enum log_target_type {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200250 LOG_TGT_TYPE_VTY, /*!< VTY logging */
251 LOG_TGT_TYPE_SYSLOG, /*!< syslog based logging */
252 LOG_TGT_TYPE_FILE, /*!< text file logging */
253 LOG_TGT_TYPE_STDERR, /*!< stderr logging */
254 LOG_TGT_TYPE_STRRB, /*!< osmo_strrb-backed logging */
255 LOG_TGT_TYPE_GSMTAP, /*!< GSMTAP network logging */
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +0700256 LOG_TGT_TYPE_SYSTEMD, /*!< systemd journal logging */
Harald Welte28222962011-02-18 20:37:04 +0100257};
258
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100259/*! Whether/how to log the source filename (and line number). */
260enum log_filename_type {
261 LOG_FILENAME_NONE,
262 LOG_FILENAME_PATH,
Neels Hofmeyr0e2a9432018-01-16 02:49:48 +0100263 LOG_FILENAME_BASENAME,
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100264};
265
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200266/*! Where on a log line source file and line should be logged. */
267enum log_filename_pos {
268 LOG_FILENAME_POS_HEADER_END,
269 LOG_FILENAME_POS_LINE_END,
270};
271
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200272/*! structure representing a logging target */
Harald Welte3ae27582010-03-26 21:24:24 +0800273struct log_target {
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200274 struct llist_head entry; /*!< linked list */
Harald Welte3ae27582010-03-26 21:24:24 +0800275
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200276 /*! Internal data for filtering */
Harald Welte3ae27582010-03-26 21:24:24 +0800277 int filter_map;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200278 /*! Internal data for filtering */
Harald Welte3ae27582010-03-26 21:24:24 +0800279 void *filter_data[LOG_MAX_FILTERS+1];
280
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200281 /*! logging categories */
Harald Welteb43bc042011-06-27 10:29:17 +0200282 struct log_category *categories;
283
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200284 /*! global log level */
Harald Welte3ae27582010-03-26 21:24:24 +0800285 uint8_t loglevel;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200286 /*! should color be used when printing log messages? */
Harald Welte87dbca12011-07-16 11:57:53 +0200287 unsigned int use_color:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200288 /*! should log messages be prefixed with a timestamp? */
Harald Welte87dbca12011-07-16 11:57:53 +0200289 unsigned int print_timestamp:1;
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +0100290 /*! should log messages be prefixed with the logger Thread ID? */
291 unsigned int print_tid:1;
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100292 /*! DEPRECATED: use print_filename2 instead. */
Holger Hans Peter Freytherdb153362012-09-11 11:24:51 +0200293 unsigned int print_filename:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200294 /*! should log messages be prefixed with a category name? */
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100295 unsigned int print_category:1;
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200296 /*! should log messages be prefixed with an extended timestamp? */
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100297 unsigned int print_ext_timestamp:1;
Harald Welte3ae27582010-03-26 21:24:24 +0800298
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200299 /*! the type of this log taget */
Harald Welte28222962011-02-18 20:37:04 +0100300 enum log_target_type type;
301
Harald Welte3ae27582010-03-26 21:24:24 +0800302 union {
303 struct {
Harald Welteb72867f2020-09-26 21:45:16 +0200304 /* direct, blocking output via stdio */
Harald Welte3ae27582010-03-26 21:24:24 +0800305 FILE *out;
Harald Welte72d0c532010-08-25 19:24:00 +0200306 const char *fname;
Harald Welteb72867f2020-09-26 21:45:16 +0200307 /* indirect output via write_queue and osmo_select_main() */
308 struct osmo_wqueue *wqueue;
Harald Welte0083cd32010-08-25 14:55:44 +0200309 } tgt_file;
Harald Welte3ae27582010-03-26 21:24:24 +0800310
311 struct {
312 int priority;
Harald Welte28222962011-02-18 20:37:04 +0100313 int facility;
Harald Welte3ae27582010-03-26 21:24:24 +0800314 } tgt_syslog;
315
316 struct {
317 void *vty;
318 } tgt_vty;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000319
320 struct {
321 void *rb;
322 } tgt_rb;
Harald Welteaa00f992016-12-02 15:30:02 +0100323
324 struct {
325 struct gsmtap_inst *gsmtap_inst;
326 const char *ident;
327 const char *hostname;
328 } tgt_gsmtap;
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +0700329
330 struct {
331 bool raw;
332 } sd_journal;
Harald Welte3ae27582010-03-26 21:24:24 +0800333 };
334
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200335 /*! call-back function to be called when the logging framework
Harald Welted7c0a372016-12-02 13:52:59 +0100336 * wants to log a fully formatted string
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +0100337 * \param[in] target logging target
Harald Welte18fc4652011-08-17 14:14:17 +0200338 * \param[in] level log level of currnet message
339 * \param[in] string the string that is to be written to the log
340 */
Harald Welte76e72ab2011-02-17 15:52:39 +0100341 void (*output) (struct log_target *target, unsigned int level,
342 const char *string);
Harald Welted7c0a372016-12-02 13:52:59 +0100343
Neels Hofmeyr87e45502017-06-20 00:17:59 +0200344 /*! alternative call-back function to which the logging
Harald Welted7c0a372016-12-02 13:52:59 +0100345 * framework passes the unfortmatted input arguments,
346 * i.e. bypassing the internal string formatter
347 * \param[in] target logging target
348 * \param[in] subsys logging sub-system
349 * \param[in] level logging level
350 * \param[in] file soure code file name
351 * \param[in] line source code file line number
352 * \param[in] cont continuation of previous statement?
353 * \param[in] format format string
354 * \param[in] ap vararg list of printf arguments
355 */
356 void (*raw_output)(struct log_target *target, int subsys,
357 unsigned int level, const char *file, int line,
358 int cont, const char *format, va_list ap);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100359
360 /* Should the log level be printed? */
361 bool print_level;
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100362 /* Should we print the subsys in hex like '<000b>'? */
363 bool print_category_hex;
364 /* Should we print the source file and line, and in which way? */
365 enum log_filename_type print_filename2;
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200366 /* Where on a log line to put the source file info. */
367 enum log_filename_pos print_filename_pos;
Harald Welte3ae27582010-03-26 21:24:24 +0800368};
369
370/* use the above macros */
Andreas Eversberg2d6563b2012-07-10 13:10:15 +0200371void logp2(int subsys, unsigned int level, const char *file,
Harald Welte3ae27582010-03-26 21:24:24 +0800372 int line, int cont, const char *format, ...)
373 __attribute__ ((format (printf, 6, 7)));
Harald Welteb43bc042011-06-27 10:29:17 +0200374int log_init(const struct log_info *inf, void *talloc_ctx);
Harald Welte69e6c3c2016-04-20 10:41:27 +0200375void log_fini(void);
Jacob Erlbeckde6dd722015-11-17 11:52:24 +0100376int log_check_level(int subsys, unsigned int level);
Harald Welte3ae27582010-03-26 21:24:24 +0800377
378/* context management */
379void log_reset_context(void);
380int log_set_context(uint8_t ctx, void *value);
381
382/* filter on the targets */
383void log_set_all_filter(struct log_target *target, int);
384
385void log_set_use_color(struct log_target *target, int);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100386void log_set_print_extended_timestamp(struct log_target *target, int);
Harald Welte3ae27582010-03-26 21:24:24 +0800387void log_set_print_timestamp(struct log_target *target, int);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +0100388void log_set_print_tid(struct log_target *target, int);
Pau Espin Pedrol6e9dd022021-02-18 19:27:38 +0100389void log_set_print_filename(struct log_target *target, int) OSMO_DEPRECATED("Use log_set_print_filename2() instead");
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100390void log_set_print_filename2(struct log_target *target, enum log_filename_type lft);
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200391void log_set_print_filename_pos(struct log_target *target, enum log_filename_pos pos);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100392void log_set_print_category(struct log_target *target, int);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100393void log_set_print_category_hex(struct log_target *target, int);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100394void log_set_print_level(struct log_target *target, int);
Harald Welte3ae27582010-03-26 21:24:24 +0800395void log_set_log_level(struct log_target *target, int log_level);
396void log_parse_category_mask(struct log_target *target, const char* mask);
Harald Welteaa00f992016-12-02 15:30:02 +0100397const char* log_category_name(int subsys);
Max15b6d412017-07-06 16:57:15 +0200398int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
399const char *log_level_str(unsigned int lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
Harald Welte3ae27582010-03-26 21:24:24 +0800400int log_parse_category(const char *category);
401void log_set_category_filter(struct log_target *target, int category,
402 int enable, int level);
403
404/* management of the targets */
405struct log_target *log_target_create(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200406void log_target_destroy(struct log_target *target);
Harald Welte3ae27582010-03-26 21:24:24 +0800407struct log_target *log_target_create_stderr(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200408struct log_target *log_target_create_file(const char *fname);
Harald Welte46cfd772011-02-17 15:56:56 +0100409struct log_target *log_target_create_syslog(const char *ident, int option,
410 int facility);
Harald Welteaa00f992016-12-02 15:30:02 +0100411struct log_target *log_target_create_gsmtap(const char *host, uint16_t port,
412 const char *ident,
413 bool ofd_wq_mode,
414 bool add_sink);
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +0700415struct log_target *log_target_create_systemd(bool raw);
416void log_target_systemd_set_raw(struct log_target *target, bool raw);
Harald Welte72d0c532010-08-25 19:24:00 +0200417int log_target_file_reopen(struct log_target *tgt);
Harald Welteb72867f2020-09-26 21:45:16 +0200418int log_target_file_switch_to_stream(struct log_target *tgt);
419int log_target_file_switch_to_wqueue(struct log_target *tgt);
Harald Welte4de854d2013-03-18 19:01:40 +0100420int log_targets_reopen(void);
Harald Welte72d0c532010-08-25 19:24:00 +0200421
Harald Welte3ae27582010-03-26 21:24:24 +0800422void log_add_target(struct log_target *target);
423void log_del_target(struct log_target *target);
424
Harald Welte28222962011-02-18 20:37:04 +0100425struct log_target *log_target_find(int type, const char *fname);
Harald Welte28222962011-02-18 20:37:04 +0100426
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200427void log_enable_multithread(void);
428
429void log_tgt_mutex_lock_impl(void);
430void log_tgt_mutex_unlock_impl(void);
431#define LOG_MTX_DEBUG 0
432#if LOG_MTX_DEBUG
433 #include <pthread.h>
434 #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)
435 #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)
436#else
437 #define log_tgt_mutex_lock() log_tgt_mutex_lock_impl()
438 #define log_tgt_mutex_unlock() log_tgt_mutex_unlock_impl()
439#endif
440
Sylvain Munautdca7d2c2012-04-18 21:53:23 +0200441/*! @} */