Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 1 | /* Debugging/Logging support code */ |
| 2 | |
| 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 23 | /* \addtogroup logging |
| 24 | * @{ |
| 25 | */ |
| 26 | |
| 27 | /* \file logging.c */ |
| 28 | |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 29 | #include "../config.h" |
| 30 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 31 | #include <stdarg.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdio.h> |
| 34 | #include <string.h> |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 35 | #include <ctype.h> |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 36 | |
| 37 | #ifdef HAVE_STRINGS_H |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 38 | #include <strings.h> |
Harald Welte | 01fd5cb | 2010-03-26 23:51:31 +0800 | [diff] [blame] | 39 | #endif |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 40 | #include <time.h> |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 41 | #include <sys/time.h> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 42 | #include <errno.h> |
| 43 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 44 | #include <osmocom/core/talloc.h> |
| 45 | #include <osmocom/core/utils.h> |
| 46 | #include <osmocom/core/logging.h> |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 47 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 48 | #include <osmocom/vty/logging.h> /* for LOGGING_STR. */ |
| 49 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 50 | struct log_info *osmo_log_info; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 51 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 52 | static struct log_context log_context; |
| 53 | static void *tall_log_ctx = NULL; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 54 | LLIST_HEAD(osmo_log_target_list); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 55 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 56 | #define LOGLEVEL_DEFS 6 /* Number of loglevels.*/ |
| 57 | |
| 58 | static const struct value_string loglevel_strs[LOGLEVEL_DEFS+1] = { |
Harald Welte | 9b18670 | 2013-03-19 09:55:28 +0100 | [diff] [blame] | 59 | { 0, "EVERYTHING" }, |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 60 | { LOGL_DEBUG, "DEBUG" }, |
| 61 | { LOGL_INFO, "INFO" }, |
| 62 | { LOGL_NOTICE, "NOTICE" }, |
| 63 | { LOGL_ERROR, "ERROR" }, |
| 64 | { LOGL_FATAL, "FATAL" }, |
| 65 | { 0, NULL }, |
| 66 | }; |
| 67 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 68 | #define INT2IDX(x) (-1*(x)-1) |
| 69 | static const struct log_info_cat internal_cat[OSMO_NUM_DLIB] = { |
| 70 | [INT2IDX(DLGLOBAL)] = { /* -1 becomes 0 */ |
| 71 | .name = "DLGLOBAL", |
| 72 | .description = "Library-internal global log family", |
| 73 | .loglevel = LOGL_NOTICE, |
| 74 | .enabled = 1, |
| 75 | }, |
root | 8a996b4 | 2011-09-26 11:22:21 +0200 | [diff] [blame] | 76 | [INT2IDX(DLLAPD)] = { /* -2 becomes 1 */ |
| 77 | .name = "DLLAPD", |
| 78 | .description = "LAPD in libosmogsm", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 79 | .loglevel = LOGL_NOTICE, |
| 80 | .enabled = 1, |
| 81 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 82 | [INT2IDX(DLINP)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 83 | .name = "DLINP", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 84 | .description = "A-bis Intput Subsystem", |
| 85 | .loglevel = LOGL_NOTICE, |
| 86 | .enabled = 1, |
| 87 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 88 | [INT2IDX(DLMUX)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 89 | .name = "DLMUX", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 90 | .description = "A-bis B-Subchannel TRAU Frame Multiplex", |
| 91 | .loglevel = LOGL_NOTICE, |
| 92 | .enabled = 1, |
| 93 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 94 | [INT2IDX(DLMI)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 95 | .name = "DLMI", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 96 | .description = "A-bis Input Driver for Signalling", |
| 97 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 98 | }, |
Harald Welte | 892e621 | 2011-07-19 14:31:44 +0200 | [diff] [blame] | 99 | [INT2IDX(DLMIB)] = { |
Harald Welte | 087e113 | 2011-07-29 11:43:39 +0200 | [diff] [blame] | 100 | .name = "DLMIB", |
Pablo Neira Ayuso | 199f377 | 2011-07-07 19:46:38 +0200 | [diff] [blame] | 101 | .description = "A-bis Input Driver for B-Channels (voice)", |
| 102 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 103 | }, |
Andreas Eversberg | c626da9 | 2011-10-28 03:53:50 +0200 | [diff] [blame] | 104 | [INT2IDX(DLSMS)] = { |
| 105 | .name = "DLSMS", |
| 106 | .description = "Layer3 Short Message Service (SMS)", |
| 107 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 108 | .color = "\033[1;38m", |
| 109 | }, |
Harald Welte | 7fd0c83 | 2014-08-20 19:58:13 +0200 | [diff] [blame] | 110 | [INT2IDX(DLCTRL)] = { |
| 111 | .name = "DLCTRL", |
| 112 | .description = "Control Interface", |
| 113 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 114 | }, |
Holger Hans Peter Freyther | a5dc19d | 2014-12-04 14:35:21 +0100 | [diff] [blame] | 115 | [INT2IDX(DLGTP)] = { |
| 116 | .name = "DLGTP", |
| 117 | .description = "GPRS GTP library", |
| 118 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 119 | }, |
Jacob Erlbeck | 79125ec | 2015-11-02 15:17:50 +0100 | [diff] [blame] | 120 | [INT2IDX(DLSTATS)] = { |
| 121 | .name = "DLSTATS", |
| 122 | .description = "Statistics messages and logging", |
| 123 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 124 | }, |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 125 | }; |
| 126 | |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 127 | /*! \brief descriptive string for each log level */ |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 128 | /* You have to keep this in sync with the structure loglevel_strs. */ |
| 129 | const char *loglevel_descriptions[LOGLEVEL_DEFS+1] = { |
Holger Hans Peter Freyther | 6ec6bd9 | 2014-12-28 18:27:38 +0100 | [diff] [blame] | 130 | "Don't use. It doesn't log anything", |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 131 | "Log debug messages and higher levels", |
| 132 | "Log informational messages and higher levels", |
| 133 | "Log noticable messages and higher levels", |
| 134 | "Log error messages and higher levels", |
| 135 | "Log only fatal messages", |
| 136 | NULL, |
| 137 | }; |
| 138 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 139 | /* special magic for negative (library-internal) log subsystem numbers */ |
| 140 | static int subsys_lib2index(int subsys) |
| 141 | { |
| 142 | return (subsys * -1) + (osmo_log_info->num_cat_user-1); |
| 143 | } |
| 144 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 145 | /*! \brief Parse a human-readable log level into a numeric value |
| 146 | * \param lvl[in] zero-terminated string containing log level name |
| 147 | * \returns numeric log level |
| 148 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 149 | int log_parse_level(const char *lvl) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 150 | { |
| 151 | return get_string_value(loglevel_strs, lvl); |
| 152 | } |
| 153 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 154 | /*! \brief convert a numeric log level into human-readable string |
| 155 | * \param lvl[in] numeric log level |
| 156 | * \returns zero-terminated string (log level name) |
| 157 | */ |
Harald Welte | 9ac2225 | 2010-05-11 11:19:40 +0200 | [diff] [blame] | 158 | const char *log_level_str(unsigned int lvl) |
| 159 | { |
| 160 | return get_value_string(loglevel_strs, lvl); |
| 161 | } |
| 162 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 163 | /*! \brief parse a human-readable log category into numeric form |
| 164 | * \param[in] category human-readable log category name |
| 165 | * \returns numeric category value, or -EINVAL otherwise |
| 166 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 167 | int log_parse_category(const char *category) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 168 | { |
| 169 | int i; |
| 170 | |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 171 | for (i = 0; i < osmo_log_info->num_cat; ++i) { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 172 | if (osmo_log_info->cat[i].name == NULL) |
| 173 | continue; |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 174 | if (!strcasecmp(osmo_log_info->cat[i].name+1, category)) |
Harald Welte | faadfe2 | 2010-03-26 21:05:43 +0800 | [diff] [blame] | 175 | return i; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 181 | /*! \brief parse the log category mask |
| 182 | * \param[in] target log target to be configured |
| 183 | * \param[in] _mask log category mask string |
| 184 | * |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 185 | * The format can be this: category1:category2:category3 |
| 186 | * or category1,2:category2,3:... |
| 187 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 188 | void log_parse_category_mask(struct log_target* target, const char *_mask) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 189 | { |
| 190 | int i = 0; |
| 191 | char *mask = strdup(_mask); |
| 192 | char *category_token = NULL; |
| 193 | |
| 194 | /* Disable everything to enable it afterwards */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 195 | for (i = 0; i < osmo_log_info->num_cat; ++i) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 196 | target->categories[i].enabled = 0; |
| 197 | |
| 198 | category_token = strtok(mask, ":"); |
Neels Hofmeyr | da1b20c | 2016-04-14 15:12:16 +0200 | [diff] [blame] | 199 | OSMO_ASSERT(category_token); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 200 | do { |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 201 | for (i = 0; i < osmo_log_info->num_cat; ++i) { |
Nico Golde | 0262d3f | 2012-09-21 17:44:58 +0200 | [diff] [blame] | 202 | size_t length, cat_length; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 203 | char* colon = strstr(category_token, ","); |
Nico Golde | 0262d3f | 2012-09-21 17:44:58 +0200 | [diff] [blame] | 204 | |
| 205 | if (!osmo_log_info->cat[i].name) |
| 206 | continue; |
| 207 | |
| 208 | length = strlen(category_token); |
| 209 | cat_length = strlen(osmo_log_info->cat[i].name); |
Pablo Neira Ayuso | 300e78d | 2011-08-11 13:24:18 +0200 | [diff] [blame] | 210 | |
| 211 | /* Use longest length not to match subocurrences. */ |
| 212 | if (cat_length > length) |
| 213 | length = cat_length; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 214 | |
| 215 | if (colon) |
| 216 | length = colon - category_token; |
| 217 | |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 218 | if (strncasecmp(osmo_log_info->cat[i].name, |
| 219 | category_token, length) == 0) { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 220 | int level = 0; |
| 221 | |
| 222 | if (colon) |
| 223 | level = atoi(colon+1); |
| 224 | |
Harald Welte | faadfe2 | 2010-03-26 21:05:43 +0800 | [diff] [blame] | 225 | target->categories[i].enabled = 1; |
| 226 | target->categories[i].loglevel = level; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } while ((category_token = strtok(NULL, ":"))); |
| 230 | |
| 231 | free(mask); |
| 232 | } |
| 233 | |
| 234 | static const char* color(int subsys) |
| 235 | { |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 236 | if (subsys < osmo_log_info->num_cat) |
| 237 | return osmo_log_info->cat[subsys].color; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 238 | |
Harald Welte | d788f66 | 2010-03-26 09:45:03 +0800 | [diff] [blame] | 239 | return NULL; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 240 | } |
| 241 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 242 | static const char* category_name(int subsys) |
| 243 | { |
| 244 | if (subsys < osmo_log_info->num_cat) |
| 245 | return osmo_log_info->cat[subsys].name; |
| 246 | |
| 247 | return NULL; |
| 248 | } |
| 249 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 250 | static void _output(struct log_target *target, unsigned int subsys, |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 251 | unsigned int level, const char *file, int line, int cont, |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 252 | const char *format, va_list ap) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 253 | { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 254 | char buf[4096]; |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 255 | int ret, len = 0, offset = 0, rem = sizeof(buf); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 256 | |
| 257 | /* are we using color */ |
| 258 | if (target->use_color) { |
Harald Welte | d788f66 | 2010-03-26 09:45:03 +0800 | [diff] [blame] | 259 | const char *c = color(subsys); |
| 260 | if (c) { |
Holger Hans Peter Freyther | 5f91a40 | 2014-12-05 10:29:45 +0100 | [diff] [blame] | 261 | ret = snprintf(buf + offset, rem, "%s", c); |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 262 | if (ret < 0) |
| 263 | goto err; |
| 264 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | d788f66 | 2010-03-26 09:45:03 +0800 | [diff] [blame] | 265 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 266 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 267 | if (!cont) { |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 268 | if (target->print_ext_timestamp) { |
| 269 | struct tm tm; |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 270 | struct timeval tv; |
| 271 | gettimeofday(&tv, NULL); |
| 272 | localtime_r(&tv.tv_sec, &tm); |
| 273 | 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] | 274 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, |
Jacob Erlbeck | b61b2ca | 2015-03-17 10:21:15 +0100 | [diff] [blame] | 275 | tm.tm_hour, tm.tm_min, tm.tm_sec, |
| 276 | (int)(tv.tv_usec / 1000)); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 277 | if (ret < 0) |
| 278 | goto err; |
| 279 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 280 | } else if (target->print_timestamp) { |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 281 | char *timestr; |
| 282 | time_t tm; |
| 283 | tm = time(NULL); |
| 284 | timestr = ctime(&tm); |
| 285 | timestr[strlen(timestr)-1] = '\0'; |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 286 | ret = snprintf(buf + offset, rem, "%s ", timestr); |
| 287 | if (ret < 0) |
| 288 | goto err; |
| 289 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 290 | } |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 291 | if (target->print_category) { |
| 292 | ret = snprintf(buf + offset, rem, "%s ", category_name(subsys)); |
| 293 | if (ret < 0) |
| 294 | goto err; |
| 295 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 296 | } |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 297 | if (target->print_filename) { |
| 298 | ret = snprintf(buf + offset, rem, "<%4.4x> %s:%d ", |
| 299 | subsys, file, line); |
| 300 | if (ret < 0) |
| 301 | goto err; |
| 302 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 303 | } |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 304 | } |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 305 | ret = vsnprintf(buf + offset, rem, format, ap); |
| 306 | if (ret < 0) |
| 307 | goto err; |
| 308 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 309 | |
Pablo Neira Ayuso | 7503fb8 | 2011-05-03 22:32:43 +0200 | [diff] [blame] | 310 | ret = snprintf(buf + offset, rem, "%s", |
| 311 | target->use_color ? "\033[0;m" : ""); |
| 312 | if (ret < 0) |
| 313 | goto err; |
| 314 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 315 | err: |
| 316 | buf[sizeof(buf)-1] = '\0'; |
| 317 | target->output(target, level, buf); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 318 | } |
| 319 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 320 | static inline int map_subsys(int subsys) |
| 321 | { |
| 322 | if (subsys < 0) |
| 323 | subsys = subsys_lib2index(subsys); |
| 324 | |
| 325 | if (subsys > osmo_log_info->num_cat) |
| 326 | subsys = DLGLOBAL; |
| 327 | return subsys; |
| 328 | } |
| 329 | |
| 330 | static inline int check_log_to_target(struct log_target *tar, int subsys, int level) |
| 331 | { |
| 332 | struct log_category *category; |
| 333 | |
| 334 | category = &tar->categories[subsys]; |
| 335 | |
| 336 | /* subsystem is not supposed to be logged */ |
| 337 | if (!category->enabled) |
| 338 | return 0; |
| 339 | |
| 340 | /* Check the global log level */ |
| 341 | if (tar->loglevel != 0 && level < tar->loglevel) |
| 342 | return 0; |
| 343 | |
| 344 | /* Check the category log level */ |
| 345 | if (tar->loglevel == 0 && category->loglevel != 0 && |
| 346 | level < category->loglevel) |
| 347 | return 0; |
| 348 | |
Holger Hans Peter Freyther | 79599ac | 2016-01-15 16:49:06 +0100 | [diff] [blame] | 349 | /* Apply filters here... if that becomes messy we will |
| 350 | * need to put filters in a list and each filter will |
| 351 | * say stop, continue, output */ |
| 352 | if ((tar->filter_map & LOG_FILTER_ALL) != 0) |
| 353 | return 1; |
| 354 | |
| 355 | if (osmo_log_info->filter_fn) |
| 356 | return osmo_log_info->filter_fn(&log_context, tar); |
| 357 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 358 | /* TODO: Check the filter/selector too? */ |
| 359 | return 1; |
| 360 | } |
| 361 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 362 | /*! \brief vararg version of logging function |
| 363 | * \param[in] subsys Logging sub-system |
| 364 | * \param[in] level Log level |
| 365 | * \param[in] file name of source code file |
| 366 | * \param[in] cont continuation (1) or new line (0) |
| 367 | * \param[in] format format string |
| 368 | * \param[in] ap vararg-list containing format string arguments |
| 369 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 370 | void osmo_vlogp(int subsys, int level, const char *file, int line, |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 371 | int cont, const char *format, va_list ap) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 372 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 373 | struct log_target *tar; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 374 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 375 | subsys = map_subsys(subsys); |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 376 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 377 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 378 | va_list bp; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 379 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 380 | if (!check_log_to_target(tar, subsys, level)) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 381 | continue; |
| 382 | |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 383 | /* According to the manpage, vsnprintf leaves the value of ap |
| 384 | * in undefined state. Since _output uses vsnprintf and it may |
| 385 | * be called several times, we have to pass a copy of ap. */ |
| 386 | va_copy(bp, ap); |
Harald Welte | da127cb | 2011-07-02 21:51:32 +0200 | [diff] [blame] | 387 | _output(tar, subsys, level, file, line, cont, format, bp); |
Pablo Neira Ayuso | dd93bf4 | 2011-05-19 01:40:43 +0200 | [diff] [blame] | 388 | va_end(bp); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 392 | /*! \brief logging function used by DEBUGP() macro |
| 393 | * \param[in] subsys Logging sub-system |
| 394 | * \param[in] file name of source code file |
| 395 | * \param[in] cont continuation (1) or new line (0) |
| 396 | * \param[in] format format string |
| 397 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 398 | void logp(int subsys, const char *file, int line, int cont, |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 399 | const char *format, ...) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 400 | { |
| 401 | va_list ap; |
| 402 | |
| 403 | va_start(ap, format); |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 404 | osmo_vlogp(subsys, LOGL_DEBUG, file, line, cont, format, ap); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 405 | va_end(ap); |
| 406 | } |
| 407 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 408 | /*! \brief logging function used by LOGP() macro |
| 409 | * \param[in] subsys Logging sub-system |
| 410 | * \param[in] level Log level |
| 411 | * \param[in] file name of source code file |
| 412 | * \param[in] cont continuation (1) or new line (0) |
| 413 | * \param[in] format format string |
| 414 | */ |
Holger Hans Peter Freyther | fb4bfc2 | 2012-07-12 09:26:25 +0200 | [diff] [blame] | 415 | 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] | 416 | { |
| 417 | va_list ap; |
| 418 | |
| 419 | va_start(ap, format); |
Harald Welte | 36c5a3e | 2011-08-27 14:33:19 +0200 | [diff] [blame] | 420 | osmo_vlogp(subsys, level, file, line, cont, format, ap); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 421 | va_end(ap); |
| 422 | } |
| 423 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 424 | /*! \brief Register a new log target with the logging core |
| 425 | * \param[in] target Log target to be registered |
| 426 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 427 | void log_add_target(struct log_target *target) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 428 | { |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 429 | llist_add_tail(&target->entry, &osmo_log_target_list); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 430 | } |
| 431 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 432 | /*! \brief Unregister a log target from the logging core |
| 433 | * \param[in] target Log target to be unregistered |
| 434 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 435 | void log_del_target(struct log_target *target) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 436 | { |
| 437 | llist_del(&target->entry); |
| 438 | } |
| 439 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 440 | /*! \brief Reset (clear) the logging context */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 441 | void log_reset_context(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 442 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 443 | memset(&log_context, 0, sizeof(log_context)); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 444 | } |
| 445 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 446 | /*! \brief Set the logging context |
| 447 | * \param[in] ctx_nr logging context number |
| 448 | * \param[in] value value to which the context is to be set |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 449 | * \returns 0 in case of success; negative otherwise |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 450 | * |
| 451 | * A logging context is something like the subscriber identity to which |
| 452 | * the currently processed message relates, or the BTS through which it |
| 453 | * was received. As soon as this data is known, it can be set using |
| 454 | * this function. The main use of context information is for logging |
| 455 | * filters. |
| 456 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 457 | int log_set_context(uint8_t ctx_nr, void *value) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 458 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 459 | if (ctx_nr > LOG_MAX_CTX) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 460 | return -EINVAL; |
| 461 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 462 | log_context.ctx[ctx_nr] = value; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 467 | /*! \brief Enable the \ref LOG_FILTER_ALL log filter |
| 468 | * \param[in] target Log target to be affected |
| 469 | * \param[in] all enable (1) or disable (0) the ALL filter |
| 470 | * |
| 471 | * When the \ref LOG_FILTER_ALL filter is enabled, all log messages will |
| 472 | * be printed. It acts as a wildcard. Setting it to \a 1 means there |
| 473 | * is no filtering. |
| 474 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 475 | void log_set_all_filter(struct log_target *target, int all) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 476 | { |
| 477 | if (all) |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 478 | target->filter_map |= LOG_FILTER_ALL; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 479 | else |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 480 | target->filter_map &= ~LOG_FILTER_ALL; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 481 | } |
| 482 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 483 | /*! \brief Enable or disable the use of colored output |
| 484 | * \param[in] target Log target to be affected |
| 485 | * \param[in] use_color Use color (1) or don't use color (0) |
| 486 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 487 | void log_set_use_color(struct log_target *target, int use_color) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 488 | { |
| 489 | target->use_color = use_color; |
| 490 | } |
| 491 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 492 | /*! \brief Enable or disable printing of timestamps while logging |
| 493 | * \param[in] target Log target to be affected |
| 494 | * \param[in] print_timestamp Enable (1) or disable (0) timestamps |
| 495 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 496 | void log_set_print_timestamp(struct log_target *target, int print_timestamp) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 497 | { |
| 498 | target->print_timestamp = print_timestamp; |
| 499 | } |
| 500 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 501 | /*! \brief Enable or disable printing of extended timestamps while logging |
| 502 | * \param[in] target Log target to be affected |
| 503 | * \param[in] print_timestamp Enable (1) or disable (0) timestamps |
| 504 | * |
| 505 | * When both timestamp and extended timestamp is enabled then only |
| 506 | * the extended timestamp will be used. The format of the timestamp |
| 507 | * is YYYYMMDDhhmmssnnn. |
| 508 | */ |
| 509 | void log_set_print_extended_timestamp(struct log_target *target, int print_timestamp) |
| 510 | { |
| 511 | target->print_ext_timestamp = print_timestamp; |
| 512 | } |
| 513 | |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 514 | /*! \brief Enable or disable printing of the filename while logging |
| 515 | * \param[in] target Log target to be affected |
| 516 | * \param[in] print_filename Enable (1) or disable (0) filenames |
| 517 | */ |
| 518 | void log_set_print_filename(struct log_target *target, int print_filename) |
| 519 | { |
| 520 | target->print_filename = print_filename; |
| 521 | } |
| 522 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 523 | /*! \brief Enable or disable printing of the category name |
| 524 | * \param[in] target Log target to be affected |
| 525 | * \param[in] print_catname Enable (1) or disable (0) filenames |
| 526 | * |
| 527 | * Print the category/subsys name in front of every log message. |
| 528 | */ |
| 529 | void log_set_print_category(struct log_target *target, int print_category) |
| 530 | { |
| 531 | target->print_category = print_category; |
| 532 | } |
| 533 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 534 | /*! \brief Set the global log level for a given log target |
| 535 | * \param[in] target Log target to be affected |
| 536 | * \param[in] log_level New global log level |
| 537 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 538 | void log_set_log_level(struct log_target *target, int log_level) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 539 | { |
| 540 | target->loglevel = log_level; |
| 541 | } |
| 542 | |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 543 | /*! \brief Set a category filter on a given log target |
| 544 | * \param[in] target Log target to be affected |
| 545 | * \param[in] category Log category to be affected |
| 546 | * \param[in] enable whether to enable or disable the filter |
| 547 | * \param[in] level Log level of the filter |
| 548 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 549 | void log_set_category_filter(struct log_target *target, int category, |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 550 | int enable, int level) |
| 551 | { |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 552 | if (category >= osmo_log_info->num_cat) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 553 | return; |
| 554 | target->categories[category].enabled = !!enable; |
| 555 | target->categories[category].loglevel = level; |
| 556 | } |
| 557 | |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 558 | static void _file_output(struct log_target *target, unsigned int level, |
| 559 | const char *log) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 560 | { |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 561 | fprintf(target->tgt_file.out, "%s", log); |
| 562 | fflush(target->tgt_file.out); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 563 | } |
| 564 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 565 | /*! \brief Create a new log target skeleton |
| 566 | * \returns dynamically-allocated log target |
| 567 | * This funcition allocates a \ref log_target and initializes it |
| 568 | * with some default values. The newly created target is not |
| 569 | * registered yet. |
| 570 | */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 571 | struct log_target *log_target_create(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 572 | { |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 573 | struct log_target *target; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 574 | unsigned int i; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 575 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 576 | target = talloc_zero(tall_log_ctx, struct log_target); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 577 | if (!target) |
| 578 | return NULL; |
| 579 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 580 | target->categories = talloc_zero_array(target, |
| 581 | struct log_category, |
| 582 | osmo_log_info->num_cat); |
| 583 | if (!target->categories) { |
| 584 | talloc_free(target); |
| 585 | return NULL; |
| 586 | } |
| 587 | |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 588 | INIT_LLIST_HEAD(&target->entry); |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 589 | |
| 590 | /* initialize the per-category enabled/loglevel from defaults */ |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 591 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 592 | struct log_category *cat = &target->categories[i]; |
Harald Welte | 4ebdf74 | 2010-05-19 19:54:00 +0200 | [diff] [blame] | 593 | cat->enabled = osmo_log_info->cat[i].enabled; |
| 594 | cat->loglevel = osmo_log_info->cat[i].loglevel; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* global settings */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 598 | target->use_color = 1; |
| 599 | target->print_timestamp = 0; |
Holger Hans Peter Freyther | db15336 | 2012-09-11 11:24:51 +0200 | [diff] [blame] | 600 | target->print_filename = 1; |
Harald Welte | cc6313c | 2010-03-26 22:04:03 +0800 | [diff] [blame] | 601 | |
| 602 | /* global log level */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 603 | target->loglevel = 0; |
| 604 | return target; |
| 605 | } |
| 606 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 607 | /*! \brief Create the STDERR log target |
| 608 | * \returns dynamically-allocated \ref log_target for STDERR */ |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 609 | struct log_target *log_target_create_stderr(void) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 610 | { |
Harald Welte | a3b844c | 2010-03-27 00:04:40 +0800 | [diff] [blame] | 611 | /* since C89/C99 says stderr is a macro, we can safely do this! */ |
| 612 | #ifdef stderr |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 613 | struct log_target *target; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 614 | |
Harald Welte | 3ae2758 | 2010-03-26 21:24:24 +0800 | [diff] [blame] | 615 | target = log_target_create(); |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 616 | if (!target) |
| 617 | return NULL; |
| 618 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 619 | target->type = LOG_TGT_TYPE_STDERR; |
Harald Welte | 0083cd3 | 2010-08-25 14:55:44 +0200 | [diff] [blame] | 620 | target->tgt_file.out = stderr; |
| 621 | target->output = _file_output; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 622 | return target; |
Harald Welte | a3b844c | 2010-03-27 00:04:40 +0800 | [diff] [blame] | 623 | #else |
| 624 | return NULL; |
| 625 | #endif /* stderr */ |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 626 | } |
| 627 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 628 | /*! \brief Create a new file-based log target |
| 629 | * \param[in] fname File name of the new log file |
| 630 | * \returns Log target in case of success, NULL otherwise |
| 631 | */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 632 | struct log_target *log_target_create_file(const char *fname) |
| 633 | { |
| 634 | struct log_target *target; |
| 635 | |
| 636 | target = log_target_create(); |
| 637 | if (!target) |
| 638 | return NULL; |
| 639 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 640 | target->type = LOG_TGT_TYPE_FILE; |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 641 | target->tgt_file.out = fopen(fname, "a"); |
| 642 | if (!target->tgt_file.out) |
| 643 | return NULL; |
| 644 | |
| 645 | target->output = _file_output; |
| 646 | |
| 647 | target->tgt_file.fname = talloc_strdup(target, fname); |
| 648 | |
| 649 | return target; |
| 650 | } |
| 651 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 652 | /*! \brief Find a registered log target |
| 653 | * \param[in] type Log target type |
| 654 | * \param[in] fname File name |
| 655 | * \returns Log target (if found), NULL otherwise |
| 656 | */ |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 657 | struct log_target *log_target_find(int type, const char *fname) |
| 658 | { |
| 659 | struct log_target *tgt; |
| 660 | |
| 661 | llist_for_each_entry(tgt, &osmo_log_target_list, entry) { |
| 662 | if (tgt->type != type) |
| 663 | continue; |
| 664 | if (tgt->type == LOG_TGT_TYPE_FILE) { |
| 665 | if (!strcmp(fname, tgt->tgt_file.fname)) |
| 666 | return tgt; |
| 667 | } else |
| 668 | return tgt; |
| 669 | } |
| 670 | return NULL; |
| 671 | } |
| 672 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 673 | /*! \brief Unregister, close and delete a log target |
| 674 | * \param target[in] log target to unregister, close and delete */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 675 | void log_target_destroy(struct log_target *target) |
| 676 | { |
| 677 | |
| 678 | /* just in case, to make sure we don't have any references */ |
| 679 | log_del_target(target); |
| 680 | |
| 681 | if (target->output == &_file_output) { |
Sylvain Munaut | af5ee34 | 2010-09-17 14:38:17 +0200 | [diff] [blame] | 682 | /* since C89/C99 says stderr is a macro, we can safely do this! */ |
| 683 | #ifdef stderr |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 684 | /* don't close stderr */ |
Sylvain Munaut | af5ee34 | 2010-09-17 14:38:17 +0200 | [diff] [blame] | 685 | if (target->tgt_file.out != stderr) |
| 686 | #endif |
| 687 | { |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 688 | fclose(target->tgt_file.out); |
| 689 | target->tgt_file.out = NULL; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | talloc_free(target); |
| 694 | } |
| 695 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 696 | /*! \brief close and re-open a log file (for log file rotation) |
| 697 | * \param[in] target log target to re-open |
| 698 | * \returns 0 in case of success; negative otherwise */ |
Harald Welte | 3086c39 | 2010-08-25 19:10:50 +0200 | [diff] [blame] | 699 | int log_target_file_reopen(struct log_target *target) |
| 700 | { |
| 701 | fclose(target->tgt_file.out); |
| 702 | |
| 703 | target->tgt_file.out = fopen(target->tgt_file.fname, "a"); |
| 704 | if (!target->tgt_file.out) |
| 705 | return -errno; |
| 706 | |
| 707 | /* we assume target->output already to be set */ |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 712 | /*! \brief close and re-open all log files (for log file rotation) |
| 713 | * \returns 0 in case of success; negative otherwise */ |
Harald Welte | 4de854d | 2013-03-18 19:01:40 +0100 | [diff] [blame] | 714 | int log_targets_reopen(void) |
| 715 | { |
| 716 | struct log_target *tar; |
| 717 | int rc = 0; |
| 718 | |
| 719 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
| 720 | switch (tar->type) { |
| 721 | case LOG_TGT_TYPE_FILE: |
| 722 | if (log_target_file_reopen(tar) < 0) |
| 723 | rc = -1; |
| 724 | break; |
| 725 | default: |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return rc; |
| 731 | } |
| 732 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 733 | /*! \brief Generates the logging command string for VTY |
| 734 | * \param[in] unused_info Deprecated parameter, no longer used! |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 735 | * \returns vty command string for use by VTY command node |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 736 | */ |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 737 | const char *log_vty_command_string(const struct log_info *unused_info) |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 738 | { |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 739 | struct log_info *info = osmo_log_info; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 740 | int len = 0, offset = 0, ret, i, rem; |
| 741 | int size = strlen("logging level () ()") + 1; |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 742 | char *str; |
| 743 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 744 | for (i = 0; i < info->num_cat; i++) { |
| 745 | if (info->cat[i].name == NULL) |
| 746 | continue; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 747 | size += strlen(info->cat[i].name) + 1; |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 748 | } |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 749 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 750 | for (i = 0; i < LOGLEVEL_DEFS; i++) |
| 751 | size += strlen(loglevel_strs[i].str) + 1; |
| 752 | |
| 753 | rem = size; |
Pablo Neira Ayuso | f1fae4d | 2011-05-03 22:32:42 +0200 | [diff] [blame] | 754 | str = talloc_zero_size(tall_log_ctx, size); |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 755 | if (!str) |
| 756 | return NULL; |
| 757 | |
Holger Hans Peter Freyther | 952a18e | 2011-03-29 17:03:56 +0200 | [diff] [blame] | 758 | ret = snprintf(str + offset, rem, "logging level (all|"); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 759 | if (ret < 0) |
| 760 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 761 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 762 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 763 | for (i = 0; i < info->num_cat; i++) { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 764 | if (info->cat[i].name) { |
| 765 | int j, name_len = strlen(info->cat[i].name)+1; |
| 766 | char name[name_len]; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 767 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 768 | for (j = 0; j < name_len; j++) |
| 769 | name[j] = tolower(info->cat[i].name[j]); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 770 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 771 | name[name_len-1] = '\0'; |
| 772 | ret = snprintf(str + offset, rem, "%s|", name+1); |
| 773 | if (ret < 0) |
| 774 | goto err; |
| 775 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 776 | } |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 777 | } |
| 778 | offset--; /* to remove the trailing | */ |
| 779 | rem++; |
| 780 | |
| 781 | ret = snprintf(str + offset, rem, ") ("); |
| 782 | if (ret < 0) |
| 783 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 784 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 785 | |
| 786 | for (i = 0; i < LOGLEVEL_DEFS; i++) { |
| 787 | int j, loglevel_str_len = strlen(loglevel_strs[i].str)+1; |
| 788 | char loglevel_str[loglevel_str_len]; |
| 789 | |
| 790 | for (j = 0; j < loglevel_str_len; j++) |
| 791 | loglevel_str[j] = tolower(loglevel_strs[i].str[j]); |
| 792 | |
| 793 | loglevel_str[loglevel_str_len-1] = '\0'; |
| 794 | ret = snprintf(str + offset, rem, "%s|", loglevel_str); |
| 795 | if (ret < 0) |
| 796 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 797 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 798 | } |
| 799 | offset--; /* to remove the trailing | */ |
| 800 | rem++; |
| 801 | |
| 802 | ret = snprintf(str + offset, rem, ")"); |
| 803 | if (ret < 0) |
| 804 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 805 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 806 | err: |
Pablo Neira Ayuso | 534ba81 | 2011-05-03 22:32:48 +0200 | [diff] [blame] | 807 | str[size-1] = '\0'; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 808 | return str; |
| 809 | } |
| 810 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 811 | /*! \brief Generates the logging command description for VTY |
| 812 | * \param[in] unused_info Deprecated parameter, no longer used! |
Harald Welte | 2d2e2cc | 2016-04-25 12:11:20 +0200 | [diff] [blame] | 813 | * \returns logging command description for use by VTY command node |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 814 | */ |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 815 | const char *log_vty_command_description(const struct log_info *unused_info) |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 816 | { |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 817 | struct log_info *info = osmo_log_info; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 818 | char *str; |
| 819 | int i, ret, len = 0, offset = 0, rem; |
| 820 | unsigned int size = |
| 821 | strlen(LOGGING_STR |
| 822 | "Set the log level for a specified category\n") + 1; |
| 823 | |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 824 | for (i = 0; i < info->num_cat; i++) { |
| 825 | if (info->cat[i].name == NULL) |
| 826 | continue; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 827 | size += strlen(info->cat[i].description) + 1; |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 828 | } |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 829 | |
| 830 | for (i = 0; i < LOGLEVEL_DEFS; i++) |
| 831 | size += strlen(loglevel_descriptions[i]) + 1; |
| 832 | |
Pablo Neira Ayuso | d6b5195 | 2011-05-03 22:32:32 +0200 | [diff] [blame] | 833 | size += strlen("Global setting for all subsystems") + 1; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 834 | rem = size; |
Pablo Neira Ayuso | f1fae4d | 2011-05-03 22:32:42 +0200 | [diff] [blame] | 835 | str = talloc_zero_size(tall_log_ctx, size); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 836 | if (!str) |
| 837 | return NULL; |
| 838 | |
| 839 | ret = snprintf(str + offset, rem, LOGGING_STR |
| 840 | "Set the log level for a specified category\n"); |
| 841 | if (ret < 0) |
| 842 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 843 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 844 | |
Pablo Neira Ayuso | d6b5195 | 2011-05-03 22:32:32 +0200 | [diff] [blame] | 845 | ret = snprintf(str + offset, rem, |
| 846 | "Global setting for all subsystems\n"); |
| 847 | if (ret < 0) |
| 848 | goto err; |
| 849 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
| 850 | |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 851 | for (i = 0; i < info->num_cat; i++) { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 852 | if (info->cat[i].name == NULL) |
| 853 | continue; |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 854 | ret = snprintf(str + offset, rem, "%s\n", |
| 855 | info->cat[i].description); |
| 856 | if (ret < 0) |
| 857 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 858 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 859 | } |
| 860 | for (i = 0; i < LOGLEVEL_DEFS; i++) { |
| 861 | ret = snprintf(str + offset, rem, "%s\n", |
| 862 | loglevel_descriptions[i]); |
| 863 | if (ret < 0) |
| 864 | goto err; |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 865 | OSMO_SNPRINTF_RET(ret, rem, offset, len); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 866 | } |
| 867 | err: |
Pablo Neira Ayuso | 534ba81 | 2011-05-03 22:32:48 +0200 | [diff] [blame] | 868 | str[size-1] = '\0'; |
Harald Welte | 7638af9 | 2010-05-11 16:39:22 +0200 | [diff] [blame] | 869 | return str; |
| 870 | } |
| 871 | |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 872 | /*! \brief Initialize the Osmocom logging core |
| 873 | * \param[in] inf Information regarding logging categories |
| 874 | * \param[in] ctx \ref talloc context for logging allocations |
| 875 | * \returns 0 in case of success, negative in case of error |
| 876 | */ |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 877 | int log_init(const struct log_info *inf, void *ctx) |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 878 | { |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 879 | int i; |
| 880 | |
| 881 | tall_log_ctx = talloc_named_const(ctx, 1, "logging"); |
| 882 | if (!tall_log_ctx) |
| 883 | return -ENOMEM; |
| 884 | |
| 885 | osmo_log_info = talloc_zero(tall_log_ctx, struct log_info); |
| 886 | if (!osmo_log_info) |
| 887 | return -ENOMEM; |
| 888 | |
Holger Hans Peter Freyther | b7d0f46 | 2013-12-29 19:38:01 +0100 | [diff] [blame] | 889 | osmo_log_info->filter_fn = inf->filter_fn; |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 890 | osmo_log_info->num_cat_user = inf->num_cat; |
| 891 | /* total number = number of user cat + library cat */ |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 892 | osmo_log_info->num_cat = inf->num_cat + ARRAY_SIZE(internal_cat); |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 893 | |
| 894 | osmo_log_info->cat = talloc_zero_array(osmo_log_info, |
| 895 | struct log_info_cat, |
| 896 | osmo_log_info->num_cat); |
| 897 | if (!osmo_log_info->cat) { |
| 898 | talloc_free(osmo_log_info); |
| 899 | osmo_log_info = NULL; |
| 900 | return -ENOMEM; |
| 901 | } |
| 902 | |
| 903 | /* copy over the user part */ |
| 904 | for (i = 0; i < inf->num_cat; i++) { |
Holger Hans Peter Freyther | 06f6455 | 2012-09-11 10:31:29 +0200 | [diff] [blame] | 905 | memcpy((struct log_info_cat *) &osmo_log_info->cat[i], |
| 906 | &inf->cat[i], |
Harald Welte | b43bc04 | 2011-06-27 10:29:17 +0200 | [diff] [blame] | 907 | sizeof(struct log_info_cat)); |
| 908 | } |
| 909 | |
| 910 | /* copy over the library part */ |
Harald Welte | 9fe1652 | 2011-06-27 14:00:03 +0200 | [diff] [blame] | 911 | for (i = 0; i < ARRAY_SIZE(internal_cat); i++) { |
Harald Welte | ce9fec3 | 2011-06-27 14:19:16 +0200 | [diff] [blame] | 912 | unsigned int cn = osmo_log_info->num_cat_user + i; |
Holger Hans Peter Freyther | 06f6455 | 2012-09-11 10:31:29 +0200 | [diff] [blame] | 913 | memcpy((struct log_info_cat *) &osmo_log_info->cat[cn], |
Harald Welte | 9fe1652 | 2011-06-27 14:00:03 +0200 | [diff] [blame] | 914 | &internal_cat[i], sizeof(struct log_info_cat)); |
| 915 | } |
| 916 | |
| 917 | return 0; |
Harald Welte | 4a2bb9e | 2010-03-26 09:33:40 +0800 | [diff] [blame] | 918 | } |
Harald Welte | 18fc465 | 2011-08-17 14:14:17 +0200 | [diff] [blame] | 919 | |
Harald Welte | 69e6c3c | 2016-04-20 10:41:27 +0200 | [diff] [blame] | 920 | /* \brief De-initialize the Osmocom logging core |
| 921 | * This function destroys all targets and releases associated memory */ |
| 922 | void log_fini(void) |
| 923 | { |
| 924 | struct log_target *tar, *tar2; |
| 925 | |
| 926 | llist_for_each_entry_safe(tar, tar2, &osmo_log_target_list, entry) |
| 927 | log_target_destroy(tar); |
| 928 | |
| 929 | talloc_free(osmo_log_info); |
| 930 | osmo_log_info = NULL; |
| 931 | talloc_free(tall_log_ctx); |
| 932 | tall_log_ctx = NULL; |
| 933 | } |
| 934 | |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 935 | /*! \brief Check whether a log entry will be generated. |
| 936 | * \returns != 0 if a log entry might get generated by at least one target */ |
| 937 | int log_check_level(int subsys, unsigned int level) |
| 938 | { |
| 939 | struct log_target *tar; |
| 940 | |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 941 | subsys = map_subsys(subsys); |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 942 | |
| 943 | /* TODO: The following could/should be cached (update on config) */ |
| 944 | |
| 945 | llist_for_each_entry(tar, &osmo_log_target_list, entry) { |
Holger Hans Peter Freyther | e0dc6a1 | 2015-12-21 14:45:16 +0100 | [diff] [blame] | 946 | if (!check_log_to_target(tar, subsys, level)) |
Jacob Erlbeck | de6dd72 | 2015-11-17 11:52:24 +0100 | [diff] [blame] | 947 | continue; |
| 948 | |
| 949 | /* This might get logged (ignoring filters) */ |
| 950 | return 1; |
| 951 | } |
| 952 | |
| 953 | /* We are sure, that this will not be logged. */ |
| 954 | return 0; |
| 955 | } |
| 956 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 957 | /*! @} */ |