Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file logging.c |
| 2 | * Debugging/Logging support code. */ |
| 3 | /* |
| 4 | * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 5 | * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | * |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | * |
| 24 | */ |
| 25 | |
Harald Welte | f01b238 | 2017-10-16 13:55:34 +0200 | [diff] [blame] | 26 | /*! \addtogroup logging |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 27 | * @{ |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 28 | * libosmocore Logging sub-system |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 29 | * |
| 30 | * \file logging.c */ |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 31 | |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 32 | #include "../config.h" |
| 33 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 34 | #include <stdarg.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <stdio.h> |
| 37 | #include <string.h> |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 38 | |
| 39 | #ifdef HAVE_STRINGS_H |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 40 | #include <strings.h> |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 41 | #endif |
Vadim Yanitskiy | 04f4271 | 2020-09-09 04:47:25 +0700 | [diff] [blame] | 42 | |
| 43 | #ifdef HAVE_SYSLOG_H |
| 44 | #include <syslog.h> |
| 45 | #endif |
| 46 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 47 | #include <time.h> |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 48 | #include <sys/time.h> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 49 | #include <errno.h> |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 50 | #include <pthread.h> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 51 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 52 | #include <osmocom/core/talloc.h> |
| 53 | #include <osmocom/core/utils.h> |
| 54 | #include <osmocom/core/logging.h> |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 55 | #include <osmocom/core/timer.h> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 56 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 57 | #include <osmocom/vty/logging.h> /* for LOGGING_STR. */ |
| 58 | |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 59 | osmo_static_assert(_LOG_CTX_COUNT <= ARRAY_SIZE(((struct log_context*)NULL)->ctx), |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 60 | enum_logging_ctx_items_fit_in_struct_log_context); |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 61 | osmo_static_assert(_LOG_FLT_COUNT <= ARRAY_SIZE(((struct log_target*)NULL)->filter_data), |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 62 | enum_logging_filters_fit_in_log_target_filter_data); |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 63 | osmo_static_assert(_LOG_FLT_COUNT <= 8*sizeof(((struct log_target*)NULL)->filter_map), |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 64 | enum_logging_filters_fit_in_log_target_filter_map); |
| 65 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 66 | struct log_info *osmo_log_info; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 67 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 68 | static struct log_context log_context; |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 69 | void *tall_log_ctx = NULL; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 70 | LLIST_HEAD(osmo_log_target_list); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 71 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 72 | #if (!EMBEDDED) |
| 73 | /*! This mutex must be held while using osmo_log_target_list or any of its |
| 74 | log_targets in a multithread program. Prevents race conditions between threads |
| 75 | like producing unordered timestamps or VTY deleting a target while another |
| 76 | thread is writing to it */ |
| 77 | static pthread_mutex_t osmo_log_tgt_mutex; |
| 78 | static bool osmo_log_tgt_mutex_on = false; |
| 79 | |
| 80 | /*! Enable multithread support (mutex) in libosmocore logging system. |
| 81 | * Must be called by processes willing to use logging subsystem from several |
| 82 | * threads. Once enabled, it's not possible to disable it again. |
| 83 | */ |
| 84 | void log_enable_multithread(void) { |
| 85 | if (osmo_log_tgt_mutex_on) |
| 86 | return; |
| 87 | pthread_mutex_init(&osmo_log_tgt_mutex, NULL); |
| 88 | osmo_log_tgt_mutex_on = true; |
| 89 | } |
| 90 | |
| 91 | /*! Acquire the osmo_log_tgt_mutex. Don't use this function directly, always use |
| 92 | * macro log_tgt_mutex_lock() instead. |
| 93 | */ |
| 94 | void log_tgt_mutex_lock_impl(void) { |
| 95 | /* These lines are useful to debug scenarios where there's only 1 thread |
| 96 | and a double lock appears, for instance during startup and some |
| 97 | unlock() missing somewhere: |
| 98 | if (osmo_log_tgt_mutex_on && pthread_mutex_trylock(&osmo_log_tgt_mutex) != 0) |
| 99 | osmo_panic("acquiring already locked mutex!\n"); |
| 100 | return; |
| 101 | */ |
| 102 | |
| 103 | if (osmo_log_tgt_mutex_on) |
| 104 | pthread_mutex_lock(&osmo_log_tgt_mutex); |
| 105 | } |
| 106 | |
| 107 | /*! Release the osmo_log_tgt_mutex. Don't use this function directly, always use |
| 108 | * macro log_tgt_mutex_unlock() instead. |
| 109 | */ |
| 110 | void log_tgt_mutex_unlock_impl(void) { |
| 111 | if (osmo_log_tgt_mutex_on) |
| 112 | pthread_mutex_unlock(&osmo_log_tgt_mutex); |
| 113 | } |
| 114 | |
| 115 | #else /* if (!EMBEDDED) */ |
| 116 | #pragma message ("logging multithread support disabled in embedded build") |
| 117 | void log_enable_multithread(void) {} |
| 118 | void log_tgt_mutex_lock_impl(void) {} |
| 119 | void log_tgt_mutex_unlock_impl(void) {} |
| 120 | #endif /* if (!EMBEDDED) */ |
| 121 | |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 122 | const struct value_string loglevel_strs[] = { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 123 | { LOGL_DEBUG, "DEBUG" }, |
| 124 | { LOGL_INFO, "INFO" }, |
| 125 | { LOGL_NOTICE, "NOTICE" }, |
| 126 | { LOGL_ERROR, "ERROR" }, |
| 127 | { LOGL_FATAL, "FATAL" }, |
| 128 | { 0, NULL }, |
| 129 | }; |
| 130 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 131 | #define INT2IDX(x) (-1*(x)-1) |
| 132 | static const struct log_info_cat internal_cat[OSMO_NUM_DLIB] = { |
| 133 | [INT2IDX(DLGLOBAL)] = { /* -1 becomes 0 */ |
| 134 | .name = "DLGLOBAL", |
| 135 | .description = "Library-internal global log family", |
| 136 | .loglevel = LOGL_NOTICE, |
| 137 | .enabled = 1, |
| 138 | }, |
root | 8a996b4 | 2011-09-26 11:22:21 +0200 | [diff] [blame] | 139 | [INT2IDX(DLLAPD)] = { /* -2 becomes 1 */ |
| 140 | .name = "DLLAPD", |
| 141 | .description = "LAPD in libosmogsm", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 142 | .loglevel = LOGL_NOTICE, |
| 143 | .enabled = 1, |
| 144 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 145 | [INT2IDX(DLINP)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 146 | .name = "DLINP", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 147 | .description = "A-bis Intput Subsystem", |
| 148 | .loglevel = LOGL_NOTICE, |
| 149 | .enabled = 1, |
| 150 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 151 | [INT2IDX(DLMUX)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 152 | .name = "DLMUX", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 153 | .description = "A-bis B-Subchannel TRAU Frame Multiplex", |
| 154 | .loglevel = LOGL_NOTICE, |
| 155 | .enabled = 1, |
| 156 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 157 | [INT2IDX(DLMI)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 158 | .name = "DLMI", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 159 | .description = "A-bis Input Driver for Signalling", |
| 160 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 161 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 162 | [INT2IDX(DLMIB)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 163 | .name = "DLMIB", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 164 | .description = "A-bis Input Driver for B-Channels (voice)", |
| 165 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 166 | }, |
Andreas Eversberg | c626da9 | 2011-10-28 03:53:50 +0200 | [diff] [blame] | 167 | [INT2IDX(DLSMS)] = { |
| 168 | .name = "DLSMS", |
| 169 | .description = "Layer3 Short Message Service (SMS)", |
| 170 | .enabled = 1, .loglevel = LOGL_NOTICE, |
Neels Hofmeyr | c5b7175 | 2019-11-20 04:50:52 +0100 | [diff] [blame] | 171 | .color = OSMO_LOGCOLOR_BRIGHTWHITE, |
Andreas Eversberg | c626da9 | 2011-10-28 03:53:50 +0200 | [diff] [blame] | 172 | }, |
Harald Welte | 7fd0c83 | 2014-08-20 19:58:13 +0200 | [diff] [blame] | 173 | [INT2IDX(DLCTRL)] = { |
| 174 | .name = "DLCTRL", |
| 175 | .description = "Control Interface", |
| 176 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 177 | }, |
Holger Hans Peter Freyther | a5dc19d | 2014-12-04 14:35:21 +0100 | [diff] [blame] | 178 | [INT2IDX(DLGTP)] = { |
| 179 | .name = "DLGTP", |
| 180 | .description = "GPRS GTP library", |
| 181 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 182 | }, |
Jacob Erlbeck | 79125ec | 2015-11-02 15:17:50 +0100 | [diff] [blame] | 183 | [INT2IDX(DLSTATS)] = { |
| 184 | .name = "DLSTATS", |
| 185 | .description = "Statistics messages and logging", |
| 186 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 187 | }, |
Neels Hofmeyr | 9795cf1 | 2016-12-10 17:01:06 +0100 | [diff] [blame] | 188 | [INT2IDX(DLGSUP)] = { |
| 189 | .name = "DLGSUP", |
| 190 | .description = "Generic Subscriber Update Protocol", |
| 191 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 192 | }, |
Harald Welte | c0f0007 | 2016-04-27 18:32:35 +0200 | [diff] [blame] | 193 | [INT2IDX(DLOAP)] = { |
| 194 | .name = "DLOAP", |
| 195 | .description = "Osmocom Authentication Protocol", |
| 196 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 197 | }, |
Harald Welte | 059c404 | 2017-04-03 22:20:49 +0200 | [diff] [blame] | 198 | [INT2IDX(DLSS7)] = { |
| 199 | .name = "DLSS7", |
| 200 | .description = "libosmo-sigtran Signalling System 7", |
| 201 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 202 | }, |
| 203 | [INT2IDX(DLSCCP)] = { |
| 204 | .name = "DLSCCP", |
| 205 | .description = "libosmo-sigtran SCCP Implementation", |
| 206 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 207 | }, |
| 208 | [INT2IDX(DLSUA)] = { |
| 209 | .name = "DLSUA", |
| 210 | .description = "libosmo-sigtran SCCP User Adaptation", |
| 211 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 212 | }, |
| 213 | [INT2IDX(DLM3UA)] = { |
| 214 | .name = "DLM3UA", |
| 215 | .description = "libosmo-sigtran MTP3 User Adaptation", |
| 216 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 217 | }, |
Neels Hofmeyr | a7ccf61 | 2017-07-11 18:43:09 +0200 | [diff] [blame] | 218 | [INT2IDX(DLMGCP)] = { |
| 219 | .name = "DLMGCP", |
| 220 | .description = "libosmo-mgcp Media Gateway Control Protocol", |
| 221 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 222 | }, |
Pau Espin Pedrol | 8fd8557 | 2018-02-27 19:43:10 +0100 | [diff] [blame] | 223 | [INT2IDX(DLJIBUF)] = { |
| 224 | .name = "DLJIBUF", |
| 225 | .description = "libosmo-netif Jitter Buffer", |
| 226 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 227 | }, |
Max | 450f5ac | 2019-02-14 19:12:03 +0100 | [diff] [blame] | 228 | [INT2IDX(DLRSPRO)] = { |
| 229 | .name = "DLRSPRO", |
| 230 | .description = "Remote SIM protocol", |
| 231 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 232 | }, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 233 | [INT2IDX(DLNS)] = { |
| 234 | .name = "DLNS", |
| 235 | .description = "GPRS NS layer", |
| 236 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 237 | }, |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 238 | }; |
| 239 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 240 | void assert_loginfo(const char *src) |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 241 | { |
| 242 | if (!osmo_log_info) { |
| 243 | fprintf(stderr, "ERROR: osmo_log_info == NULL! " |
Max | 68bf16a | 2018-01-10 17:00:43 +0100 | [diff] [blame] | 244 | "You must call log_init() before using logging in %s()!\n", src); |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 245 | OSMO_ASSERT(osmo_log_info); |
| 246 | } |
| 247 | } |
| 248 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 249 | /* special magic for negative (library-internal) log subsystem numbers */ |
| 250 | static int subsys_lib2index(int subsys) |
| 251 | { |
| 252 | return (subsys * -1) + (osmo_log_info->num_cat_user-1); |
| 253 | } |
| 254 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 255 | /*! Parse a human-readable log level into a numeric value |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 256 | * \param[in] lvl zero-terminated string containing log level name |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 257 | * \returns numeric log level |
| 258 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 259 | int log_parse_level(const char *lvl) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 260 | { |
| 261 | return get_string_value(loglevel_strs, lvl); |
| 262 | } |
| 263 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 264 | /*! convert a numeric log level into human-readable string |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 265 | * \param[in] lvl numeric log level |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 266 | * \returns zero-terminated string (log level name) |
| 267 | */ |
Harald Welte | 9ac2225 | 2010-05-11 11:19:40 +0200 | [diff] [blame] | 268 | const char *log_level_str(unsigned int lvl) |
| 269 | { |
| 270 | return get_value_string(loglevel_strs, lvl); |
| 271 | } |
| 272 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 273 | /*! parse a human-readable log category into numeric form |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 274 | * \param[in] category human-readable log category name |
| 275 | * \returns numeric category value, or -EINVAL otherwise |
| 276 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 277 | int log_parse_category(const char *category) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 278 | { |
| 279 | int i; |
| 280 | |
Max | 68bf16a | 2018-01-10 17:00:43 +0100 | [diff] [blame] | 281 | assert_loginfo(__func__); |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 282 | |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 283 | for (i = 0; i < osmo_log_info->num_cat; ++i) { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 284 | if (osmo_log_info->cat[i].name == NULL) |
| 285 | continue; |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 286 | if (!strcasecmp(osmo_log_info->cat[i].name+1, category)) |
Harald Welte | faadfe2 | 2010-03-26 21:05:43 +0800 | [diff] [blame] | 287 | return i; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 293 | /*! parse the log category mask |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 294 | * \param[in] target log target to be configured |
| 295 | * \param[in] _mask log category mask string |
| 296 | * |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 297 | * The format can be this: category1:category2:category3 |
| 298 | * or category1,2:category2,3:... |
| 299 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 300 | void log_parse_category_mask(struct log_target* target, const char *_mask) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 301 | { |
| 302 | int i = 0; |
| 303 | char *mask = strdup(_mask); |
| 304 | char *category_token = NULL; |
| 305 | |
Max | 68bf16a | 2018-01-10 17:00:43 +0100 | [diff] [blame] | 306 | assert_loginfo(__func__); |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 307 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 308 | /* Disable everything to enable it afterwards */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 309 | for (i = 0; i < osmo_log_info->num_cat; ++i) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 310 | target->categories[i].enabled = 0; |
| 311 | |
| 312 | category_token = strtok(mask, ":"); |
Neels Hofmeyr | da1b20c | 2016-04-14 15:12:16 +0200 | [diff] [blame] | 313 | OSMO_ASSERT(category_token); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 314 | do { |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 315 | for (i = 0; i < osmo_log_info->num_cat; ++i) { |
Nico Golde | 0262d3f | 2012-09-21 17:44:58 +0200 | [diff] [blame] | 316 | size_t length, cat_length; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 317 | char* colon = strstr(category_token, ","); |
Nico Golde | 0262d3f | 2012-09-21 17:44:58 +0200 | [diff] [blame] | 318 | |
| 319 | if (!osmo_log_info->cat[i].name) |
| 320 | continue; |
| 321 | |
| 322 | length = strlen(category_token); |
| 323 | cat_length = strlen(osmo_log_info->cat[i].name); |
Pablo Neira Ayuso | 300e78d | 2011-08-11 13:24:18 +0200 | [diff] [blame] | 324 | |
| 325 | /* Use longest length not to match subocurrences. */ |
| 326 | if (cat_length > length) |
| 327 | length = cat_length; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 328 | |
| 329 | if (colon) |
| 330 | length = colon - category_token; |
| 331 | |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 332 | if (strncasecmp(osmo_log_info->cat[i].name, |
| 333 | category_token, length) == 0) { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 334 | int level = 0; |
| 335 | |
| 336 | if (colon) |
| 337 | level = atoi(colon+1); |
| 338 | |
Harald Welte | faadfe2 | 2010-03-26 21:05:43 +0800 | [diff] [blame] | 339 | target->categories[i].enabled = 1; |
| 340 | target->categories[i].loglevel = level; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } while ((category_token = strtok(NULL, ":"))); |
| 344 | |
| 345 | free(mask); |
| 346 | } |
| 347 | |
| 348 | static const char* color(int subsys) |
| 349 | { |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 350 | if (subsys < osmo_log_info->num_cat) |
| 351 | return osmo_log_info->cat[subsys].color; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 352 | |
Harald Welte | d788f66 | 2010-03-26 09:45:03 +0800 | [diff] [blame] | 353 | return NULL; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 354 | } |
| 355 | |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 356 | static const struct value_string level_colors[] = { |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 357 | { LOGL_DEBUG, OSMO_LOGCOLOR_BLUE }, |
| 358 | { LOGL_INFO, OSMO_LOGCOLOR_GREEN }, |
| 359 | { LOGL_NOTICE, OSMO_LOGCOLOR_YELLOW }, |
| 360 | { LOGL_ERROR, OSMO_LOGCOLOR_RED }, |
| 361 | { LOGL_FATAL, OSMO_LOGCOLOR_RED }, |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 362 | { 0, NULL } |
| 363 | }; |
| 364 | |
| 365 | static const char *level_color(int level) |
| 366 | { |
| 367 | const char *c = get_value_string_or_null(level_colors, level); |
| 368 | if (!c) |
| 369 | return get_value_string(level_colors, LOGL_FATAL); |
| 370 | return c; |
| 371 | } |
| 372 | |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 373 | const char* log_category_name(int subsys) |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 374 | { |
| 375 | if (subsys < osmo_log_info->num_cat) |
| 376 | return osmo_log_info->cat[subsys].name; |
| 377 | |
| 378 | return NULL; |
| 379 | } |
| 380 | |
Neels Hofmeyr | 0e2a943 | 2018-01-16 02:49:48 +0100 | [diff] [blame] | 381 | static const char *const_basename(const char *path) |
| 382 | { |
| 383 | const char *bn = strrchr(path, '/'); |
| 384 | if (!bn || !bn[1]) |
| 385 | return path; |
| 386 | return bn + 1; |
| 387 | } |
| 388 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 389 | static void _output(struct log_target *target, unsigned int subsys, |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 390 | unsigned int level, const char *file, int line, int cont, |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 391 | const char *format, va_list ap) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 392 | { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 393 | char buf[4096]; |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 394 | int ret, len = 0, offset = 0, rem = sizeof(buf); |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 395 | const char *c_subsys = NULL; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 396 | |
| 397 | /* are we using color */ |
| 398 | if (target->use_color) { |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 399 | c_subsys = color(subsys); |
| 400 | if (c_subsys) { |
Neels Hofmeyr | 5e518b5 | 2018-01-17 13:20:02 +0100 | [diff] [blame] | 401 | ret = snprintf(buf + offset, rem, "%s", c_subsys); |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 402 | if (ret < 0) |
| 403 | goto err; |
| 404 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | d788f66 | 2010-03-26 09:45:03 +0800 | [diff] [blame] | 405 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 406 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 407 | if (!cont) { |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 408 | if (target->print_ext_timestamp) { |
Harald Welte | 14c4c49 | 2018-06-28 08:28:52 +0200 | [diff] [blame] | 409 | #ifdef HAVE_LOCALTIME_R |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 410 | struct tm tm; |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 411 | struct timeval tv; |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 412 | osmo_gettimeofday(&tv, NULL); |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 413 | localtime_r(&tv.tv_sec, &tm); |
| 414 | ret = snprintf(buf + offset, rem, "%04d%02d%02d%02d%02d%02d%03d ", |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 415 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 416 | tm.tm_hour, tm.tm_min, tm.tm_sec, |
| 417 | (int)(tv.tv_usec / 1000)); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 418 | if (ret < 0) |
| 419 | goto err; |
| 420 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 14c4c49 | 2018-06-28 08:28:52 +0200 | [diff] [blame] | 421 | #endif |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 422 | } else if (target->print_timestamp) { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 423 | time_t tm; |
Pau Espin Pedrol | 3aef238 | 2019-06-12 18:50:29 +0200 | [diff] [blame] | 424 | if ((tm = time(NULL)) == (time_t) -1) |
| 425 | goto err; |
Pau Espin Pedrol | cc794e9 | 2019-06-12 16:22:53 +0200 | [diff] [blame] | 426 | /* Get human-readable representation of time. |
| 427 | man ctime: we need at least 26 bytes in buf */ |
| 428 | if (rem < 26 || !ctime_r(&tm, buf + offset)) |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 429 | goto err; |
Pau Espin Pedrol | cc794e9 | 2019-06-12 16:22:53 +0200 | [diff] [blame] | 430 | ret = strlen(buf + offset); |
| 431 | if (ret <= 0) |
| 432 | goto err; |
| 433 | /* Get rid of useless final '\n' added by ctime_r. We want a space instead. */ |
| 434 | buf[offset + ret - 1] = ' '; |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 435 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 436 | } |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 437 | if (target->print_category) { |
Neels Hofmeyr | e653472 | 2018-01-16 03:02:06 +0100 | [diff] [blame] | 438 | ret = snprintf(buf + offset, rem, "%s%s%s%s ", |
| 439 | target->use_color ? level_color(level) : "", |
| 440 | log_category_name(subsys), |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 441 | target->use_color ? OSMO_LOGCOLOR_END : "", |
Neels Hofmeyr | e653472 | 2018-01-16 03:02:06 +0100 | [diff] [blame] | 442 | c_subsys ? c_subsys : ""); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 443 | if (ret < 0) |
| 444 | goto err; |
| 445 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 446 | } |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 447 | if (target->print_level) { |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 448 | ret = snprintf(buf + offset, rem, "%s%s%s%s ", |
| 449 | target->use_color ? level_color(level) : "", |
| 450 | log_level_str(level), |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 451 | target->use_color ? OSMO_LOGCOLOR_END : "", |
Neels Hofmeyr | f3fa369 | 2018-01-16 02:56:01 +0100 | [diff] [blame] | 452 | c_subsys ? c_subsys : ""); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 453 | if (ret < 0) |
| 454 | goto err; |
| 455 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 456 | } |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 457 | if (target->print_category_hex) { |
| 458 | ret = snprintf(buf + offset, rem, "<%4.4x> ", subsys); |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 459 | if (ret < 0) |
| 460 | goto err; |
| 461 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 462 | } |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 463 | |
| 464 | if (target->print_filename_pos == LOG_FILENAME_POS_HEADER_END) { |
| 465 | switch (target->print_filename2) { |
| 466 | case LOG_FILENAME_NONE: |
| 467 | break; |
| 468 | case LOG_FILENAME_PATH: |
| 469 | ret = snprintf(buf + offset, rem, "%s:%d ", file, line); |
| 470 | if (ret < 0) |
| 471 | goto err; |
| 472 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 473 | break; |
| 474 | case LOG_FILENAME_BASENAME: |
| 475 | ret = snprintf(buf + offset, rem, "%s:%d ", const_basename(file), line); |
| 476 | if (ret < 0) |
| 477 | goto err; |
| 478 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 479 | break; |
| 480 | } |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 481 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 482 | } |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 483 | ret = vsnprintf(buf + offset, rem, format, ap); |
| 484 | if (ret < 0) |
| 485 | goto err; |
| 486 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 487 | |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 488 | /* For LOG_FILENAME_POS_LAST, print the source file info only when the caller ended the log |
| 489 | * message in '\n'. If so, nip the last '\n' away, insert the source file info and re-append an |
| 490 | * '\n'. All this to allow LOGP("start..."); LOGPC("...end\n") constructs. */ |
| 491 | if (target->print_filename_pos == LOG_FILENAME_POS_LINE_END |
| 492 | && offset > 0 && buf[offset-1] == '\n') { |
| 493 | switch (target->print_filename2) { |
| 494 | case LOG_FILENAME_NONE: |
| 495 | break; |
| 496 | case LOG_FILENAME_PATH: |
| 497 | offset --; |
| 498 | ret = snprintf(buf + offset, rem, " (%s:%d)\n", file, line); |
| 499 | if (ret < 0) |
| 500 | goto err; |
| 501 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 502 | break; |
| 503 | case LOG_FILENAME_BASENAME: |
| 504 | offset --; |
| 505 | ret = snprintf(buf + offset, rem, " (%s:%d)\n", const_basename(file), line); |
| 506 | if (ret < 0) |
| 507 | goto err; |
| 508 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | |
Pau Espin Pedrol | 6407c82 | 2020-07-20 16:41:44 +0200 | [diff] [blame] | 513 | if (target->use_color && c_subsys) { |
Neels Hofmeyr | f2644ae | 2019-11-20 04:00:29 +0100 | [diff] [blame] | 514 | ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END); |
Neels Hofmeyr | c475988 | 2018-01-16 02:10:48 +0100 | [diff] [blame] | 515 | if (ret < 0) |
| 516 | goto err; |
| 517 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 518 | } |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 519 | err: |
| 520 | buf[sizeof(buf)-1] = '\0'; |
| 521 | target->output(target, level, buf); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 522 | } |
| 523 | |
Neels Hofmeyr | 42240de | 2016-12-12 15:13:56 +0100 | [diff] [blame] | 524 | /* Catch internal logging category indexes as well as out-of-bounds indexes. |
| 525 | * For internal categories, the ID is negative starting with -1; and internal |
| 526 | * logging categories are added behind the user categories. For out-of-bounds |
| 527 | * indexes, return the index of DLGLOBAL. The returned category index is |
| 528 | * guaranteed to exist in osmo_log_info, otherwise the program would abort, |
| 529 | * which should never happen unless even the DLGLOBAL category is missing. */ |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 530 | static inline int map_subsys(int subsys) |
| 531 | { |
Neels Hofmeyr | 7480226 | 2016-12-12 16:00:24 +0100 | [diff] [blame] | 532 | /* Note: comparing signed and unsigned integers */ |
| 533 | |
| 534 | if (subsys > 0 && ((unsigned int)subsys) >= osmo_log_info->num_cat_user) |
| 535 | subsys = DLGLOBAL; |
| 536 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 537 | if (subsys < 0) |
| 538 | subsys = subsys_lib2index(subsys); |
| 539 | |
Neels Hofmeyr | ca13574 | 2016-12-12 14:18:54 +0100 | [diff] [blame] | 540 | if (subsys < 0 || subsys >= osmo_log_info->num_cat) |
Neels Hofmeyr | 42240de | 2016-12-12 15:13:56 +0100 | [diff] [blame] | 541 | subsys = subsys_lib2index(DLGLOBAL); |
| 542 | |
Neels Hofmeyr | ca13574 | 2016-12-12 14:18:54 +0100 | [diff] [blame] | 543 | OSMO_ASSERT(!(subsys < 0 || subsys >= osmo_log_info->num_cat)); |
| 544 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 545 | return subsys; |
| 546 | } |
| 547 | |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 548 | static inline bool should_log_to_target(struct log_target *tar, int subsys, |
| 549 | int level) |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 550 | { |
| 551 | struct log_category *category; |
| 552 | |
| 553 | category = &tar->categories[subsys]; |
| 554 | |
| 555 | /* subsystem is not supposed to be logged */ |
| 556 | if (!category->enabled) |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 557 | return false; |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 558 | |
| 559 | /* Check the global log level */ |
| 560 | if (tar->loglevel != 0 && level < tar->loglevel) |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 561 | return false; |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 562 | |
| 563 | /* Check the category log level */ |
| 564 | if (tar->loglevel == 0 && category->loglevel != 0 && |
| 565 | level < category->loglevel) |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 566 | return false; |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 567 | |
Holger Hans Peter Freyther | 79599ac | 2016-01-15 16:49:06 +0100 | [diff] [blame] | 568 | /* Apply filters here... if that becomes messy we will |
| 569 | * need to put filters in a list and each filter will |
| 570 | * say stop, continue, output */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 571 | if ((tar->filter_map & (1 << LOG_FLT_ALL)) != 0) |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 572 | return true; |
Holger Hans Peter Freyther | 79599ac | 2016-01-15 16:49:06 +0100 | [diff] [blame] | 573 | |
| 574 | if (osmo_log_info->filter_fn) |
| 575 | return osmo_log_info->filter_fn(&log_context, tar); |
| 576 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 577 | /* TODO: Check the filter/selector too? */ |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 578 | return true; |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 581 | /*! vararg version of logging function |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 582 | * \param[in] subsys Logging sub-system |
| 583 | * \param[in] level Log level |
| 584 | * \param[in] file name of source code file |
| 585 | * \param[in] cont continuation (1) or new line (0) |
| 586 | * \param[in] format format string |
| 587 | * \param[in] ap vararg-list containing format string arguments |
| 588 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 589 | void osmo_vlogp(int subsys, int level, const char *file, int line, |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 590 | int cont, const char *format, va_list ap) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 591 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 592 | struct log_target *tar; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 593 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 594 | subsys = map_subsys(subsys); |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 595 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 596 | log_tgt_mutex_lock(); |
| 597 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 598 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 599 | va_list bp; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 600 | |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 601 | if (!should_log_to_target(tar, subsys, level)) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 602 | continue; |
| 603 | |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 604 | /* According to the manpage, vsnprintf leaves the value of ap |
| 605 | * in undefined state. Since _output uses vsnprintf and it may |
| 606 | * be called several times, we have to pass a copy of ap. */ |
| 607 | va_copy(bp, ap); |
Harald Welte | d7c0a37 | 2016-12-02 13:52:59 +0100 | [diff] [blame] | 608 | if (tar->raw_output) |
| 609 | tar->raw_output(tar, subsys, level, file, line, cont, format, bp); |
| 610 | else |
| 611 | _output(tar, subsys, level, file, line, cont, format, bp); |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 612 | va_end(bp); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 613 | } |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 614 | |
| 615 | log_tgt_mutex_unlock(); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 616 | } |
| 617 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 618 | /*! logging function used by DEBUGP() macro |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 619 | * \param[in] subsys Logging sub-system |
| 620 | * \param[in] file name of source code file |
| 621 | * \param[in] cont continuation (1) or new line (0) |
| 622 | * \param[in] format format string |
| 623 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 624 | void logp(int subsys, const char *file, int line, int cont, |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 625 | const char *format, ...) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 626 | { |
| 627 | va_list ap; |
| 628 | |
| 629 | va_start(ap, format); |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 630 | osmo_vlogp(subsys, LOGL_DEBUG, file, line, cont, format, ap); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 631 | va_end(ap); |
| 632 | } |
| 633 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 634 | /*! logging function used by LOGP() macro |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 635 | * \param[in] subsys Logging sub-system |
| 636 | * \param[in] level Log level |
| 637 | * \param[in] file name of source code file |
| 638 | * \param[in] cont continuation (1) or new line (0) |
| 639 | * \param[in] format format string |
| 640 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 641 | void logp2(int subsys, unsigned int level, const char *file, int line, int cont, const char *format, ...) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 642 | { |
| 643 | va_list ap; |
| 644 | |
| 645 | va_start(ap, format); |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 646 | osmo_vlogp(subsys, level, file, line, cont, format, ap); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 647 | va_end(ap); |
| 648 | } |
| 649 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 650 | /*! Register a new log target with the logging core |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 651 | * \param[in] target Log target to be registered |
| 652 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 653 | void log_add_target(struct log_target *target) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 654 | { |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 655 | llist_add_tail(&target->entry, &osmo_log_target_list); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 656 | } |
| 657 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 658 | /*! Unregister a log target from the logging core |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 659 | * \param[in] target Log target to be unregistered |
| 660 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 661 | void log_del_target(struct log_target *target) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 662 | { |
| 663 | llist_del(&target->entry); |
| 664 | } |
| 665 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 666 | /*! Reset (clear) the logging context */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 667 | void log_reset_context(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 668 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 669 | memset(&log_context, 0, sizeof(log_context)); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 670 | } |
| 671 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 672 | /*! Set the logging context |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 673 | * \param[in] ctx_nr logging context number |
| 674 | * \param[in] value value to which the context is to be set |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 675 | * \returns 0 in case of success; negative otherwise |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 676 | * |
| 677 | * A logging context is something like the subscriber identity to which |
| 678 | * the currently processed message relates, or the BTS through which it |
| 679 | * was received. As soon as this data is known, it can be set using |
| 680 | * this function. The main use of context information is for logging |
| 681 | * filters. |
| 682 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 683 | int log_set_context(uint8_t ctx_nr, void *value) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 684 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 685 | if (ctx_nr > LOG_MAX_CTX) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 686 | return -EINVAL; |
| 687 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 688 | log_context.ctx[ctx_nr] = value; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 693 | /*! Enable the \ref LOG_FLT_ALL log filter |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 694 | * \param[in] target Log target to be affected |
| 695 | * \param[in] all enable (1) or disable (0) the ALL filter |
| 696 | * |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 697 | * When the \ref LOG_FLT_ALL filter is enabled, all log messages will be |
Neels Hofmeyr | 812ba6d | 2017-02-17 16:35:27 +0100 | [diff] [blame] | 698 | * printed. It acts as a wildcard. Setting it to \a 1 means there is no |
| 699 | * filtering. |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 700 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 701 | void log_set_all_filter(struct log_target *target, int all) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 702 | { |
| 703 | if (all) |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 704 | target->filter_map |= (1 << LOG_FLT_ALL); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 705 | else |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 706 | target->filter_map &= ~(1 << LOG_FLT_ALL); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 707 | } |
| 708 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 709 | /*! Enable or disable the use of colored output |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 710 | * \param[in] target Log target to be affected |
| 711 | * \param[in] use_color Use color (1) or don't use color (0) |
| 712 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 713 | void log_set_use_color(struct log_target *target, int use_color) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 714 | { |
| 715 | target->use_color = use_color; |
| 716 | } |
| 717 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 718 | /*! Enable or disable printing of timestamps while logging |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 719 | * \param[in] target Log target to be affected |
| 720 | * \param[in] print_timestamp Enable (1) or disable (0) timestamps |
| 721 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 722 | void log_set_print_timestamp(struct log_target *target, int print_timestamp) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 723 | { |
| 724 | target->print_timestamp = print_timestamp; |
| 725 | } |
| 726 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 727 | /*! Enable or disable printing of extended timestamps while logging |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 728 | * \param[in] target Log target to be affected |
| 729 | * \param[in] print_timestamp Enable (1) or disable (0) timestamps |
| 730 | * |
| 731 | * When both timestamp and extended timestamp is enabled then only |
| 732 | * the extended timestamp will be used. The format of the timestamp |
| 733 | * is YYYYMMDDhhmmssnnn. |
| 734 | */ |
| 735 | void log_set_print_extended_timestamp(struct log_target *target, int print_timestamp) |
| 736 | { |
| 737 | target->print_ext_timestamp = print_timestamp; |
| 738 | } |
| 739 | |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 740 | /*! Use log_set_print_filename2() instead. |
| 741 | * Call log_set_print_filename2() with LOG_FILENAME_PATH or LOG_FILENAME_NONE, *as well as* call |
| 742 | * log_set_print_category_hex() with the argument passed to this function. This is to mirror legacy |
| 743 | * behavior, which combined the category in hex with the filename. For example, if the category-hex |
| 744 | * output were no longer affected by log_set_print_filename(), many unit tests (in libosmocore as well as |
| 745 | * dependent projects) would fail since they expect the category to disappear along with the filename. |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 746 | * \param[in] target Log target to be affected |
| 747 | * \param[in] print_filename Enable (1) or disable (0) filenames |
| 748 | */ |
| 749 | void log_set_print_filename(struct log_target *target, int print_filename) |
| 750 | { |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 751 | log_set_print_filename2(target, print_filename ? LOG_FILENAME_PATH : LOG_FILENAME_NONE); |
| 752 | log_set_print_category_hex(target, print_filename); |
| 753 | } |
| 754 | |
| 755 | /*! Enable or disable printing of the filename while logging. |
| 756 | * \param[in] target Log target to be affected. |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 757 | * \param[in] lft An LOG_FILENAME_* enum value. |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 758 | * LOG_FILENAME_NONE omits the source file and line information from logs. |
| 759 | * LOG_FILENAME_PATH prints the entire source file path as passed to LOGP macros. |
| 760 | */ |
| 761 | void log_set_print_filename2(struct log_target *target, enum log_filename_type lft) |
| 762 | { |
| 763 | target->print_filename2 = lft; |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 766 | /*! Set the position where on a log line the source file info should be logged. |
| 767 | * \param[in] target Log target to be affected. |
| 768 | * \param[in] pos A LOG_FILENAME_POS_* enum value. |
| 769 | * LOG_FILENAME_POS_DEFAULT logs just before the caller supplied log message. |
| 770 | * LOG_FILENAME_POS_LAST logs only at the end of a log line, where the caller issued an '\n' to end the |
| 771 | */ |
| 772 | void log_set_print_filename_pos(struct log_target *target, enum log_filename_pos pos) |
| 773 | { |
| 774 | target->print_filename_pos = pos; |
| 775 | } |
| 776 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 777 | /*! Enable or disable printing of the category name |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 778 | * \param[in] target Log target to be affected |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 779 | * \param[in] print_category Enable (1) or disable (0) filenames |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 780 | * |
| 781 | * Print the category/subsys name in front of every log message. |
| 782 | */ |
| 783 | void log_set_print_category(struct log_target *target, int print_category) |
| 784 | { |
| 785 | target->print_category = print_category; |
| 786 | } |
| 787 | |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 788 | /*! Enable or disable printing of the category number in hex ('<000b>'). |
| 789 | * \param[in] target Log target to be affected. |
| 790 | * \param[in] print_category_hex Enable (1) or disable (0) hex category. |
| 791 | */ |
| 792 | void log_set_print_category_hex(struct log_target *target, int print_category_hex) |
| 793 | { |
| 794 | target->print_category_hex = print_category_hex; |
| 795 | } |
| 796 | |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 797 | /*! Enable or disable printing of the log level name. |
| 798 | * \param[in] target Log target to be affected |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 799 | * \param[in] print_level Enable (1) or disable (0) log level name |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 800 | * |
| 801 | * Print the log level name in front of every log message. |
| 802 | */ |
| 803 | void log_set_print_level(struct log_target *target, int print_level) |
| 804 | { |
| 805 | target->print_level = (bool)print_level; |
| 806 | } |
| 807 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 808 | /*! Set the global log level for a given log target |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 809 | * \param[in] target Log target to be affected |
| 810 | * \param[in] log_level New global log level |
| 811 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 812 | void log_set_log_level(struct log_target *target, int log_level) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 813 | { |
| 814 | target->loglevel = log_level; |
| 815 | } |
| 816 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 817 | /*! Set a category filter on a given log target |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 818 | * \param[in] target Log target to be affected |
| 819 | * \param[in] category Log category to be affected |
| 820 | * \param[in] enable whether to enable or disable the filter |
| 821 | * \param[in] level Log level of the filter |
| 822 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 823 | void log_set_category_filter(struct log_target *target, int category, |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 824 | int enable, int level) |
| 825 | { |
Neels Hofmeyr | 886d6fd | 2016-12-12 13:49:03 +0100 | [diff] [blame] | 826 | if (!target) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 827 | return; |
Neels Hofmeyr | 886d6fd | 2016-12-12 13:49:03 +0100 | [diff] [blame] | 828 | category = map_subsys(category); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 829 | target->categories[category].enabled = !!enable; |
| 830 | target->categories[category].loglevel = level; |
| 831 | } |
| 832 | |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 833 | #if (!EMBEDDED) |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 834 | static void _file_output(struct log_target *target, unsigned int level, |
| 835 | const char *log) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 836 | { |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 837 | fprintf(target->tgt_file.out, "%s", log); |
| 838 | fflush(target->tgt_file.out); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 839 | } |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 840 | #endif |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 841 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 842 | /*! Create a new log target skeleton |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 843 | * \returns dynamically-allocated log target |
| 844 | * This funcition allocates a \ref log_target and initializes it |
| 845 | * with some default values. The newly created target is not |
| 846 | * registered yet. |
| 847 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 848 | struct log_target *log_target_create(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 849 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 850 | struct log_target *target; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 851 | unsigned int i; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 852 | |
Max | 68bf16a | 2018-01-10 17:00:43 +0100 | [diff] [blame] | 853 | assert_loginfo(__func__); |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 854 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 855 | target = talloc_zero(tall_log_ctx, struct log_target); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 856 | if (!target) |
| 857 | return NULL; |
| 858 | |
Pau Espin Pedrol | 9d4a36e | 2018-07-26 11:55:33 +0200 | [diff] [blame] | 859 | target->categories = talloc_zero_array(target, |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 860 | struct log_category, |
| 861 | osmo_log_info->num_cat); |
| 862 | if (!target->categories) { |
| 863 | talloc_free(target); |
| 864 | return NULL; |
| 865 | } |
| 866 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 867 | INIT_LLIST_HEAD(&target->entry); |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 868 | |
| 869 | /* initialize the per-category enabled/loglevel from defaults */ |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 870 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 871 | struct log_category *cat = &target->categories[i]; |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 872 | cat->enabled = osmo_log_info->cat[i].enabled; |
| 873 | cat->loglevel = osmo_log_info->cat[i].loglevel; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* global settings */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 877 | target->use_color = 1; |
| 878 | target->print_timestamp = 0; |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 879 | target->print_filename2 = LOG_FILENAME_PATH; |
| 880 | target->print_category_hex = true; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 881 | |
| 882 | /* global log level */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 883 | target->loglevel = 0; |
| 884 | return target; |
| 885 | } |
| 886 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 887 | /*! Create the STDERR log target |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 888 | * \returns dynamically-allocated \ref log_target for STDERR */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 889 | struct log_target *log_target_create_stderr(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 890 | { |
Harald Welte | a3b844c | 2010-03-27 00:04:40 +0800 | [diff] [blame] | 891 | /* since C89/C99 says stderr is a macro, we can safely do this! */ |
Harald Welte | b93ce5a | 2017-05-15 10:58:15 +0200 | [diff] [blame] | 892 | #if !EMBEDDED && defined(stderr) |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 893 | struct log_target *target; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 894 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 895 | target = log_target_create(); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 896 | if (!target) |
| 897 | return NULL; |
| 898 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 899 | target->type = LOG_TGT_TYPE_STDERR; |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 900 | target->tgt_file.out = stderr; |
| 901 | target->output = _file_output; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 902 | return target; |
Harald Welte | a3b844c | 2010-03-27 00:04:40 +0800 | [diff] [blame] | 903 | #else |
| 904 | return NULL; |
| 905 | #endif /* stderr */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 906 | } |
| 907 | |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 908 | #if (!EMBEDDED) |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 909 | /*! Create a new file-based log target |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 910 | * \param[in] fname File name of the new log file |
| 911 | * \returns Log target in case of success, NULL otherwise |
| 912 | */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 913 | struct log_target *log_target_create_file(const char *fname) |
| 914 | { |
| 915 | struct log_target *target; |
| 916 | |
| 917 | target = log_target_create(); |
| 918 | if (!target) |
| 919 | return NULL; |
| 920 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 921 | target->type = LOG_TGT_TYPE_FILE; |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 922 | target->tgt_file.out = fopen(fname, "a"); |
Vadim Yanitskiy | b89114b | 2020-09-09 04:51:04 +0700 | [diff] [blame] | 923 | if (!target->tgt_file.out) { |
| 924 | log_target_destroy(target); |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 925 | return NULL; |
Vadim Yanitskiy | b89114b | 2020-09-09 04:51:04 +0700 | [diff] [blame] | 926 | } |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 927 | |
| 928 | target->output = _file_output; |
| 929 | |
| 930 | target->tgt_file.fname = talloc_strdup(target, fname); |
| 931 | |
| 932 | return target; |
| 933 | } |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 934 | #endif |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 935 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 936 | /*! Find a registered log target |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 937 | * \param[in] type Log target type |
| 938 | * \param[in] fname File name |
| 939 | * \returns Log target (if found), NULL otherwise |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 940 | * Must be called with mutex osmo_log_tgt_mutex held, see log_tgt_mutex_lock. |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 941 | */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 942 | struct log_target *log_target_find(int type, const char *fname) |
| 943 | { |
| 944 | struct log_target *tgt; |
| 945 | |
| 946 | llist_for_each_entry(tgt, &osmo_log_target_list, entry) { |
| 947 | if (tgt->type != type) |
| 948 | continue; |
Max | c90f40a | 2018-01-11 10:52:28 +0100 | [diff] [blame] | 949 | switch (tgt->type) { |
| 950 | case LOG_TGT_TYPE_FILE: |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 951 | if (!strcmp(fname, tgt->tgt_file.fname)) |
| 952 | return tgt; |
Max | c90f40a | 2018-01-11 10:52:28 +0100 | [diff] [blame] | 953 | break; |
| 954 | case LOG_TGT_TYPE_GSMTAP: |
| 955 | if (!strcmp(fname, tgt->tgt_gsmtap.hostname)) |
| 956 | return tgt; |
| 957 | break; |
| 958 | default: |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 959 | return tgt; |
Max | c90f40a | 2018-01-11 10:52:28 +0100 | [diff] [blame] | 960 | } |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 961 | } |
| 962 | return NULL; |
| 963 | } |
| 964 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 965 | /*! Unregister, close and delete a log target |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 966 | * \param[in] target log target to unregister, close and delete */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 967 | void log_target_destroy(struct log_target *target) |
| 968 | { |
| 969 | |
| 970 | /* just in case, to make sure we don't have any references */ |
| 971 | log_del_target(target); |
| 972 | |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 973 | #if (!EMBEDDED) |
Vadim Yanitskiy | 744236b | 2020-09-09 04:42:22 +0700 | [diff] [blame] | 974 | switch (target->type) { |
| 975 | case LOG_TGT_TYPE_FILE: |
Vadim Yanitskiy | b89114b | 2020-09-09 04:51:04 +0700 | [diff] [blame] | 976 | if (target->tgt_file.out == NULL) |
| 977 | break; |
Vadim Yanitskiy | 744236b | 2020-09-09 04:42:22 +0700 | [diff] [blame] | 978 | fclose(target->tgt_file.out); |
| 979 | target->tgt_file.out = NULL; |
| 980 | break; |
Vadim Yanitskiy | 04f4271 | 2020-09-09 04:47:25 +0700 | [diff] [blame] | 981 | #ifdef HAVE_SYSLOG_H |
| 982 | case LOG_TGT_TYPE_SYSLOG: |
| 983 | closelog(); |
| 984 | break; |
| 985 | #endif /* HAVE_SYSLOG_H */ |
Vadim Yanitskiy | 744236b | 2020-09-09 04:42:22 +0700 | [diff] [blame] | 986 | default: |
| 987 | /* make GCC happy */ |
| 988 | break; |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 989 | } |
Harald Welte | 44c0f63 | 2017-01-15 17:58:29 +0100 | [diff] [blame] | 990 | #endif |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 991 | |
| 992 | talloc_free(target); |
| 993 | } |
| 994 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 995 | /*! close and re-open a log file (for log file rotation) |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 996 | * \param[in] target log target to re-open |
| 997 | * \returns 0 in case of success; negative otherwise */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 998 | int log_target_file_reopen(struct log_target *target) |
| 999 | { |
| 1000 | fclose(target->tgt_file.out); |
| 1001 | |
| 1002 | target->tgt_file.out = fopen(target->tgt_file.fname, "a"); |
| 1003 | if (!target->tgt_file.out) |
| 1004 | return -errno; |
| 1005 | |
| 1006 | /* we assume target->output already to be set */ |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1011 | /*! close and re-open all log files (for log file rotation) |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 1012 | * \returns 0 in case of success; negative otherwise */ |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 1013 | int log_targets_reopen(void) |
| 1014 | { |
| 1015 | struct log_target *tar; |
| 1016 | int rc = 0; |
| 1017 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1018 | log_tgt_mutex_lock(); |
| 1019 | |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 1020 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
| 1021 | switch (tar->type) { |
| 1022 | case LOG_TGT_TYPE_FILE: |
| 1023 | if (log_target_file_reopen(tar) < 0) |
| 1024 | rc = -1; |
| 1025 | break; |
| 1026 | default: |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1031 | log_tgt_mutex_unlock(); |
| 1032 | |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 1033 | return rc; |
| 1034 | } |
| 1035 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1036 | /*! Initialize the Osmocom logging core |
Max | 72dfd43 | 2018-12-04 11:24:18 +0100 | [diff] [blame] | 1037 | * \param[in] inf Information regarding logging categories, could be NULL |
Vadim Yanitskiy | 73e66b3 | 2019-03-25 21:24:20 +0700 | [diff] [blame] | 1038 | * \param[in] ctx talloc context for logging allocations |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 1039 | * \returns 0 in case of success, negative in case of error |
Max | 72dfd43 | 2018-12-04 11:24:18 +0100 | [diff] [blame] | 1040 | * |
| 1041 | * If inf is NULL then only library-internal categories are initialized. |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 1042 | */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1043 | int log_init(const struct log_info *inf, void *ctx) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 1044 | { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1045 | int i; |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1046 | struct log_info_cat *cat_ptr; |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1047 | |
Philipp Maier | dc02c06 | 2020-05-12 17:51:25 +0200 | [diff] [blame] | 1048 | /* Ensure that log_init is not called multiple times */ |
| 1049 | OSMO_ASSERT(tall_log_ctx == NULL) |
| 1050 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1051 | tall_log_ctx = talloc_named_const(ctx, 1, "logging"); |
| 1052 | if (!tall_log_ctx) |
| 1053 | return -ENOMEM; |
| 1054 | |
| 1055 | osmo_log_info = talloc_zero(tall_log_ctx, struct log_info); |
| 1056 | if (!osmo_log_info) |
| 1057 | return -ENOMEM; |
| 1058 | |
Max | 72dfd43 | 2018-12-04 11:24:18 +0100 | [diff] [blame] | 1059 | osmo_log_info->num_cat = ARRAY_SIZE(internal_cat); |
| 1060 | |
| 1061 | if (inf) { |
| 1062 | osmo_log_info->filter_fn = inf->filter_fn; |
| 1063 | osmo_log_info->num_cat_user = inf->num_cat; |
| 1064 | osmo_log_info->num_cat += inf->num_cat; |
| 1065 | } |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1066 | |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1067 | cat_ptr = talloc_zero_array(osmo_log_info, struct log_info_cat, |
| 1068 | osmo_log_info->num_cat); |
| 1069 | if (!cat_ptr) { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1070 | talloc_free(osmo_log_info); |
| 1071 | osmo_log_info = NULL; |
| 1072 | return -ENOMEM; |
| 1073 | } |
| 1074 | |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1075 | /* copy over the user part and sanitize loglevel */ |
| 1076 | if (inf) { |
Max | 72dfd43 | 2018-12-04 11:24:18 +0100 | [diff] [blame] | 1077 | for (i = 0; i < inf->num_cat; i++) { |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1078 | memcpy(&cat_ptr[i], &inf->cat[i], |
| 1079 | sizeof(struct log_info_cat)); |
| 1080 | |
| 1081 | /* Make sure that the loglevel is set to NOTICE in case |
| 1082 | * no loglevel has been preset. */ |
| 1083 | if (!cat_ptr[i].loglevel) { |
| 1084 | cat_ptr[i].loglevel = LOGL_NOTICE; |
| 1085 | } |
Max | 72dfd43 | 2018-12-04 11:24:18 +0100 | [diff] [blame] | 1086 | } |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /* copy over the library part */ |
Harald Welte | 9fe1652 | 2011-06-27 14:00:03 +0200 | [diff] [blame] | 1090 | for (i = 0; i < ARRAY_SIZE(internal_cat); i++) { |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 1091 | unsigned int cn = osmo_log_info->num_cat_user + i; |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1092 | memcpy(&cat_ptr[cn], &internal_cat[i], sizeof(struct log_info_cat)); |
Harald Welte | 9fe1652 | 2011-06-27 14:00:03 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Philipp Maier | dcad1c5 | 2020-03-25 11:25:59 +0100 | [diff] [blame] | 1095 | osmo_log_info->cat = cat_ptr; |
| 1096 | |
Harald Welte | 9fe1652 | 2011-06-27 14:00:03 +0200 | [diff] [blame] | 1097 | return 0; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 1098 | } |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 1099 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1100 | /* De-initialize the Osmocom logging core |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 1101 | * This function destroys all targets and releases associated memory */ |
| 1102 | void log_fini(void) |
| 1103 | { |
| 1104 | struct log_target *tar, *tar2; |
| 1105 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1106 | log_tgt_mutex_lock(); |
| 1107 | |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 1108 | llist_for_each_entry_safe(tar, tar2, &osmo_log_target_list, entry) |
| 1109 | log_target_destroy(tar); |
| 1110 | |
| 1111 | talloc_free(osmo_log_info); |
| 1112 | osmo_log_info = NULL; |
| 1113 | talloc_free(tall_log_ctx); |
| 1114 | tall_log_ctx = NULL; |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1115 | |
| 1116 | log_tgt_mutex_unlock(); |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1119 | /*! Check whether a log entry will be generated. |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1120 | * \returns != 0 if a log entry might get generated by at least one target */ |
| 1121 | int log_check_level(int subsys, unsigned int level) |
| 1122 | { |
| 1123 | struct log_target *tar; |
| 1124 | |
Max | 68bf16a | 2018-01-10 17:00:43 +0100 | [diff] [blame] | 1125 | assert_loginfo(__func__); |
Harald Welte | 18a7d81 | 2017-03-16 23:54:55 +0100 | [diff] [blame] | 1126 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 1127 | subsys = map_subsys(subsys); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1128 | |
| 1129 | /* TODO: The following could/should be cached (update on config) */ |
| 1130 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1131 | log_tgt_mutex_lock(); |
| 1132 | |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1133 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 1134 | if (!should_log_to_target(tar, subsys, level)) |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1135 | continue; |
| 1136 | |
| 1137 | /* This might get logged (ignoring filters) */ |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1138 | log_tgt_mutex_unlock(); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1139 | return 1; |
| 1140 | } |
| 1141 | |
| 1142 | /* We are sure, that this will not be logged. */ |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1143 | log_tgt_mutex_unlock(); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 1144 | return 0; |
| 1145 | } |
| 1146 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 1147 | /*! @} */ |