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