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 | * |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 23 | #include "../../config.h" |
| 24 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
| 26 | #include <osmocom/core/logging.h> |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 27 | #include <osmocom/core/logging_internal.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 28 | #include <osmocom/core/utils.h> |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 29 | #include <osmocom/core/strrb.h> |
| 30 | #include <osmocom/core/loggingrb.h> |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 31 | #include <osmocom/core/gsmtap.h> |
Harald Welte | e4d9a2c | 2020-09-27 11:28:58 +0200 | [diff] [blame] | 32 | #include <osmocom/core/application.h> |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 33 | |
| 34 | #include <osmocom/vty/command.h> |
| 35 | #include <osmocom/vty/buffer.h> |
| 36 | #include <osmocom/vty/vty.h> |
| 37 | #include <osmocom/vty/telnet_interface.h> |
| 38 | #include <osmocom/vty/logging.h> |
| 39 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 40 | #define LOG_STR "Configure logging sub-system\n" |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 41 | #define LEVEL_STR "Set the log level for a specified category\n" |
| 42 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 43 | #define CATEGORY_ALL_STR "Deprecated alias for 'force-all'\n" |
| 44 | #define FORCE_ALL_STR \ |
| 45 | "Globally force all logging categories to a specific level. This is released by the" \ |
| 46 | " 'no logging level force-all' command. Note: any 'logging level <category> <level>'" \ |
| 47 | " commands will have no visible effect after this, until the forced level is released.\n" |
| 48 | #define NO_FORCE_ALL_STR \ |
| 49 | "Release any globally forced log level set with 'logging level force-all <level>'\n" |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 50 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 51 | #define LOG_LEVEL_ARGS "(debug|info|notice|error|fatal)" |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 52 | #define LOG_LEVEL_STRS \ |
| 53 | "Log debug messages and higher levels\n" \ |
| 54 | "Log informational messages and higher levels\n" \ |
| 55 | "Log noticeable messages and higher levels\n" \ |
| 56 | "Log error messages and higher levels\n" \ |
| 57 | "Log only fatal messages\n" |
| 58 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 59 | #define EVERYTHING_STR "Deprecated alias for 'no logging level force-all'\n" |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 60 | |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 61 | /*! \file logging_vty.c |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 62 | * Configuration of logging from VTY |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 63 | * |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 64 | * This module implements |
| 65 | * - functions that permit configuration of the libosmocore logging |
| 66 | * framework from VTY commands in the configure -> logging node. |
| 67 | * |
| 68 | * - functions that permit logging *to* a VTY session. Basically each |
| 69 | * VTY session gets its own log target, with configurable |
| 70 | * per-subsystem log levels. This is performed internally via the |
| 71 | * \ref log_target_create_vty function. |
| 72 | * |
| 73 | * You have to call \ref logging_vty_add_cmds from your application |
| 74 | * once to enable both of the above. |
| 75 | * |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 76 | */ |
| 77 | |
Harald Welte | 76e72ab | 2011-02-17 15:52:39 +0100 | [diff] [blame] | 78 | static void _vty_output(struct log_target *tgt, |
| 79 | unsigned int level, const char *line) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 80 | { |
| 81 | struct vty *vty = tgt->tgt_vty.vty; |
| 82 | vty_out(vty, "%s", line); |
| 83 | /* This is an ugly hack, but there is no easy way... */ |
| 84 | if (strchr(line, '\n')) |
| 85 | vty_out(vty, "\r"); |
| 86 | } |
| 87 | |
| 88 | struct log_target *log_target_create_vty(struct vty *vty) |
| 89 | { |
| 90 | struct log_target *target; |
| 91 | |
| 92 | target = log_target_create(); |
| 93 | if (!target) |
| 94 | return NULL; |
| 95 | |
| 96 | target->tgt_vty.vty = vty; |
| 97 | target->output = _vty_output; |
| 98 | return target; |
| 99 | } |
| 100 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 101 | /*! Get tgt with log lock acquired, return and release lock with warning if tgt |
| 102 | * is not found. Lock must be released later with log_tgt_mutex_unlock(). |
| 103 | */ |
| 104 | #define ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt) \ |
| 105 | do { \ |
| 106 | log_tgt_mutex_lock(); \ |
| 107 | tgt = osmo_log_vty2tgt(vty); \ |
| 108 | if (!(tgt)) { \ |
| 109 | log_tgt_mutex_unlock(); \ |
| 110 | return CMD_WARNING; \ |
| 111 | } \ |
| 112 | } while (0) |
| 113 | |
| 114 | #define RET_WITH_UNLOCK(ret) \ |
| 115 | do { \ |
| 116 | log_tgt_mutex_unlock(); \ |
| 117 | return (ret); \ |
| 118 | } while (0) |
| 119 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 120 | DEFUN(enable_logging, |
| 121 | enable_logging_cmd, |
| 122 | "logging enable", |
| 123 | LOGGING_STR |
| 124 | "Enables logging to this vty\n") |
| 125 | { |
| 126 | struct telnet_connection *conn; |
| 127 | |
| 128 | conn = (struct telnet_connection *) vty->priv; |
| 129 | if (conn->dbg) { |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 130 | vty_out(vty, "%% Logging already enabled.%s", VTY_NEWLINE); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 131 | return CMD_WARNING; |
| 132 | } |
| 133 | |
| 134 | conn->dbg = log_target_create_vty(vty); |
| 135 | if (!conn->dbg) |
| 136 | return CMD_WARNING; |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 137 | log_tgt_mutex_lock(); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 138 | log_add_target(conn->dbg); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 139 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 142 | /*! Get log target associated to VTY console. |
| 143 | * \param[in] vty Log target type |
| 144 | * \returns Log target (if logging enabled), NULL otherwise |
| 145 | * Must be called with mutex osmo_log_tgt_mutex held, see log_tgt_mutex_lock. |
| 146 | */ |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 147 | struct log_target *osmo_log_vty2tgt(struct vty *vty) |
| 148 | { |
| 149 | struct telnet_connection *conn; |
| 150 | |
| 151 | if (vty->node == CFG_LOG_NODE) |
| 152 | return vty->index; |
| 153 | |
| 154 | |
| 155 | conn = (struct telnet_connection *) vty->priv; |
| 156 | if (!conn->dbg) |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 157 | vty_out(vty, "%% Logging was not enabled.%s", VTY_NEWLINE); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 158 | |
| 159 | return conn->dbg; |
| 160 | } |
| 161 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 162 | DEFUN(logging_fltr_all, |
| 163 | logging_fltr_all_cmd, |
| 164 | "logging filter all (0|1)", |
| 165 | LOGGING_STR FILTER_STR |
| 166 | "Do you want to log all messages?\n" |
| 167 | "Only print messages matched by other filters\n" |
| 168 | "Bypass filter and print all messages\n") |
| 169 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 170 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 171 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 172 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 173 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 174 | log_set_all_filter(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 175 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | DEFUN(logging_use_clr, |
| 179 | logging_use_clr_cmd, |
| 180 | "logging color (0|1)", |
| 181 | LOGGING_STR "Configure color-printing for log messages\n" |
| 182 | "Don't use color for printing messages\n" |
| 183 | "Use color for printing messages\n") |
| 184 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 185 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 186 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 187 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 188 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 189 | log_set_use_color(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 190 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | DEFUN(logging_prnt_timestamp, |
| 194 | logging_prnt_timestamp_cmd, |
| 195 | "logging timestamp (0|1)", |
| 196 | LOGGING_STR "Configure log message timestamping\n" |
| 197 | "Don't prefix each log message\n" |
| 198 | "Prefix each log message with current timestamp\n") |
| 199 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 200 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 201 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 202 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 203 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 204 | log_set_print_timestamp(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 205 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 208 | DEFUN(logging_prnt_ext_timestamp, |
| 209 | logging_prnt_ext_timestamp_cmd, |
| 210 | "logging print extended-timestamp (0|1)", |
| 211 | LOGGING_STR "Log output settings\n" |
| 212 | "Configure log message timestamping\n" |
| 213 | "Don't prefix each log message\n" |
| 214 | "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n") |
| 215 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 216 | struct log_target *tgt; |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 217 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 218 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 219 | |
| 220 | log_set_print_extended_timestamp(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 221 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Pau Espin Pedrol | 662d10d | 2021-02-18 18:19:23 +0100 | [diff] [blame] | 224 | DEFUN(logging_prnt_tid, |
| 225 | logging_prnt_tid_cmd, |
| 226 | "logging print thread-id (0|1)", |
| 227 | LOGGING_STR "Log output settings\n" |
| 228 | "Configure log message logging Thread ID\n" |
| 229 | "Don't prefix each log message\n" |
| 230 | "Prefix each log message with current Thread ID\n") |
| 231 | { |
| 232 | struct log_target *tgt; |
| 233 | |
| 234 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 235 | |
| 236 | log_set_print_tid(tgt, atoi(argv[0])); |
| 237 | RET_WITH_UNLOCK(CMD_SUCCESS); |
| 238 | } |
| 239 | |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 240 | DEFUN(logging_prnt_cat, |
| 241 | logging_prnt_cat_cmd, |
| 242 | "logging print category (0|1)", |
| 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 category/subsystem name\n") |
| 247 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 248 | struct log_target *tgt; |
| 249 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 250 | |
| 251 | log_set_print_category(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 252 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 255 | DEFUN(logging_prnt_cat_hex, |
| 256 | logging_prnt_cat_hex_cmd, |
| 257 | "logging print category-hex (0|1)", |
| 258 | LOGGING_STR "Log output settings\n" |
| 259 | "Configure log message\n" |
| 260 | "Don't prefix each log message\n" |
| 261 | "Prefix each log message with category/subsystem nr in hex ('<000b>')\n") |
| 262 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 263 | struct log_target *tgt; |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 264 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 265 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 266 | |
| 267 | log_set_print_category_hex(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 268 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 271 | DEFUN(logging_prnt_level, |
| 272 | logging_prnt_level_cmd, |
| 273 | "logging print level (0|1)", |
| 274 | LOGGING_STR "Log output settings\n" |
| 275 | "Configure log message\n" |
| 276 | "Don't prefix each log message\n" |
| 277 | "Prefix each log message with the log level name\n") |
| 278 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 279 | struct log_target *tgt; |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 280 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 281 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 282 | |
| 283 | log_set_print_level(tgt, atoi(argv[0])); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 284 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 287 | static const struct value_string logging_print_file_args[] = { |
| 288 | { LOG_FILENAME_NONE, "0" }, |
| 289 | { LOG_FILENAME_PATH, "1" }, |
| 290 | { LOG_FILENAME_BASENAME, "basename" }, |
| 291 | { 0, NULL } |
| 292 | }; |
| 293 | |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 294 | DEFUN(logging_prnt_file, |
| 295 | logging_prnt_file_cmd, |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 296 | "logging print file (0|1|basename) [last]", |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 297 | LOGGING_STR "Log output settings\n" |
| 298 | "Configure log message\n" |
| 299 | "Don't prefix each log message\n" |
| 300 | "Prefix each log message with the source file and line\n" |
Neels Hofmeyr | 77ae45d | 2018-08-27 20:32:36 +0200 | [diff] [blame] | 301 | "Prefix each log message with the source file's basename (strip leading paths) and line\n" |
| 302 | "Log source file info at the end of a log line. If omitted, log source file info just" |
| 303 | " before the log text.\n") |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 304 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 305 | struct log_target *tgt; |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 306 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 307 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 308 | |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 309 | 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] | 310 | if (argc > 1) |
| 311 | log_set_print_filename_pos(tgt, LOG_FILENAME_POS_LINE_END); |
| 312 | else |
| 313 | log_set_print_filename_pos(tgt, LOG_FILENAME_POS_HEADER_END); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 314 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 317 | static void add_category_strings(char **cmd_str_p, char **doc_str_p, |
| 318 | const struct log_info *categories) |
| 319 | { |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 320 | char buf[128]; |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 321 | int i; |
| 322 | for (i = 0; i < categories->num_cat; i++) { |
| 323 | if (categories->cat[i].name == NULL) |
| 324 | continue; |
| 325 | /* skip the leading 'D' in each category name, hence '+ 1' */ |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 326 | osmo_str_tolower_buf(buf, sizeof(buf), categories->cat[i].name + 1); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 327 | osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s", |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 328 | i ? "|" : "", buf); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 329 | osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n", |
| 330 | categories->cat[i].description); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | static void gen_logging_level_cmd_strs(struct cmd_element *cmd, |
| 335 | const char *level_args, const char *level_strs) |
| 336 | { |
| 337 | char *cmd_str = NULL; |
| 338 | char *doc_str = NULL; |
| 339 | |
| 340 | assert_loginfo(__func__); |
| 341 | |
| 342 | OSMO_ASSERT(cmd->string == NULL); |
| 343 | OSMO_ASSERT(cmd->doc == NULL); |
| 344 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 345 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logging level ("); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 346 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 347 | LOGGING_STR |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 348 | LEVEL_STR); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 349 | add_category_strings(&cmd_str, &doc_str, osmo_log_info); |
| 350 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args); |
| 351 | osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs); |
| 352 | |
Harald Welte | bebec21 | 2020-07-15 12:21:29 +0200 | [diff] [blame] | 353 | talloc_set_name_const(cmd_str, "vty_log_level_cmd_str"); |
| 354 | talloc_set_name_const(doc_str, "vty_log_level_doc_str"); |
| 355 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 356 | cmd->string = cmd_str; |
| 357 | cmd->doc = doc_str; |
| 358 | } |
| 359 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 360 | /* logging level (<categories>) (debug|...|fatal) */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 361 | DEFUN(logging_level, |
| 362 | logging_level_cmd, |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 363 | NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */ |
| 364 | NULL) /* same thing for helpstr. */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 365 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 366 | struct log_target *tgt; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 367 | int category = log_parse_category(argv[0]); |
| 368 | int level = log_parse_level(argv[1]); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 369 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 370 | if (level < 0) { |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 371 | vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE); |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 372 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 375 | if (category < 0) { |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 376 | vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE); |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 377 | return CMD_WARNING; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 380 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 381 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 382 | tgt->categories[category].enabled = 1; |
| 383 | tgt->categories[category].loglevel = level; |
| 384 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 385 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 388 | DEFUN(logging_level_set_all, logging_level_set_all_cmd, |
| 389 | "logging level set-all " LOG_LEVEL_ARGS, |
| 390 | LOGGING_STR LEVEL_STR |
| 391 | "Once-off set all categories to the given log level. There is no single command" |
| 392 | " to take back these changes -- each category is set to the given level, period.\n" |
| 393 | LOG_LEVEL_STRS) |
| 394 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 395 | struct log_target *tgt; |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 396 | int level = log_parse_level(argv[0]); |
| 397 | int i; |
Neels Hofmeyr | ea6f519 | 2018-10-01 15:51:18 +0200 | [diff] [blame] | 398 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 399 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Neels Hofmeyr | ea6f519 | 2018-10-01 15:51:18 +0200 | [diff] [blame] | 400 | |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 401 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
| 402 | struct log_category *cat = &tgt->categories[i]; |
| 403 | /* skip empty entries in the array */ |
| 404 | if (!osmo_log_info->cat[i].name) |
| 405 | continue; |
| 406 | |
| 407 | cat->enabled = 1; |
| 408 | cat->loglevel = level; |
| 409 | } |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 410 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 411 | } |
| 412 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 413 | /* logging level (<categories>) everything */ |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 414 | DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd, |
| 415 | NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */ |
| 416 | NULL) /* same thing for helpstr. */ |
| 417 | { |
| 418 | vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE); |
| 419 | return CMD_SUCCESS; |
| 420 | } |
| 421 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 422 | DEFUN(logging_level_force_all, logging_level_force_all_cmd, |
| 423 | "logging level force-all " LOG_LEVEL_ARGS, |
| 424 | LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS) |
| 425 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 426 | struct log_target *tgt; |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 427 | int level = log_parse_level(argv[0]); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 428 | |
| 429 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 430 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 431 | log_set_log_level(tgt, level); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 432 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd, |
| 436 | "no logging level force-all", |
| 437 | NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR) |
| 438 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 439 | struct log_target *tgt; |
| 440 | |
| 441 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 442 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 443 | log_set_log_level(tgt, 0); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 444 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* 'logging level all (debug|...|fatal)' */ |
| 448 | ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd, |
| 449 | "logging level all " LOG_LEVEL_ARGS, |
| 450 | LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS); |
| 451 | |
| 452 | /* 'logging level all everything' */ |
| 453 | ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd, |
| 454 | "logging level all everything", |
| 455 | LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR); |
| 456 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 457 | DEFUN(logging_set_category_mask, |
| 458 | logging_set_category_mask_cmd, |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 459 | "logging set-log-mask MASK", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 460 | LOGGING_STR |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 461 | "Set the logmask of this logging target\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 462 | "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific" |
| 463 | " application, refer to the 'logging level' command. Optionally add individual log levels like" |
| 464 | " 'abc,1:mno,3:xyz,5', where the level numbers are" |
| 465 | " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG) |
| 466 | " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO) |
| 467 | " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE) |
| 468 | " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR) |
| 469 | " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL) |
| 470 | "\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 471 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 472 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 473 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 474 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 475 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 476 | log_parse_category_mask(tgt, argv[0]); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 477 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 480 | ALIAS_DEPRECATED(logging_set_category_mask, |
| 481 | logging_set_category_mask_old_cmd, |
| 482 | "logging set log mask MASK", |
| 483 | LOGGING_STR |
| 484 | "Decide which categories to output.\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 485 | "Log commands\n" "Mask commands\n" |
| 486 | "'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] | 487 | |
| 488 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 489 | DEFUN(diable_logging, |
| 490 | disable_logging_cmd, |
| 491 | "logging disable", |
| 492 | LOGGING_STR |
| 493 | "Disables logging to this vty\n") |
| 494 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 495 | struct log_target *tgt; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 496 | struct telnet_connection *conn = (struct telnet_connection *) vty->priv; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 497 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 498 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 499 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 500 | log_del_target(tgt); |
| 501 | talloc_free(tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 502 | conn->dbg = NULL; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 503 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 504 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void vty_print_logtarget(struct vty *vty, const struct log_info *info, |
| 508 | const struct log_target *tgt) |
| 509 | { |
| 510 | unsigned int i; |
| 511 | |
| 512 | vty_out(vty, " Global Loglevel: %s%s", |
| 513 | log_level_str(tgt->loglevel), VTY_NEWLINE); |
| 514 | vty_out(vty, " Use color: %s, Print Timestamp: %s%s", |
| 515 | tgt->use_color ? "On" : "Off", |
| 516 | tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE); |
| 517 | |
| 518 | vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE); |
| 519 | |
| 520 | for (i = 0; i < info->num_cat; i++) { |
| 521 | const struct log_category *cat = &tgt->categories[i]; |
Daniel Willmann | 55363a9 | 2016-11-15 10:05:51 +0100 | [diff] [blame] | 522 | /* Skip categories that were not initialized */ |
| 523 | if (!info->cat[i].name) |
| 524 | continue; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 525 | vty_out(vty, " %-10s %-10s %-8s %s%s", |
| 526 | info->cat[i].name+1, log_level_str(cat->loglevel), |
| 527 | cat->enabled ? "Enabled" : "Disabled", |
| 528 | info->cat[i].description, |
| 529 | VTY_NEWLINE); |
| 530 | } |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 531 | |
| 532 | vty_out(vty, " Log Filter 'ALL': %s%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 533 | tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled", |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 534 | VTY_NEWLINE); |
| 535 | |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 536 | /* print application specific filters */ |
| 537 | if (info->print_fn) |
| 538 | info->print_fn(vty, info, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | #define SHOW_LOG_STR "Show current logging configuration\n" |
| 542 | |
| 543 | DEFUN(show_logging_vty, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 544 | show_logging_vty_cmd, |
| 545 | "show logging vty", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 546 | SHOW_STR SHOW_LOG_STR |
| 547 | "Show current logging configuration for this vty\n") |
| 548 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 549 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 550 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 551 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 552 | |
| 553 | vty_print_logtarget(vty, osmo_log_info, tgt); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 554 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 557 | DEFUN(show_alarms, |
| 558 | show_alarms_cmd, |
| 559 | "show alarms", |
| 560 | SHOW_STR SHOW_LOG_STR |
| 561 | "Show the contents of the logging ringbuffer\n") |
| 562 | { |
| 563 | int i, num_alarms; |
| 564 | struct osmo_strrb *rb; |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 565 | struct log_target *tgt; |
| 566 | |
| 567 | log_tgt_mutex_lock(); |
| 568 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 569 | if (!tgt) { |
| 570 | vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s", |
| 571 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 572 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | rb = tgt->tgt_rb.rb; |
| 576 | num_alarms = osmo_strrb_elements(rb); |
| 577 | |
| 578 | vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE); |
| 579 | |
| 580 | for (i = 0; i < num_alarms; i++) |
| 581 | vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i), |
| 582 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 583 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 586 | gDEFUN(cfg_description, cfg_description_cmd, |
| 587 | "description .TEXT", |
Thorsten Alteholz | a81055d | 2017-03-02 22:13:48 +0100 | [diff] [blame] | 588 | "Save human-readable description of the object\n" |
Holger Hans Peter Freyther | c9b3e06 | 2012-07-25 13:02:49 +0200 | [diff] [blame] | 589 | "Text until the end of the line\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 590 | { |
| 591 | char **dptr = vty->index_sub; |
| 592 | |
| 593 | if (!dptr) { |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 594 | vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 595 | return CMD_WARNING; |
| 596 | } |
| 597 | |
Holger Hans Peter Freyther | ff0670e | 2011-02-24 14:20:41 +0100 | [diff] [blame] | 598 | if (*dptr) |
| 599 | talloc_free(*dptr); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 600 | *dptr = argv_concat(argv, argc, 0); |
Holger Hans Peter Freyther | 6a75d16 | 2013-07-14 09:07:11 +0200 | [diff] [blame] | 601 | if (!*dptr) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 602 | return CMD_WARNING; |
| 603 | |
| 604 | return CMD_SUCCESS; |
| 605 | } |
| 606 | |
| 607 | gDEFUN(cfg_no_description, cfg_no_description_cmd, |
| 608 | "no description", |
| 609 | NO_STR |
| 610 | "Remove description of the object\n") |
| 611 | { |
| 612 | char **dptr = vty->index_sub; |
| 613 | |
| 614 | if (!dptr) { |
Vadim Yanitskiy | 2d1a9fa | 2021-04-05 03:08:26 +0200 | [diff] [blame] | 615 | vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 616 | return CMD_WARNING; |
| 617 | } |
| 618 | |
| 619 | if (*dptr) { |
| 620 | talloc_free(*dptr); |
| 621 | *dptr = NULL; |
| 622 | } |
| 623 | |
| 624 | return CMD_SUCCESS; |
| 625 | } |
| 626 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 627 | /* Support for configuration of log targets != the current vty */ |
| 628 | |
| 629 | struct cmd_node cfg_log_node = { |
| 630 | CFG_LOG_NODE, |
| 631 | "%s(config-log)# ", |
| 632 | 1 |
| 633 | }; |
| 634 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 635 | #ifdef HAVE_SYSLOG_H |
| 636 | |
| 637 | #include <syslog.h> |
| 638 | |
| 639 | static const int local_sysl_map[] = { |
| 640 | [0] = LOG_LOCAL0, |
| 641 | [1] = LOG_LOCAL1, |
| 642 | [2] = LOG_LOCAL2, |
| 643 | [3] = LOG_LOCAL3, |
| 644 | [4] = LOG_LOCAL4, |
| 645 | [5] = LOG_LOCAL5, |
| 646 | [6] = LOG_LOCAL6, |
| 647 | [7] = LOG_LOCAL7 |
| 648 | }; |
| 649 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 650 | /* From VTY core code */ |
| 651 | extern struct host host; |
| 652 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 653 | static int _cfg_log_syslog(struct vty *vty, int facility) |
| 654 | { |
| 655 | struct log_target *tgt; |
| 656 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 657 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 658 | /* First delete the old syslog target, if any */ |
| 659 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 660 | if (tgt) |
| 661 | log_target_destroy(tgt); |
| 662 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 663 | tgt = log_target_create_syslog(host.app_info->name, 0, facility); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 664 | if (!tgt) { |
| 665 | vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 666 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 667 | } |
| 668 | log_add_target(tgt); |
| 669 | |
| 670 | vty->index = tgt; |
| 671 | vty->node = CFG_LOG_NODE; |
| 672 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 673 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd, |
| 677 | "log syslog local <0-7>", |
| 678 | LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n" |
| 679 | "Local facility number\n") |
| 680 | { |
| 681 | int local = atoi(argv[0]); |
| 682 | int facility = local_sysl_map[local]; |
| 683 | |
| 684 | return _cfg_log_syslog(vty, facility); |
| 685 | } |
| 686 | |
| 687 | static struct value_string sysl_level_names[] = { |
| 688 | { LOG_AUTHPRIV, "authpriv" }, |
| 689 | { LOG_CRON, "cron" }, |
| 690 | { LOG_DAEMON, "daemon" }, |
| 691 | { LOG_FTP, "ftp" }, |
| 692 | { LOG_LPR, "lpr" }, |
| 693 | { LOG_MAIL, "mail" }, |
| 694 | { LOG_NEWS, "news" }, |
| 695 | { LOG_USER, "user" }, |
| 696 | { LOG_UUCP, "uucp" }, |
| 697 | /* only for value -> string conversion */ |
| 698 | { LOG_LOCAL0, "local 0" }, |
| 699 | { LOG_LOCAL1, "local 1" }, |
| 700 | { LOG_LOCAL2, "local 2" }, |
| 701 | { LOG_LOCAL3, "local 3" }, |
| 702 | { LOG_LOCAL4, "local 4" }, |
| 703 | { LOG_LOCAL5, "local 5" }, |
| 704 | { LOG_LOCAL6, "local 6" }, |
| 705 | { LOG_LOCAL7, "local 7" }, |
| 706 | { 0, NULL } |
| 707 | }; |
| 708 | |
| 709 | DEFUN(cfg_log_syslog, cfg_log_syslog_cmd, |
| 710 | "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] | 711 | LOG_STR "Logging via syslog\n" |
| 712 | "Security/authorization messages facility\n" |
| 713 | "Clock daemon (cron/at) facility\n" |
| 714 | "General system daemon facility\n" |
| 715 | "Ftp daemon facility\n" |
| 716 | "Line printer facility\n" |
| 717 | "Mail facility\n" |
| 718 | "News facility\n" |
| 719 | "Generic facility\n" |
| 720 | "UUCP facility\n") |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 721 | { |
| 722 | int facility = get_string_value(sysl_level_names, argv[0]); |
| 723 | |
| 724 | return _cfg_log_syslog(vty, facility); |
| 725 | } |
| 726 | |
| 727 | DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd, |
| 728 | "no log syslog", |
| 729 | NO_STR LOG_STR "Logging via syslog\n") |
| 730 | { |
| 731 | struct log_target *tgt; |
| 732 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 733 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 734 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 735 | if (!tgt) { |
| 736 | vty_out(vty, "%% No syslog target found%s", |
| 737 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 738 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | log_target_destroy(tgt); |
| 742 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 743 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 744 | } |
| 745 | #endif /* HAVE_SYSLOG_H */ |
| 746 | |
Vadim Yanitskiy | e7bf435 | 2020-09-09 03:36:48 +0700 | [diff] [blame] | 747 | DEFUN(cfg_log_systemd_journal, cfg_log_systemd_journal_cmd, |
| 748 | "log systemd-journal [raw]", |
| 749 | LOG_STR "Logging to systemd-journal\n" |
| 750 | "Offload rendering of the meta information (location, category) to systemd\n") |
| 751 | { |
| 752 | #ifdef ENABLE_SYSTEMD_LOGGING |
| 753 | struct log_target *tgt; |
| 754 | bool raw = argc > 0; |
| 755 | |
| 756 | log_tgt_mutex_lock(); |
| 757 | tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL); |
| 758 | if (tgt == NULL) { |
| 759 | tgt = log_target_create_systemd(raw); |
| 760 | if (tgt == NULL) { |
| 761 | vty_out(vty, "%% Unable to create systemd-journal " |
| 762 | "log target%s", VTY_NEWLINE); |
| 763 | RET_WITH_UNLOCK(CMD_WARNING); |
| 764 | } |
| 765 | log_add_target(tgt); |
| 766 | } else if (tgt->sd_journal.raw != raw) { |
| 767 | log_target_systemd_set_raw(tgt, raw); |
| 768 | } |
| 769 | |
| 770 | vty->index = tgt; |
| 771 | vty->node = CFG_LOG_NODE; |
| 772 | |
| 773 | RET_WITH_UNLOCK(CMD_SUCCESS); |
| 774 | #else |
| 775 | vty_out(vty, "%% systemd-journal logging is not available " |
| 776 | "in this build of libosmocore%s", VTY_NEWLINE); |
| 777 | return CMD_WARNING; |
| 778 | #endif /* ENABLE_SYSTEMD_LOGGING */ |
| 779 | } |
| 780 | |
| 781 | DEFUN(cfg_no_log_systemd_journal, cfg_no_log_systemd_journal_cmd, |
| 782 | "no log systemd-journal", |
| 783 | NO_STR LOG_STR "Logging to systemd-journal\n") |
| 784 | { |
| 785 | #ifdef ENABLE_SYSTEMD_LOGGING |
| 786 | struct log_target *tgt; |
| 787 | |
| 788 | log_tgt_mutex_lock(); |
| 789 | tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL); |
| 790 | if (!tgt) { |
| 791 | vty_out(vty, "%% No systemd-journal logging active%s", VTY_NEWLINE); |
| 792 | RET_WITH_UNLOCK(CMD_WARNING); |
| 793 | } |
| 794 | |
| 795 | log_target_destroy(tgt); |
| 796 | |
| 797 | RET_WITH_UNLOCK(CMD_SUCCESS); |
| 798 | #else |
| 799 | vty_out(vty, "%% systemd-journal logging is not available " |
| 800 | "in this build of libosmocore%s", VTY_NEWLINE); |
| 801 | return CMD_WARNING; |
| 802 | #endif /* ENABLE_SYSTEMD_LOGGING */ |
| 803 | } |
| 804 | |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 805 | DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd, |
| 806 | "log gsmtap [HOSTNAME]", |
Neels Hofmeyr | fd9ec3b | 2016-12-11 01:48:26 +0100 | [diff] [blame] | 807 | LOG_STR "Logging via GSMTAP\n" |
| 808 | "Host name to send the GSMTAP logging to (UDP port 4729)\n") |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 809 | { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 810 | const char *hostname = argc ? argv[0] : "127.0.0.1"; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 811 | struct log_target *tgt; |
| 812 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 813 | log_tgt_mutex_lock(); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 814 | tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname); |
| 815 | if (!tgt) { |
| 816 | tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT, |
| 817 | host.app_info->name, false, |
| 818 | true); |
| 819 | if (!tgt) { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 820 | vty_out(vty, "%% Unable to create GSMTAP log for %s%s", |
| 821 | hostname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 822 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 823 | } |
| 824 | log_add_target(tgt); |
| 825 | } |
| 826 | |
| 827 | vty->index = tgt; |
| 828 | vty->node = CFG_LOG_NODE; |
| 829 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 830 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Vadim Yanitskiy | 2f4186a | 2021-12-29 21:58:19 +0600 | [diff] [blame] | 833 | DEFUN(cfg_no_log_gsmtap, cfg_no_log_gsmtap_cmd, |
| 834 | "no log gsmtap [HOSTNAME]", |
| 835 | NO_STR LOG_STR "Logging via GSMTAP\n" |
| 836 | "Host name to send the GSMTAP logging to (UDP port 4729)\n") |
| 837 | { |
| 838 | const char *hostname = argc ? argv[0] : "127.0.0.1"; |
| 839 | struct log_target *tgt; |
| 840 | |
| 841 | log_tgt_mutex_lock(); |
| 842 | tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname); |
| 843 | if (tgt == NULL) { |
| 844 | vty_out(vty, "%% Unable to find GSMTAP log target for %s%s", |
| 845 | hostname, VTY_NEWLINE); |
| 846 | RET_WITH_UNLOCK(CMD_WARNING); |
| 847 | } |
| 848 | |
| 849 | log_target_destroy(tgt); |
| 850 | |
| 851 | RET_WITH_UNLOCK(CMD_SUCCESS); |
| 852 | } |
| 853 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 854 | DEFUN(cfg_log_stderr, cfg_log_stderr_cmd, |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 855 | "log stderr [blocking-io]", |
| 856 | LOG_STR "Logging via STDERR of the process\n" |
| 857 | "Use blocking, synchronous I/O\n") |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 858 | { |
| 859 | struct log_target *tgt; |
| 860 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 861 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 862 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 863 | if (!tgt) { |
| 864 | tgt = log_target_create_stderr(); |
| 865 | if (!tgt) { |
| 866 | vty_out(vty, "%% Unable to create stderr log%s", |
| 867 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 868 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 869 | } |
| 870 | log_add_target(tgt); |
| 871 | } |
| 872 | |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 873 | if (argc > 0 && !strcmp(argv[0], "blocking-io")) |
| 874 | log_target_file_switch_to_stream(tgt); |
| 875 | else |
| 876 | log_target_file_switch_to_wqueue(tgt); |
| 877 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 878 | vty->index = tgt; |
| 879 | vty->node = CFG_LOG_NODE; |
| 880 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 881 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd, |
| 885 | "no log stderr", |
| 886 | NO_STR LOG_STR "Logging via STDERR of the process\n") |
| 887 | { |
| 888 | struct log_target *tgt; |
| 889 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 890 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 891 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 892 | if (!tgt) { |
| 893 | vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 894 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | log_target_destroy(tgt); |
Harald Welte | e4d9a2c | 2020-09-27 11:28:58 +0200 | [diff] [blame] | 898 | osmo_stderr_target = NULL; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 899 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 900 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | DEFUN(cfg_log_file, cfg_log_file_cmd, |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 904 | "log file FILENAME [blocking-io]", |
| 905 | LOG_STR "Logging to text file\n" "Filename\n" |
| 906 | "Use blocking, synchronous I/O\n") |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 907 | { |
| 908 | const char *fname = argv[0]; |
| 909 | struct log_target *tgt; |
| 910 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 911 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 912 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 913 | if (!tgt) { |
| 914 | tgt = log_target_create_file(fname); |
| 915 | if (!tgt) { |
Vadim Yanitskiy | ad34465 | 2021-04-05 03:05:31 +0200 | [diff] [blame] | 916 | vty_out(vty, "%% Unable to create file '%s'%s", |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 917 | fname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 918 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 919 | } |
| 920 | log_add_target(tgt); |
| 921 | } |
| 922 | |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 923 | if (argc > 1 && !strcmp(argv[1], "blocking-io")) |
| 924 | log_target_file_switch_to_stream(tgt); |
| 925 | else |
| 926 | log_target_file_switch_to_wqueue(tgt); |
| 927 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 928 | vty->index = tgt; |
| 929 | vty->node = CFG_LOG_NODE; |
| 930 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 931 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | |
| 935 | DEFUN(cfg_no_log_file, cfg_no_log_file_cmd, |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 936 | "no log file FILENAME", |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 937 | NO_STR LOG_STR "Logging to text file\n" "Filename\n") |
| 938 | { |
| 939 | const char *fname = argv[0]; |
| 940 | struct log_target *tgt; |
| 941 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 942 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 943 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 944 | if (!tgt) { |
Vadim Yanitskiy | ad34465 | 2021-04-05 03:05:31 +0200 | [diff] [blame] | 945 | vty_out(vty, "%% No such log file '%s'%s", |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 946 | fname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 947 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | log_target_destroy(tgt); |
| 951 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 952 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 955 | DEFUN(cfg_log_alarms, cfg_log_alarms_cmd, |
| 956 | "log alarms <2-32700>", |
| 957 | LOG_STR "Logging alarms to osmo_strrb\n" |
| 958 | "Maximum number of messages to log\n") |
| 959 | { |
| 960 | struct log_target *tgt; |
| 961 | unsigned int rbsize = atoi(argv[0]); |
| 962 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 963 | |
| 964 | log_tgt_mutex_lock(); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 965 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 966 | if (tgt) |
| 967 | log_target_destroy(tgt); |
| 968 | |
| 969 | tgt = log_target_create_rb(rbsize); |
| 970 | if (!tgt) { |
| 971 | vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s", |
| 972 | rbsize, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 973 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 974 | } |
| 975 | log_add_target(tgt); |
| 976 | |
| 977 | vty->index = tgt; |
| 978 | vty->node = CFG_LOG_NODE; |
| 979 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 980 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd, |
| 984 | "no log alarms", |
| 985 | NO_STR LOG_STR "Logging alarms to osmo_strrb\n") |
| 986 | { |
| 987 | struct log_target *tgt; |
| 988 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 989 | log_tgt_mutex_lock(); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 990 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 991 | if (!tgt) { |
| 992 | vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 993 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | log_target_destroy(tgt); |
| 997 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 998 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1001 | static int config_write_log_single(struct vty *vty, struct log_target *tgt) |
| 1002 | { |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1003 | char level_buf[128]; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1004 | int i; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1005 | |
| 1006 | switch (tgt->type) { |
| 1007 | case LOG_TGT_TYPE_VTY: |
| 1008 | return 1; |
| 1009 | break; |
| 1010 | case LOG_TGT_TYPE_STDERR: |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 1011 | if (tgt->tgt_file.wqueue) |
| 1012 | vty_out(vty, "log stderr%s", VTY_NEWLINE); |
| 1013 | else |
| 1014 | vty_out(vty, "log stderr blocking-io%s", VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1015 | break; |
| 1016 | case LOG_TGT_TYPE_SYSLOG: |
| 1017 | #ifdef HAVE_SYSLOG_H |
| 1018 | vty_out(vty, "log syslog %s%s", |
| 1019 | get_value_string(sysl_level_names, |
| 1020 | tgt->tgt_syslog.facility), |
| 1021 | VTY_NEWLINE); |
| 1022 | #endif |
| 1023 | break; |
| 1024 | case LOG_TGT_TYPE_FILE: |
Harald Welte | b72867f | 2020-09-26 21:45:16 +0200 | [diff] [blame] | 1025 | if (tgt->tgt_file.wqueue) |
| 1026 | vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE); |
| 1027 | else |
| 1028 | vty_out(vty, "log file %s blocking-io%s", tgt->tgt_file.fname, VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1029 | break; |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 1030 | case LOG_TGT_TYPE_STRRB: |
| 1031 | vty_out(vty, "log alarms %zu%s", |
| 1032 | log_target_rb_avail_size(tgt), VTY_NEWLINE); |
| 1033 | break; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 1034 | case LOG_TGT_TYPE_GSMTAP: |
| 1035 | vty_out(vty, "log gsmtap %s%s", |
| 1036 | tgt->tgt_gsmtap.hostname, VTY_NEWLINE); |
| 1037 | break; |
Vadim Yanitskiy | e7bf435 | 2020-09-09 03:36:48 +0700 | [diff] [blame] | 1038 | case LOG_TGT_TYPE_SYSTEMD: |
| 1039 | vty_out(vty, "log systemd-journal%s%s", |
| 1040 | tgt->sd_journal.raw ? " raw" : "", |
| 1041 | VTY_NEWLINE); |
| 1042 | break; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1045 | vty_out(vty, " logging filter all %u%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 1046 | tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE); |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 1047 | /* save filters outside of libosmocore, i.e. in app code */ |
| 1048 | if (osmo_log_info->save_fn) |
| 1049 | osmo_log_info->save_fn(vty, osmo_log_info, tgt); |
Harald Welte | 2da47f1 | 2012-10-22 19:31:54 +0200 | [diff] [blame] | 1050 | |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1051 | vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0, |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1052 | VTY_NEWLINE); |
Vadim Yanitskiy | 5c4b985 | 2019-07-28 04:36:37 +0700 | [diff] [blame] | 1053 | vty_out(vty, " logging print category-hex %d%s", |
| 1054 | tgt->print_category_hex ? 1 : 0, VTY_NEWLINE); |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1055 | vty_out(vty, " logging print category %d%s", |
Michael McTernan | 7893346 | 2015-03-20 15:29:25 +0100 | [diff] [blame] | 1056 | tgt->print_category ? 1 : 0, VTY_NEWLINE); |
Pau Espin Pedrol | 662d10d | 2021-02-18 18:19:23 +0100 | [diff] [blame] | 1057 | vty_out(vty, " logging print thread-id %d%s", |
| 1058 | tgt->print_tid ? 1 : 0, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 1059 | if (tgt->print_ext_timestamp) |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1060 | vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 1061 | else |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1062 | vty_out(vty, " logging timestamp %u%s", |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 1063 | tgt->print_timestamp ? 1 : 0, VTY_NEWLINE); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 1064 | if (tgt->print_level) |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1065 | vty_out(vty, " logging print level 1%s", VTY_NEWLINE); |
Harald Welte | 8d6ca69 | 2021-01-20 17:04:23 +0100 | [diff] [blame] | 1066 | vty_out(vty, " logging print file %s%s%s", |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 1067 | get_value_string(logging_print_file_args, tgt->print_filename2), |
Harald Welte | 8d6ca69 | 2021-01-20 17:04:23 +0100 | [diff] [blame] | 1068 | tgt->print_filename_pos == LOG_FILENAME_POS_LINE_END ? " last" : "", |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 1069 | VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1070 | |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 1071 | if (tgt->loglevel) { |
| 1072 | const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel); |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1073 | if (!level_str) { |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1074 | vty_out(vty, "%% Invalid log level %u for 'force-all'%s", |
| 1075 | tgt->loglevel, VTY_NEWLINE); |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1076 | } else { |
| 1077 | osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); |
| 1078 | vty_out(vty, " logging level force-all %s%s", level_buf, VTY_NEWLINE); |
| 1079 | } |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 1080 | } |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1081 | |
| 1082 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
| 1083 | const struct log_category *cat = &tgt->categories[i]; |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1084 | char cat_name[128]; |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 1085 | const char *level_str; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1086 | |
Harald Welte | 1a02cfc | 2013-03-19 10:37:39 +0100 | [diff] [blame] | 1087 | /* skip empty entries in the array */ |
| 1088 | if (!osmo_log_info->cat[i].name) |
| 1089 | continue; |
| 1090 | |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1091 | osmo_str_tolower_buf(cat_name, sizeof(cat_name), osmo_log_info->cat[i].name + 1); |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 1092 | |
| 1093 | level_str = get_value_string_or_null(loglevel_strs, cat->loglevel); |
| 1094 | if (!level_str) { |
| 1095 | vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name, |
| 1096 | VTY_NEWLINE); |
| 1097 | continue; |
| 1098 | } |
| 1099 | |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1100 | osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 1101 | vty_out(vty, " logging level %s", cat_name); |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 1102 | vty_out(vty, " %s%s", level_buf, VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1105 | return 1; |
| 1106 | } |
| 1107 | |
| 1108 | static int config_write_log(struct vty *vty) |
| 1109 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1110 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1111 | struct log_target *dbg = vty->index; |
| 1112 | |
| 1113 | llist_for_each_entry(dbg, &osmo_log_target_list, entry) |
| 1114 | config_write_log_single(vty, dbg); |
| 1115 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 1116 | log_tgt_mutex_unlock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
| 1119 | |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1120 | static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[]) |
| 1121 | { |
| 1122 | vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE); |
Vadim Yanitskiy | 4abda9e | 2019-11-21 00:19:36 +0700 | [diff] [blame] | 1123 | return CMD_SUCCESS; /* Otherwise the process would terminate */ |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void logging_vty_add_deprecated_subsys(void *ctx, const char *name) |
| 1127 | { |
| 1128 | struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element); |
| 1129 | OSMO_ASSERT(cmd); |
Vadim Yanitskiy | 75c242e | 2019-11-21 00:06:53 +0700 | [diff] [blame] | 1130 | cmd->string = talloc_asprintf(cmd, "logging level %s " LOG_LEVEL_ARGS, name); |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1131 | cmd->func = log_deprecated_func; |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1132 | cmd->doc = LEVEL_STR |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1133 | "Deprecated Category\n"; |
| 1134 | cmd->attr = CMD_ATTR_DEPRECATED; |
| 1135 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1136 | install_lib_element(CFG_LOG_NODE, cmd); |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1139 | /* logp (<categories>) (debug|...|fatal) .LOGMESSAGE*/ |
| 1140 | DEFUN(vty_logp, |
| 1141 | vty_logp_cmd, |
| 1142 | NULL, /* cmdstr is dynamically set in gen_vty_logp_cmd_strs(). */ |
| 1143 | NULL) /* same thing for helpstr. */ |
| 1144 | { |
| 1145 | int category = log_parse_category(argv[0]); |
| 1146 | int level = log_parse_level(argv[1]); |
| 1147 | char *str = argv_concat(argv, argc, 2); |
Vadim Yanitskiy | 4b46b7e | 2021-04-05 03:45:15 +0200 | [diff] [blame] | 1148 | |
| 1149 | if (level < 0) { |
| 1150 | vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE); |
| 1151 | return CMD_WARNING; |
| 1152 | } |
| 1153 | |
| 1154 | if (category < 0) { |
| 1155 | vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE); |
| 1156 | return CMD_WARNING; |
| 1157 | } |
| 1158 | |
| 1159 | /* Properly handle library specific sub-systems */ |
| 1160 | if ((unsigned int) category >= osmo_log_info->num_cat_user) { |
| 1161 | category -= osmo_log_info->num_cat_user - 1; |
| 1162 | category *= -1; |
| 1163 | } |
| 1164 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1165 | LOGP(category, level, "%s\n", str); |
| 1166 | return CMD_SUCCESS; |
| 1167 | } |
| 1168 | |
| 1169 | static void gen_vty_logp_cmd_strs(struct cmd_element *cmd) |
| 1170 | { |
| 1171 | char *cmd_str = NULL; |
| 1172 | char *doc_str = NULL; |
| 1173 | |
| 1174 | assert_loginfo(__func__); |
| 1175 | |
| 1176 | OSMO_ASSERT(cmd->string == NULL); |
| 1177 | OSMO_ASSERT(cmd->doc == NULL); |
| 1178 | |
| 1179 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logp ("); |
| 1180 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 1181 | "Print a message on all log outputs; useful for placing markers in test logs\n"); |
| 1182 | add_category_strings(&cmd_str, &doc_str, osmo_log_info); |
| 1183 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", LOG_LEVEL_ARGS); |
| 1184 | osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", LOG_LEVEL_STRS); |
| 1185 | |
| 1186 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, " .LOGMESSAGE"); |
| 1187 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 1188 | "Arbitrary message to log on given category and log level\n"); |
| 1189 | |
Harald Welte | bebec21 | 2020-07-15 12:21:29 +0200 | [diff] [blame] | 1190 | talloc_set_name_const(cmd_str, "vty_logp_cmd_str"); |
| 1191 | talloc_set_name_const(doc_str, "vty_logp_doc_str"); |
| 1192 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1193 | cmd->string = cmd_str; |
| 1194 | cmd->doc = doc_str; |
| 1195 | } |
| 1196 | |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 1197 | /*! Register logging related commands to the VTY. Call this once from |
| 1198 | * your application if you want to support those commands. */ |
Harald Welte | e61d459 | 2022-11-03 11:05:58 +0100 | [diff] [blame] | 1199 | void logging_vty_add_cmds(void) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1200 | { |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1201 | install_lib_element_ve(&enable_logging_cmd); |
| 1202 | install_lib_element_ve(&disable_logging_cmd); |
| 1203 | install_lib_element_ve(&logging_fltr_all_cmd); |
| 1204 | install_lib_element_ve(&logging_use_clr_cmd); |
| 1205 | install_lib_element_ve(&logging_prnt_timestamp_cmd); |
| 1206 | install_lib_element_ve(&logging_prnt_ext_timestamp_cmd); |
Pau Espin Pedrol | 662d10d | 2021-02-18 18:19:23 +0100 | [diff] [blame] | 1207 | install_lib_element_ve(&logging_prnt_tid_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1208 | install_lib_element_ve(&logging_prnt_cat_cmd); |
| 1209 | install_lib_element_ve(&logging_prnt_cat_hex_cmd); |
| 1210 | install_lib_element_ve(&logging_prnt_level_cmd); |
| 1211 | install_lib_element_ve(&logging_prnt_file_cmd); |
| 1212 | install_lib_element_ve(&logging_set_category_mask_cmd); |
| 1213 | install_lib_element_ve(&logging_set_category_mask_old_cmd); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 1214 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1215 | /* logging level (<categories>) (debug|...|fatal) */ |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1216 | gen_logging_level_cmd_strs(&logging_level_cmd, |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1217 | LOG_LEVEL_ARGS, |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1218 | LOG_LEVEL_STRS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1219 | /* logging level (<categories>) everything */ |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1220 | gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd, |
| 1221 | "everything", EVERYTHING_STR); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1222 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1223 | install_lib_element_ve(&logging_level_cmd); |
| 1224 | install_lib_element_ve(&logging_level_set_all_cmd); |
| 1225 | install_lib_element_ve(&logging_level_force_all_cmd); |
| 1226 | install_lib_element_ve(&no_logging_level_force_all_cmd); |
| 1227 | install_lib_element_ve(&deprecated_logging_level_everything_cmd); |
| 1228 | install_lib_element_ve(&deprecated_logging_level_all_cmd); |
| 1229 | install_lib_element_ve(&deprecated_logging_level_all_everything_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1230 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1231 | gen_vty_logp_cmd_strs(&vty_logp_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1232 | install_lib_element_ve(&vty_logp_cmd); |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1233 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1234 | install_lib_element_ve(&show_logging_vty_cmd); |
| 1235 | install_lib_element_ve(&show_alarms_cmd); |
Pau Espin Pedrol | 0c2a46d | 2019-08-20 10:39:05 +0200 | [diff] [blame] | 1236 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1237 | install_node(&cfg_log_node, config_write_log); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1238 | install_lib_element(CFG_LOG_NODE, &logging_fltr_all_cmd); |
| 1239 | install_lib_element(CFG_LOG_NODE, &logging_use_clr_cmd); |
| 1240 | install_lib_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd); |
| 1241 | install_lib_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd); |
Pau Espin Pedrol | 662d10d | 2021-02-18 18:19:23 +0100 | [diff] [blame] | 1242 | install_lib_element(CFG_LOG_NODE, &logging_prnt_tid_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1243 | install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_cmd); |
| 1244 | install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd); |
| 1245 | install_lib_element(CFG_LOG_NODE, &logging_prnt_level_cmd); |
| 1246 | install_lib_element(CFG_LOG_NODE, &logging_prnt_file_cmd); |
| 1247 | install_lib_element(CFG_LOG_NODE, &logging_level_cmd); |
| 1248 | install_lib_element(CFG_LOG_NODE, &logging_level_set_all_cmd); |
| 1249 | install_lib_element(CFG_LOG_NODE, &logging_level_force_all_cmd); |
| 1250 | install_lib_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd); |
| 1251 | install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd); |
| 1252 | install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd); |
| 1253 | install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1254 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1255 | install_lib_element(CONFIG_NODE, &cfg_log_stderr_cmd); |
| 1256 | install_lib_element(CONFIG_NODE, &cfg_no_log_stderr_cmd); |
| 1257 | install_lib_element(CONFIG_NODE, &cfg_log_file_cmd); |
| 1258 | install_lib_element(CONFIG_NODE, &cfg_no_log_file_cmd); |
| 1259 | install_lib_element(CONFIG_NODE, &cfg_log_alarms_cmd); |
| 1260 | install_lib_element(CONFIG_NODE, &cfg_no_log_alarms_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1261 | #ifdef HAVE_SYSLOG_H |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1262 | install_lib_element(CONFIG_NODE, &cfg_log_syslog_cmd); |
| 1263 | install_lib_element(CONFIG_NODE, &cfg_log_syslog_local_cmd); |
| 1264 | install_lib_element(CONFIG_NODE, &cfg_no_log_syslog_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1265 | #endif |
Vadim Yanitskiy | e7bf435 | 2020-09-09 03:36:48 +0700 | [diff] [blame] | 1266 | install_lib_element(CONFIG_NODE, &cfg_log_systemd_journal_cmd); |
| 1267 | install_lib_element(CONFIG_NODE, &cfg_no_log_systemd_journal_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 1268 | install_lib_element(CONFIG_NODE, &cfg_log_gsmtap_cmd); |
Vadim Yanitskiy | 2f4186a | 2021-12-29 21:58:19 +0600 | [diff] [blame] | 1269 | install_lib_element(CONFIG_NODE, &cfg_no_log_gsmtap_cmd); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1270 | } |