Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 3 | * (C) 2009-2014 by Holger Hans Peter Freyther |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | * |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 27 | #include "../../config.h" |
| 28 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 29 | #include <osmocom/core/talloc.h> |
| 30 | #include <osmocom/core/logging.h> |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame^] | 31 | #include <osmocom/core/logging_internal.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 32 | #include <osmocom/core/utils.h> |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 33 | #include <osmocom/core/strrb.h> |
| 34 | #include <osmocom/core/loggingrb.h> |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 35 | #include <osmocom/core/gsmtap.h> |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 36 | |
| 37 | #include <osmocom/vty/command.h> |
| 38 | #include <osmocom/vty/buffer.h> |
| 39 | #include <osmocom/vty/vty.h> |
| 40 | #include <osmocom/vty/telnet_interface.h> |
| 41 | #include <osmocom/vty/logging.h> |
| 42 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 43 | #define LOG_STR "Configure logging sub-system\n" |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame^] | 44 | #define LEVEL_STR "Set the log level for a specified category\n" |
| 45 | |
| 46 | #define CATEGORY_ALL_STR "Global setting for all subsystems\n" |
| 47 | |
| 48 | #define LOG_LEVEL_ARGS "debug|info|notice|error|fatal" |
| 49 | #define LOG_LEVEL_STRS \ |
| 50 | "Log debug messages and higher levels\n" \ |
| 51 | "Log informational messages and higher levels\n" \ |
| 52 | "Log noticeable messages and higher levels\n" \ |
| 53 | "Log error messages and higher levels\n" \ |
| 54 | "Log only fatal messages\n" |
| 55 | |
| 56 | #define EVERYTHING_STR "Don't use. It doesn't log anything\n" |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 57 | |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 58 | /*! \file logging_vty.c |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 59 | * Configuration of logging from VTY |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 60 | * |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 61 | * This module implements |
| 62 | * - functions that permit configuration of the libosmocore logging |
| 63 | * framework from VTY commands in the configure -> logging node. |
| 64 | * |
| 65 | * - functions that permit logging *to* a VTY session. Basically each |
| 66 | * VTY session gets its own log target, with configurable |
| 67 | * per-subsystem log levels. This is performed internally via the |
| 68 | * \ref log_target_create_vty function. |
| 69 | * |
| 70 | * You have to call \ref logging_vty_add_cmds from your application |
| 71 | * once to enable both of the above. |
| 72 | * |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 73 | */ |
| 74 | |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 75 | static void _vty_output(struct log_target *tgt, |
| 76 | unsigned int level, const char *line) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 77 | { |
| 78 | struct vty *vty = tgt->tgt_vty.vty; |
| 79 | vty_out(vty, "%s", line); |
| 80 | /* This is an ugly hack, but there is no easy way... */ |
| 81 | if (strchr(line, '\n')) |
| 82 | vty_out(vty, "\r"); |
| 83 | } |
| 84 | |
| 85 | struct log_target *log_target_create_vty(struct vty *vty) |
| 86 | { |
| 87 | struct log_target *target; |
| 88 | |
| 89 | target = log_target_create(); |
| 90 | if (!target) |
| 91 | return NULL; |
| 92 | |
| 93 | target->tgt_vty.vty = vty; |
| 94 | target->output = _vty_output; |
| 95 | return target; |
| 96 | } |
| 97 | |
| 98 | DEFUN(enable_logging, |
| 99 | enable_logging_cmd, |
| 100 | "logging enable", |
| 101 | LOGGING_STR |
| 102 | "Enables logging to this vty\n") |
| 103 | { |
| 104 | struct telnet_connection *conn; |
| 105 | |
| 106 | conn = (struct telnet_connection *) vty->priv; |
| 107 | if (conn->dbg) { |
| 108 | vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE); |
| 109 | return CMD_WARNING; |
| 110 | } |
| 111 | |
| 112 | conn->dbg = log_target_create_vty(vty); |
| 113 | if (!conn->dbg) |
| 114 | return CMD_WARNING; |
| 115 | |
| 116 | log_add_target(conn->dbg); |
| 117 | return CMD_SUCCESS; |
| 118 | } |
| 119 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 120 | struct log_target *osmo_log_vty2tgt(struct vty *vty) |
| 121 | { |
| 122 | struct telnet_connection *conn; |
| 123 | |
| 124 | if (vty->node == CFG_LOG_NODE) |
| 125 | return vty->index; |
| 126 | |
| 127 | |
| 128 | conn = (struct telnet_connection *) vty->priv; |
| 129 | if (!conn->dbg) |
| 130 | vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE); |
| 131 | |
| 132 | return conn->dbg; |
| 133 | } |
| 134 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 135 | DEFUN(logging_fltr_all, |
| 136 | logging_fltr_all_cmd, |
| 137 | "logging filter all (0|1)", |
| 138 | LOGGING_STR FILTER_STR |
| 139 | "Do you want to log all messages?\n" |
| 140 | "Only print messages matched by other filters\n" |
| 141 | "Bypass filter and print all messages\n") |
| 142 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 143 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 144 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 145 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 146 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 147 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 148 | log_set_all_filter(tgt, atoi(argv[0])); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 149 | return CMD_SUCCESS; |
| 150 | } |
| 151 | |
| 152 | DEFUN(logging_use_clr, |
| 153 | logging_use_clr_cmd, |
| 154 | "logging color (0|1)", |
| 155 | LOGGING_STR "Configure color-printing for log messages\n" |
| 156 | "Don't use color for printing messages\n" |
| 157 | "Use color for printing messages\n") |
| 158 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 159 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 160 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 161 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 162 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 163 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 164 | log_set_use_color(tgt, atoi(argv[0])); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 165 | return CMD_SUCCESS; |
| 166 | } |
| 167 | |
| 168 | DEFUN(logging_prnt_timestamp, |
| 169 | logging_prnt_timestamp_cmd, |
| 170 | "logging timestamp (0|1)", |
| 171 | LOGGING_STR "Configure log message timestamping\n" |
| 172 | "Don't prefix each log message\n" |
| 173 | "Prefix each log message with current timestamp\n") |
| 174 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 175 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 176 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 177 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 178 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 179 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 180 | log_set_print_timestamp(tgt, atoi(argv[0])); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 181 | return CMD_SUCCESS; |
| 182 | } |
| 183 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 184 | DEFUN(logging_prnt_ext_timestamp, |
| 185 | logging_prnt_ext_timestamp_cmd, |
| 186 | "logging print extended-timestamp (0|1)", |
| 187 | LOGGING_STR "Log output settings\n" |
| 188 | "Configure log message timestamping\n" |
| 189 | "Don't prefix each log message\n" |
| 190 | "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n") |
| 191 | { |
| 192 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
| 193 | |
| 194 | if (!tgt) |
| 195 | return CMD_WARNING; |
| 196 | |
| 197 | log_set_print_extended_timestamp(tgt, atoi(argv[0])); |
| 198 | return CMD_SUCCESS; |
| 199 | } |
| 200 | |
| 201 | DEFUN(logging_prnt_cat, |
| 202 | logging_prnt_cat_cmd, |
| 203 | "logging print category (0|1)", |
| 204 | LOGGING_STR "Log output settings\n" |
| 205 | "Configure log message\n" |
| 206 | "Don't prefix each log message\n" |
| 207 | "Prefix each log message with category/subsystem name\n") |
| 208 | { |
| 209 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
| 210 | |
| 211 | if (!tgt) |
| 212 | return CMD_WARNING; |
| 213 | |
| 214 | log_set_print_category(tgt, atoi(argv[0])); |
| 215 | return CMD_SUCCESS; |
| 216 | } |
| 217 | |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 218 | DEFUN(logging_prnt_cat_hex, |
| 219 | logging_prnt_cat_hex_cmd, |
| 220 | "logging print category-hex (0|1)", |
| 221 | LOGGING_STR "Log output settings\n" |
| 222 | "Configure log message\n" |
| 223 | "Don't prefix each log message\n" |
| 224 | "Prefix each log message with category/subsystem nr in hex ('<000b>')\n") |
| 225 | { |
| 226 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
| 227 | |
| 228 | if (!tgt) |
| 229 | return CMD_WARNING; |
| 230 | |
| 231 | log_set_print_category_hex(tgt, atoi(argv[0])); |
| 232 | return CMD_SUCCESS; |
| 233 | } |
| 234 | |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 235 | DEFUN(logging_prnt_level, |
| 236 | logging_prnt_level_cmd, |
| 237 | "logging print level (0|1)", |
| 238 | LOGGING_STR "Log output settings\n" |
| 239 | "Configure log message\n" |
| 240 | "Don't prefix each log message\n" |
| 241 | "Prefix each log message with the log level name\n") |
| 242 | { |
| 243 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
| 244 | |
| 245 | if (!tgt) |
| 246 | return CMD_WARNING; |
| 247 | |
| 248 | log_set_print_level(tgt, atoi(argv[0])); |
| 249 | return CMD_SUCCESS; |
| 250 | } |
| 251 | |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 252 | static const struct value_string logging_print_file_args[] = { |
| 253 | { LOG_FILENAME_NONE, "0" }, |
| 254 | { LOG_FILENAME_PATH, "1" }, |
| 255 | { LOG_FILENAME_BASENAME, "basename" }, |
| 256 | { 0, NULL } |
| 257 | }; |
| 258 | |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 259 | DEFUN(logging_prnt_file, |
| 260 | logging_prnt_file_cmd, |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 261 | "logging print file (0|1|basename) [last]", |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 262 | LOGGING_STR "Log output settings\n" |
| 263 | "Configure log message\n" |
| 264 | "Don't prefix each log message\n" |
| 265 | "Prefix each log message with the source file and line\n" |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 266 | "Prefix each log message with the source file's basename (strip leading paths) and line\n" |
| 267 | "Log source file info at the end of a log line. If omitted, log source file info just" |
| 268 | " before the log text.\n") |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 269 | { |
| 270 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 271 | |
| 272 | if (!tgt) |
| 273 | return CMD_WARNING; |
| 274 | |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 275 | log_set_print_filename2(tgt, get_string_value(logging_print_file_args, argv[0])); |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 276 | if (argc > 1) |
| 277 | log_set_print_filename_pos(tgt, LOG_FILENAME_POS_LINE_END); |
| 278 | else |
| 279 | log_set_print_filename_pos(tgt, LOG_FILENAME_POS_HEADER_END); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 280 | return CMD_SUCCESS; |
| 281 | } |
| 282 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame^] | 283 | static void add_category_strings(char **cmd_str_p, char **doc_str_p, |
| 284 | const struct log_info *categories) |
| 285 | { |
| 286 | int i; |
| 287 | for (i = 0; i < categories->num_cat; i++) { |
| 288 | if (categories->cat[i].name == NULL) |
| 289 | continue; |
| 290 | /* skip the leading 'D' in each category name, hence '+ 1' */ |
| 291 | osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s", |
| 292 | i ? "|" : "", |
| 293 | osmo_str_tolower(categories->cat[i].name + 1)); |
| 294 | osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n", |
| 295 | categories->cat[i].description); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static void gen_logging_level_cmd_strs(struct cmd_element *cmd, |
| 300 | const char *level_args, const char *level_strs) |
| 301 | { |
| 302 | char *cmd_str = NULL; |
| 303 | char *doc_str = NULL; |
| 304 | |
| 305 | assert_loginfo(__func__); |
| 306 | |
| 307 | OSMO_ASSERT(cmd->string == NULL); |
| 308 | OSMO_ASSERT(cmd->doc == NULL); |
| 309 | |
| 310 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logging level (all|"); |
| 311 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 312 | LOGGING_STR |
| 313 | LEVEL_STR |
| 314 | CATEGORY_ALL_STR); |
| 315 | add_category_strings(&cmd_str, &doc_str, osmo_log_info); |
| 316 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args); |
| 317 | osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs); |
| 318 | |
| 319 | cmd->string = cmd_str; |
| 320 | cmd->doc = doc_str; |
| 321 | } |
| 322 | |
| 323 | /* logging level (all|<categories>) (everything|debug|...|fatal) */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 324 | DEFUN(logging_level, |
| 325 | logging_level_cmd, |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 326 | NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */ |
| 327 | NULL) /* same thing for helpstr. */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 328 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 329 | int category = log_parse_category(argv[0]); |
| 330 | int level = log_parse_level(argv[1]); |
| 331 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 332 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 333 | if (!tgt) |
| 334 | return CMD_WARNING; |
| 335 | |
| 336 | if (level < 0) { |
| 337 | vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 338 | return CMD_WARNING; |
| 339 | } |
| 340 | |
Max | ed0eda2 | 2017-07-06 17:09:01 +0200 | [diff] [blame] | 341 | if (strcmp(argv[1], "everything") == 0) { /* FIXME: remove this check once 'everything' is phased out */ |
| 342 | vty_out(vty, "%% Ignoring deprecated logging level %s%s", argv[1], VTY_NEWLINE); |
| 343 | return CMD_SUCCESS; |
| 344 | } |
| 345 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 346 | /* Check for special case where we want to set global log level */ |
| 347 | if (!strcmp(argv[0], "all")) { |
| 348 | log_set_log_level(tgt, level); |
| 349 | return CMD_SUCCESS; |
| 350 | } |
| 351 | |
| 352 | if (category < 0) { |
| 353 | vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE); |
| 354 | return CMD_WARNING; |
| 355 | } |
| 356 | |
| 357 | tgt->categories[category].enabled = 1; |
| 358 | tgt->categories[category].loglevel = level; |
| 359 | |
| 360 | return CMD_SUCCESS; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | DEFUN(logging_set_category_mask, |
| 364 | logging_set_category_mask_cmd, |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 365 | "logging set-log-mask MASK", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 366 | LOGGING_STR |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 367 | "Set the logmask of this logging target\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 368 | "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific" |
| 369 | " application, refer to the 'logging level' command. Optionally add individual log levels like" |
| 370 | " 'abc,1:mno,3:xyz,5', where the level numbers are" |
| 371 | " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG) |
| 372 | " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO) |
| 373 | " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE) |
| 374 | " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR) |
| 375 | " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL) |
| 376 | "\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 377 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 378 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 379 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 380 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 381 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 382 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 383 | log_parse_category_mask(tgt, argv[0]); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 384 | return CMD_SUCCESS; |
| 385 | } |
| 386 | |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 387 | ALIAS_DEPRECATED(logging_set_category_mask, |
| 388 | logging_set_category_mask_old_cmd, |
| 389 | "logging set log mask MASK", |
| 390 | LOGGING_STR |
| 391 | "Decide which categories to output.\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 392 | "Log commands\n" "Mask commands\n" |
| 393 | "'set log mask' is deprecated, please refer to the docs of 'set-log-mask' instead\n"); |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 394 | |
| 395 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 396 | DEFUN(diable_logging, |
| 397 | disable_logging_cmd, |
| 398 | "logging disable", |
| 399 | LOGGING_STR |
| 400 | "Disables logging to this vty\n") |
| 401 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 402 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
| 403 | struct telnet_connection *conn = (struct telnet_connection *) vty->priv; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 404 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 405 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 406 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 407 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 408 | log_del_target(tgt); |
| 409 | talloc_free(tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 410 | conn->dbg = NULL; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 411 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 412 | return CMD_SUCCESS; |
| 413 | } |
| 414 | |
| 415 | static void vty_print_logtarget(struct vty *vty, const struct log_info *info, |
| 416 | const struct log_target *tgt) |
| 417 | { |
| 418 | unsigned int i; |
| 419 | |
| 420 | vty_out(vty, " Global Loglevel: %s%s", |
| 421 | log_level_str(tgt->loglevel), VTY_NEWLINE); |
| 422 | vty_out(vty, " Use color: %s, Print Timestamp: %s%s", |
| 423 | tgt->use_color ? "On" : "Off", |
| 424 | tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE); |
| 425 | |
| 426 | vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE); |
| 427 | |
| 428 | for (i = 0; i < info->num_cat; i++) { |
| 429 | const struct log_category *cat = &tgt->categories[i]; |
Daniel Willmann | 55363a9 | 2016-11-15 10:05:51 +0100 | [diff] [blame] | 430 | /* Skip categories that were not initialized */ |
| 431 | if (!info->cat[i].name) |
| 432 | continue; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 433 | vty_out(vty, " %-10s %-10s %-8s %s%s", |
| 434 | info->cat[i].name+1, log_level_str(cat->loglevel), |
| 435 | cat->enabled ? "Enabled" : "Disabled", |
| 436 | info->cat[i].description, |
| 437 | VTY_NEWLINE); |
| 438 | } |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 439 | |
| 440 | vty_out(vty, " Log Filter 'ALL': %s%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 441 | tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled", |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 442 | VTY_NEWLINE); |
| 443 | |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 444 | /* print application specific filters */ |
| 445 | if (info->print_fn) |
| 446 | info->print_fn(vty, info, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | #define SHOW_LOG_STR "Show current logging configuration\n" |
| 450 | |
| 451 | DEFUN(show_logging_vty, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 452 | show_logging_vty_cmd, |
| 453 | "show logging vty", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 454 | SHOW_STR SHOW_LOG_STR |
| 455 | "Show current logging configuration for this vty\n") |
| 456 | { |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 457 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 458 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 459 | if (!tgt) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 460 | return CMD_WARNING; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 461 | |
| 462 | vty_print_logtarget(vty, osmo_log_info, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 463 | |
| 464 | return CMD_SUCCESS; |
| 465 | } |
| 466 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 467 | DEFUN(show_alarms, |
| 468 | show_alarms_cmd, |
| 469 | "show alarms", |
| 470 | SHOW_STR SHOW_LOG_STR |
| 471 | "Show the contents of the logging ringbuffer\n") |
| 472 | { |
| 473 | int i, num_alarms; |
| 474 | struct osmo_strrb *rb; |
| 475 | struct log_target *tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 476 | if (!tgt) { |
| 477 | vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s", |
| 478 | VTY_NEWLINE); |
| 479 | return CMD_WARNING; |
| 480 | } |
| 481 | |
| 482 | rb = tgt->tgt_rb.rb; |
| 483 | num_alarms = osmo_strrb_elements(rb); |
| 484 | |
| 485 | vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE); |
| 486 | |
| 487 | for (i = 0; i < num_alarms; i++) |
| 488 | vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i), |
| 489 | VTY_NEWLINE); |
| 490 | |
| 491 | return CMD_SUCCESS; |
| 492 | } |
| 493 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 494 | gDEFUN(cfg_description, cfg_description_cmd, |
| 495 | "description .TEXT", |
Thorsten Alteholz | a81055d | 2017-03-02 22:13:48 +0100 | [diff] [blame] | 496 | "Save human-readable description of the object\n" |
Holger Hans Peter Freyther | c9b3e06 | 2012-07-25 13:02:49 +0200 | [diff] [blame] | 497 | "Text until the end of the line\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 498 | { |
| 499 | char **dptr = vty->index_sub; |
| 500 | |
| 501 | if (!dptr) { |
| 502 | vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); |
| 503 | return CMD_WARNING; |
| 504 | } |
| 505 | |
Holger Hans Peter Freyther | ff0670e | 2011-02-24 14:20:41 +0100 | [diff] [blame] | 506 | if (*dptr) |
| 507 | talloc_free(*dptr); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 508 | *dptr = argv_concat(argv, argc, 0); |
Holger Hans Peter Freyther | 6a75d16 | 2013-07-14 09:07:11 +0200 | [diff] [blame] | 509 | if (!*dptr) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 510 | return CMD_WARNING; |
| 511 | |
| 512 | return CMD_SUCCESS; |
| 513 | } |
| 514 | |
| 515 | gDEFUN(cfg_no_description, cfg_no_description_cmd, |
| 516 | "no description", |
| 517 | NO_STR |
| 518 | "Remove description of the object\n") |
| 519 | { |
| 520 | char **dptr = vty->index_sub; |
| 521 | |
| 522 | if (!dptr) { |
| 523 | vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); |
| 524 | return CMD_WARNING; |
| 525 | } |
| 526 | |
| 527 | if (*dptr) { |
| 528 | talloc_free(*dptr); |
| 529 | *dptr = NULL; |
| 530 | } |
| 531 | |
| 532 | return CMD_SUCCESS; |
| 533 | } |
| 534 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 535 | /* Support for configuration of log targets != the current vty */ |
| 536 | |
| 537 | struct cmd_node cfg_log_node = { |
| 538 | CFG_LOG_NODE, |
| 539 | "%s(config-log)# ", |
| 540 | 1 |
| 541 | }; |
| 542 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 543 | #ifdef HAVE_SYSLOG_H |
| 544 | |
| 545 | #include <syslog.h> |
| 546 | |
| 547 | static const int local_sysl_map[] = { |
| 548 | [0] = LOG_LOCAL0, |
| 549 | [1] = LOG_LOCAL1, |
| 550 | [2] = LOG_LOCAL2, |
| 551 | [3] = LOG_LOCAL3, |
| 552 | [4] = LOG_LOCAL4, |
| 553 | [5] = LOG_LOCAL5, |
| 554 | [6] = LOG_LOCAL6, |
| 555 | [7] = LOG_LOCAL7 |
| 556 | }; |
| 557 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 558 | /* From VTY core code */ |
| 559 | extern struct host host; |
| 560 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 561 | static int _cfg_log_syslog(struct vty *vty, int facility) |
| 562 | { |
| 563 | struct log_target *tgt; |
| 564 | |
| 565 | /* First delete the old syslog target, if any */ |
| 566 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 567 | if (tgt) |
| 568 | log_target_destroy(tgt); |
| 569 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 570 | tgt = log_target_create_syslog(host.app_info->name, 0, facility); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 571 | if (!tgt) { |
| 572 | vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE); |
| 573 | return CMD_WARNING; |
| 574 | } |
| 575 | log_add_target(tgt); |
| 576 | |
| 577 | vty->index = tgt; |
| 578 | vty->node = CFG_LOG_NODE; |
| 579 | |
| 580 | return CMD_SUCCESS; |
| 581 | } |
| 582 | |
| 583 | DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd, |
| 584 | "log syslog local <0-7>", |
| 585 | LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n" |
| 586 | "Local facility number\n") |
| 587 | { |
| 588 | int local = atoi(argv[0]); |
| 589 | int facility = local_sysl_map[local]; |
| 590 | |
| 591 | return _cfg_log_syslog(vty, facility); |
| 592 | } |
| 593 | |
| 594 | static struct value_string sysl_level_names[] = { |
| 595 | { LOG_AUTHPRIV, "authpriv" }, |
| 596 | { LOG_CRON, "cron" }, |
| 597 | { LOG_DAEMON, "daemon" }, |
| 598 | { LOG_FTP, "ftp" }, |
| 599 | { LOG_LPR, "lpr" }, |
| 600 | { LOG_MAIL, "mail" }, |
| 601 | { LOG_NEWS, "news" }, |
| 602 | { LOG_USER, "user" }, |
| 603 | { LOG_UUCP, "uucp" }, |
| 604 | /* only for value -> string conversion */ |
| 605 | { LOG_LOCAL0, "local 0" }, |
| 606 | { LOG_LOCAL1, "local 1" }, |
| 607 | { LOG_LOCAL2, "local 2" }, |
| 608 | { LOG_LOCAL3, "local 3" }, |
| 609 | { LOG_LOCAL4, "local 4" }, |
| 610 | { LOG_LOCAL5, "local 5" }, |
| 611 | { LOG_LOCAL6, "local 6" }, |
| 612 | { LOG_LOCAL7, "local 7" }, |
| 613 | { 0, NULL } |
| 614 | }; |
| 615 | |
| 616 | DEFUN(cfg_log_syslog, cfg_log_syslog_cmd, |
| 617 | "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)", |
Holger Hans Peter Freyther | a4463fd | 2011-10-03 23:17:36 +0200 | [diff] [blame] | 618 | LOG_STR "Logging via syslog\n" |
| 619 | "Security/authorization messages facility\n" |
| 620 | "Clock daemon (cron/at) facility\n" |
| 621 | "General system daemon facility\n" |
| 622 | "Ftp daemon facility\n" |
| 623 | "Line printer facility\n" |
| 624 | "Mail facility\n" |
| 625 | "News facility\n" |
| 626 | "Generic facility\n" |
| 627 | "UUCP facility\n") |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 628 | { |
| 629 | int facility = get_string_value(sysl_level_names, argv[0]); |
| 630 | |
| 631 | return _cfg_log_syslog(vty, facility); |
| 632 | } |
| 633 | |
| 634 | DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd, |
| 635 | "no log syslog", |
| 636 | NO_STR LOG_STR "Logging via syslog\n") |
| 637 | { |
| 638 | struct log_target *tgt; |
| 639 | |
| 640 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 641 | if (!tgt) { |
| 642 | vty_out(vty, "%% No syslog target found%s", |
| 643 | VTY_NEWLINE); |
| 644 | return CMD_WARNING; |
| 645 | } |
| 646 | |
| 647 | log_target_destroy(tgt); |
| 648 | |
| 649 | return CMD_SUCCESS; |
| 650 | } |
| 651 | #endif /* HAVE_SYSLOG_H */ |
| 652 | |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 653 | DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd, |
| 654 | "log gsmtap [HOSTNAME]", |
Neels Hofmeyr | fd9ec3b | 2016-12-11 01:48:26 +0100 | [diff] [blame] | 655 | LOG_STR "Logging via GSMTAP\n" |
| 656 | "Host name to send the GSMTAP logging to (UDP port 4729)\n") |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 657 | { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 658 | const char *hostname = argc ? argv[0] : "127.0.0.1"; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 659 | struct log_target *tgt; |
| 660 | |
| 661 | tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname); |
| 662 | if (!tgt) { |
| 663 | tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT, |
| 664 | host.app_info->name, false, |
| 665 | true); |
| 666 | if (!tgt) { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 667 | vty_out(vty, "%% Unable to create GSMTAP log for %s%s", |
| 668 | hostname, VTY_NEWLINE); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 669 | return CMD_WARNING; |
| 670 | } |
| 671 | log_add_target(tgt); |
| 672 | } |
| 673 | |
| 674 | vty->index = tgt; |
| 675 | vty->node = CFG_LOG_NODE; |
| 676 | |
| 677 | return CMD_SUCCESS; |
| 678 | } |
| 679 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 680 | DEFUN(cfg_log_stderr, cfg_log_stderr_cmd, |
| 681 | "log stderr", |
| 682 | LOG_STR "Logging via STDERR of the process\n") |
| 683 | { |
| 684 | struct log_target *tgt; |
| 685 | |
| 686 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 687 | if (!tgt) { |
| 688 | tgt = log_target_create_stderr(); |
| 689 | if (!tgt) { |
| 690 | vty_out(vty, "%% Unable to create stderr log%s", |
| 691 | VTY_NEWLINE); |
| 692 | return CMD_WARNING; |
| 693 | } |
| 694 | log_add_target(tgt); |
| 695 | } |
| 696 | |
| 697 | vty->index = tgt; |
| 698 | vty->node = CFG_LOG_NODE; |
| 699 | |
| 700 | return CMD_SUCCESS; |
| 701 | } |
| 702 | |
| 703 | DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd, |
| 704 | "no log stderr", |
| 705 | NO_STR LOG_STR "Logging via STDERR of the process\n") |
| 706 | { |
| 707 | struct log_target *tgt; |
| 708 | |
| 709 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 710 | if (!tgt) { |
| 711 | vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE); |
| 712 | return CMD_WARNING; |
| 713 | } |
| 714 | |
| 715 | log_target_destroy(tgt); |
| 716 | |
| 717 | return CMD_SUCCESS; |
| 718 | } |
| 719 | |
| 720 | DEFUN(cfg_log_file, cfg_log_file_cmd, |
| 721 | "log file .FILENAME", |
| 722 | LOG_STR "Logging to text file\n" "Filename\n") |
| 723 | { |
| 724 | const char *fname = argv[0]; |
| 725 | struct log_target *tgt; |
| 726 | |
| 727 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 728 | if (!tgt) { |
| 729 | tgt = log_target_create_file(fname); |
| 730 | if (!tgt) { |
| 731 | vty_out(vty, "%% Unable to create file `%s'%s", |
| 732 | fname, VTY_NEWLINE); |
| 733 | return CMD_WARNING; |
| 734 | } |
| 735 | log_add_target(tgt); |
| 736 | } |
| 737 | |
| 738 | vty->index = tgt; |
| 739 | vty->node = CFG_LOG_NODE; |
| 740 | |
| 741 | return CMD_SUCCESS; |
| 742 | } |
| 743 | |
| 744 | |
| 745 | DEFUN(cfg_no_log_file, cfg_no_log_file_cmd, |
| 746 | "no log file .FILENAME", |
| 747 | NO_STR LOG_STR "Logging to text file\n" "Filename\n") |
| 748 | { |
| 749 | const char *fname = argv[0]; |
| 750 | struct log_target *tgt; |
| 751 | |
| 752 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 753 | if (!tgt) { |
| 754 | vty_out(vty, "%% No such log file `%s'%s", |
| 755 | fname, VTY_NEWLINE); |
| 756 | return CMD_WARNING; |
| 757 | } |
| 758 | |
| 759 | log_target_destroy(tgt); |
| 760 | |
| 761 | return CMD_SUCCESS; |
| 762 | } |
| 763 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 764 | DEFUN(cfg_log_alarms, cfg_log_alarms_cmd, |
| 765 | "log alarms <2-32700>", |
| 766 | LOG_STR "Logging alarms to osmo_strrb\n" |
| 767 | "Maximum number of messages to log\n") |
| 768 | { |
| 769 | struct log_target *tgt; |
| 770 | unsigned int rbsize = atoi(argv[0]); |
| 771 | |
| 772 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 773 | if (tgt) |
| 774 | log_target_destroy(tgt); |
| 775 | |
| 776 | tgt = log_target_create_rb(rbsize); |
| 777 | if (!tgt) { |
| 778 | vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s", |
| 779 | rbsize, VTY_NEWLINE); |
| 780 | return CMD_WARNING; |
| 781 | } |
| 782 | log_add_target(tgt); |
| 783 | |
| 784 | vty->index = tgt; |
| 785 | vty->node = CFG_LOG_NODE; |
| 786 | |
| 787 | return CMD_SUCCESS; |
| 788 | } |
| 789 | |
| 790 | DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd, |
| 791 | "no log alarms", |
| 792 | NO_STR LOG_STR "Logging alarms to osmo_strrb\n") |
| 793 | { |
| 794 | struct log_target *tgt; |
| 795 | |
| 796 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 797 | if (!tgt) { |
| 798 | vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE); |
| 799 | return CMD_WARNING; |
| 800 | } |
| 801 | |
| 802 | log_target_destroy(tgt); |
| 803 | |
| 804 | return CMD_SUCCESS; |
| 805 | } |
| 806 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 807 | static int config_write_log_single(struct vty *vty, struct log_target *tgt) |
| 808 | { |
| 809 | int i; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 810 | |
| 811 | switch (tgt->type) { |
| 812 | case LOG_TGT_TYPE_VTY: |
| 813 | return 1; |
| 814 | break; |
| 815 | case LOG_TGT_TYPE_STDERR: |
| 816 | vty_out(vty, "log stderr%s", VTY_NEWLINE); |
| 817 | break; |
| 818 | case LOG_TGT_TYPE_SYSLOG: |
| 819 | #ifdef HAVE_SYSLOG_H |
| 820 | vty_out(vty, "log syslog %s%s", |
| 821 | get_value_string(sysl_level_names, |
| 822 | tgt->tgt_syslog.facility), |
| 823 | VTY_NEWLINE); |
| 824 | #endif |
| 825 | break; |
| 826 | case LOG_TGT_TYPE_FILE: |
| 827 | vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE); |
| 828 | break; |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 829 | case LOG_TGT_TYPE_STRRB: |
| 830 | vty_out(vty, "log alarms %zu%s", |
| 831 | log_target_rb_avail_size(tgt), VTY_NEWLINE); |
| 832 | break; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 833 | case LOG_TGT_TYPE_GSMTAP: |
| 834 | vty_out(vty, "log gsmtap %s%s", |
| 835 | tgt->tgt_gsmtap.hostname, VTY_NEWLINE); |
| 836 | break; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Harald Welte | 2da47f1 | 2012-10-22 19:31:54 +0200 | [diff] [blame] | 839 | vty_out(vty, " logging filter all %u%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 840 | tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE); |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 841 | /* save filters outside of libosmocore, i.e. in app code */ |
| 842 | if (osmo_log_info->save_fn) |
| 843 | osmo_log_info->save_fn(vty, osmo_log_info, tgt); |
Harald Welte | 2da47f1 | 2012-10-22 19:31:54 +0200 | [diff] [blame] | 844 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 845 | vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0, |
| 846 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 879acef | 2015-01-27 11:06:51 +0100 | [diff] [blame] | 847 | vty_out(vty, " logging print category %d%s", |
Michael McTernan | 7893346 | 2015-03-20 15:29:25 +0100 | [diff] [blame] | 848 | tgt->print_category ? 1 : 0, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 849 | if (tgt->print_ext_timestamp) |
| 850 | vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE); |
| 851 | else |
| 852 | vty_out(vty, " logging timestamp %u%s", |
| 853 | tgt->print_timestamp ? 1 : 0, VTY_NEWLINE); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 854 | if (tgt->print_level) |
| 855 | vty_out(vty, " logging print level 1%s", VTY_NEWLINE); |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 856 | vty_out(vty, " logging print file %s%s", |
| 857 | get_value_string(logging_print_file_args, tgt->print_filename2), |
| 858 | VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 859 | |
| 860 | /* stupid old osmo logging API uses uppercase strings... */ |
Neels Hofmeyr | 7c74989 | 2018-09-07 03:01:38 +0200 | [diff] [blame] | 861 | vty_out(vty, " logging level all %s%s", osmo_str_tolower(log_level_str(tgt->loglevel)), |
| 862 | VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 863 | |
| 864 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
| 865 | const struct log_category *cat = &tgt->categories[i]; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 866 | |
Harald Welte | 1a02cfc | 2013-03-19 10:37:39 +0100 | [diff] [blame] | 867 | /* skip empty entries in the array */ |
| 868 | if (!osmo_log_info->cat[i].name) |
| 869 | continue; |
| 870 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 871 | /* stupid old osmo logging API uses uppercase strings... */ |
Neels Hofmeyr | 7c74989 | 2018-09-07 03:01:38 +0200 | [diff] [blame] | 872 | vty_out(vty, " logging level %s", osmo_str_tolower(osmo_log_info->cat[i].name+1)); |
| 873 | vty_out(vty, " %s%s", osmo_str_tolower(log_level_str(cat->loglevel)), VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 874 | } |
| 875 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 876 | return 1; |
| 877 | } |
| 878 | |
| 879 | static int config_write_log(struct vty *vty) |
| 880 | { |
| 881 | struct log_target *dbg = vty->index; |
| 882 | |
| 883 | llist_for_each_entry(dbg, &osmo_log_target_list, entry) |
| 884 | config_write_log_single(vty, dbg); |
| 885 | |
| 886 | return 1; |
| 887 | } |
| 888 | |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 889 | static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[]) |
| 890 | { |
| 891 | vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE); |
| 892 | return CMD_WARNING; |
| 893 | } |
| 894 | |
| 895 | void logging_vty_add_deprecated_subsys(void *ctx, const char *name) |
| 896 | { |
| 897 | struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element); |
| 898 | OSMO_ASSERT(cmd); |
| 899 | cmd->string = talloc_asprintf(cmd, "logging level %s (everything|debug|info|notice|error|fatal)", |
| 900 | name); |
| 901 | printf("%s\n", cmd->string); |
| 902 | cmd->func = log_deprecated_func; |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame^] | 903 | cmd->doc = LEVEL_STR |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 904 | "Deprecated Category\n"; |
| 905 | cmd->attr = CMD_ATTR_DEPRECATED; |
| 906 | |
| 907 | install_element(CFG_LOG_NODE, cmd); |
| 908 | } |
| 909 | |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 910 | /*! Register logging related commands to the VTY. Call this once from |
| 911 | * your application if you want to support those commands. */ |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 912 | void logging_vty_add_cmds() |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 913 | { |
| 914 | install_element_ve(&enable_logging_cmd); |
| 915 | install_element_ve(&disable_logging_cmd); |
| 916 | install_element_ve(&logging_fltr_all_cmd); |
| 917 | install_element_ve(&logging_use_clr_cmd); |
| 918 | install_element_ve(&logging_prnt_timestamp_cmd); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 919 | install_element_ve(&logging_prnt_ext_timestamp_cmd); |
| 920 | install_element_ve(&logging_prnt_cat_cmd); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 921 | install_element_ve(&logging_prnt_cat_hex_cmd); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 922 | install_element_ve(&logging_prnt_level_cmd); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 923 | install_element_ve(&logging_prnt_file_cmd); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 924 | install_element_ve(&logging_set_category_mask_cmd); |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 925 | install_element_ve(&logging_set_category_mask_old_cmd); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 926 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame^] | 927 | /* logging level (all|<categories>) (everything|debug|...|fatal) */ |
| 928 | gen_logging_level_cmd_strs(&logging_level_cmd, |
| 929 | "(everything|" LOG_LEVEL_ARGS ")", |
| 930 | EVERYTHING_STR LOG_LEVEL_STRS); |
| 931 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 932 | install_element_ve(&logging_level_cmd); |
| 933 | install_element_ve(&show_logging_vty_cmd); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 934 | install_element_ve(&show_alarms_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 935 | |
| 936 | install_node(&cfg_log_node, config_write_log); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 937 | install_element(CFG_LOG_NODE, &logging_fltr_all_cmd); |
| 938 | install_element(CFG_LOG_NODE, &logging_use_clr_cmd); |
| 939 | install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 940 | install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd); |
| 941 | install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 942 | install_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 943 | install_element(CFG_LOG_NODE, &logging_prnt_level_cmd); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 944 | install_element(CFG_LOG_NODE, &logging_prnt_file_cmd); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 945 | install_element(CFG_LOG_NODE, &logging_level_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 946 | |
| 947 | install_element(CONFIG_NODE, &cfg_log_stderr_cmd); |
| 948 | install_element(CONFIG_NODE, &cfg_no_log_stderr_cmd); |
| 949 | install_element(CONFIG_NODE, &cfg_log_file_cmd); |
| 950 | install_element(CONFIG_NODE, &cfg_no_log_file_cmd); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 951 | install_element(CONFIG_NODE, &cfg_log_alarms_cmd); |
| 952 | install_element(CONFIG_NODE, &cfg_no_log_alarms_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 953 | #ifdef HAVE_SYSLOG_H |
| 954 | install_element(CONFIG_NODE, &cfg_log_syslog_cmd); |
| 955 | install_element(CONFIG_NODE, &cfg_log_syslog_local_cmd); |
| 956 | install_element(CONFIG_NODE, &cfg_no_log_syslog_cmd); |
| 957 | #endif |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 958 | install_element(CONFIG_NODE, &cfg_log_gsmtap_cmd); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 959 | } |