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