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