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 | |
Harald Welte | bebec21 | 2020-07-15 12:21:29 +0200 | [diff] [blame] | 340 | talloc_set_name_const(cmd_str, "vty_log_level_cmd_str"); |
| 341 | talloc_set_name_const(doc_str, "vty_log_level_doc_str"); |
| 342 | |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 343 | cmd->string = cmd_str; |
| 344 | cmd->doc = doc_str; |
| 345 | } |
| 346 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 347 | /* logging level (<categories>) (debug|...|fatal) */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 348 | DEFUN(logging_level, |
| 349 | logging_level_cmd, |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 350 | NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */ |
| 351 | NULL) /* same thing for helpstr. */ |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 352 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 353 | struct log_target *tgt; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 354 | int category = log_parse_category(argv[0]); |
| 355 | int level = log_parse_level(argv[1]); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 356 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 357 | if (level < 0) { |
| 358 | vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE); |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 359 | return CMD_WARNING; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 362 | if (category < 0) { |
| 363 | vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE); |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 364 | return CMD_WARNING; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Pau Espin Pedrol | 57d1118 | 2020-01-02 16:21:14 +0100 | [diff] [blame] | 367 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 368 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 369 | tgt->categories[category].enabled = 1; |
| 370 | tgt->categories[category].loglevel = level; |
| 371 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 372 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 375 | DEFUN(logging_level_set_all, logging_level_set_all_cmd, |
| 376 | "logging level set-all " LOG_LEVEL_ARGS, |
| 377 | LOGGING_STR LEVEL_STR |
| 378 | "Once-off set all categories to the given log level. There is no single command" |
| 379 | " to take back these changes -- each category is set to the given level, period.\n" |
| 380 | LOG_LEVEL_STRS) |
| 381 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 382 | struct log_target *tgt; |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 383 | int level = log_parse_level(argv[0]); |
| 384 | int i; |
Neels Hofmeyr | ea6f519 | 2018-10-01 15:51:18 +0200 | [diff] [blame] | 385 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 386 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Neels Hofmeyr | ea6f519 | 2018-10-01 15:51:18 +0200 | [diff] [blame] | 387 | |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 388 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
| 389 | struct log_category *cat = &tgt->categories[i]; |
| 390 | /* skip empty entries in the array */ |
| 391 | if (!osmo_log_info->cat[i].name) |
| 392 | continue; |
| 393 | |
| 394 | cat->enabled = 1; |
| 395 | cat->loglevel = level; |
| 396 | } |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 397 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 400 | /* logging level (<categories>) everything */ |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 401 | DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd, |
| 402 | NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */ |
| 403 | NULL) /* same thing for helpstr. */ |
| 404 | { |
| 405 | vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE); |
| 406 | return CMD_SUCCESS; |
| 407 | } |
| 408 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 409 | DEFUN(logging_level_force_all, logging_level_force_all_cmd, |
| 410 | "logging level force-all " LOG_LEVEL_ARGS, |
| 411 | LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS) |
| 412 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 413 | struct log_target *tgt; |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 414 | int level = log_parse_level(argv[0]); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 415 | |
| 416 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 417 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 418 | log_set_log_level(tgt, level); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 419 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd, |
| 423 | "no logging level force-all", |
| 424 | NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR) |
| 425 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 426 | struct log_target *tgt; |
| 427 | |
| 428 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
| 429 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 430 | log_set_log_level(tgt, 0); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 431 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* 'logging level all (debug|...|fatal)' */ |
| 435 | ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd, |
| 436 | "logging level all " LOG_LEVEL_ARGS, |
| 437 | LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS); |
| 438 | |
| 439 | /* 'logging level all everything' */ |
| 440 | ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd, |
| 441 | "logging level all everything", |
| 442 | LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR); |
| 443 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 444 | DEFUN(logging_set_category_mask, |
| 445 | logging_set_category_mask_cmd, |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 446 | "logging set-log-mask MASK", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 447 | LOGGING_STR |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 448 | "Set the logmask of this logging target\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 449 | "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific" |
| 450 | " application, refer to the 'logging level' command. Optionally add individual log levels like" |
| 451 | " 'abc,1:mno,3:xyz,5', where the level numbers are" |
| 452 | " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG) |
| 453 | " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO) |
| 454 | " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE) |
| 455 | " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR) |
| 456 | " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL) |
| 457 | "\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 458 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 459 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 460 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 461 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 462 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 463 | log_parse_category_mask(tgt, argv[0]); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 464 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 467 | ALIAS_DEPRECATED(logging_set_category_mask, |
| 468 | logging_set_category_mask_old_cmd, |
| 469 | "logging set log mask MASK", |
| 470 | LOGGING_STR |
| 471 | "Decide which categories to output.\n" |
Neels Hofmeyr | 84ea2e0 | 2017-12-09 05:53:18 +0100 | [diff] [blame] | 472 | "Log commands\n" "Mask commands\n" |
| 473 | "'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] | 474 | |
| 475 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 476 | DEFUN(diable_logging, |
| 477 | disable_logging_cmd, |
| 478 | "logging disable", |
| 479 | LOGGING_STR |
| 480 | "Disables logging to this vty\n") |
| 481 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 482 | struct log_target *tgt; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 483 | struct telnet_connection *conn = (struct telnet_connection *) vty->priv; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 484 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 485 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 486 | |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 487 | log_del_target(tgt); |
| 488 | talloc_free(tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 489 | conn->dbg = NULL; |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 490 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 491 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void vty_print_logtarget(struct vty *vty, const struct log_info *info, |
| 495 | const struct log_target *tgt) |
| 496 | { |
| 497 | unsigned int i; |
| 498 | |
| 499 | vty_out(vty, " Global Loglevel: %s%s", |
| 500 | log_level_str(tgt->loglevel), VTY_NEWLINE); |
| 501 | vty_out(vty, " Use color: %s, Print Timestamp: %s%s", |
| 502 | tgt->use_color ? "On" : "Off", |
| 503 | tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE); |
| 504 | |
| 505 | vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE); |
| 506 | |
| 507 | for (i = 0; i < info->num_cat; i++) { |
| 508 | const struct log_category *cat = &tgt->categories[i]; |
Daniel Willmann | 55363a9 | 2016-11-15 10:05:51 +0100 | [diff] [blame] | 509 | /* Skip categories that were not initialized */ |
| 510 | if (!info->cat[i].name) |
| 511 | continue; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 512 | vty_out(vty, " %-10s %-10s %-8s %s%s", |
| 513 | info->cat[i].name+1, log_level_str(cat->loglevel), |
| 514 | cat->enabled ? "Enabled" : "Disabled", |
| 515 | info->cat[i].description, |
| 516 | VTY_NEWLINE); |
| 517 | } |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 518 | |
| 519 | vty_out(vty, " Log Filter 'ALL': %s%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 520 | tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled", |
Harald Welte | 6d2d4d6 | 2013-03-10 09:53:24 +0000 | [diff] [blame] | 521 | VTY_NEWLINE); |
| 522 | |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 523 | /* print application specific filters */ |
| 524 | if (info->print_fn) |
| 525 | info->print_fn(vty, info, tgt); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | #define SHOW_LOG_STR "Show current logging configuration\n" |
| 529 | |
| 530 | DEFUN(show_logging_vty, |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 531 | show_logging_vty_cmd, |
| 532 | "show logging vty", |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 533 | SHOW_STR SHOW_LOG_STR |
| 534 | "Show current logging configuration for this vty\n") |
| 535 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 536 | struct log_target *tgt; |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 537 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 538 | ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 539 | |
| 540 | vty_print_logtarget(vty, osmo_log_info, tgt); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 541 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 544 | DEFUN(show_alarms, |
| 545 | show_alarms_cmd, |
| 546 | "show alarms", |
| 547 | SHOW_STR SHOW_LOG_STR |
| 548 | "Show the contents of the logging ringbuffer\n") |
| 549 | { |
| 550 | int i, num_alarms; |
| 551 | struct osmo_strrb *rb; |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 552 | struct log_target *tgt; |
| 553 | |
| 554 | log_tgt_mutex_lock(); |
| 555 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 556 | if (!tgt) { |
| 557 | vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s", |
| 558 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 559 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | rb = tgt->tgt_rb.rb; |
| 563 | num_alarms = osmo_strrb_elements(rb); |
| 564 | |
| 565 | vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE); |
| 566 | |
| 567 | for (i = 0; i < num_alarms; i++) |
| 568 | vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i), |
| 569 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 570 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 573 | gDEFUN(cfg_description, cfg_description_cmd, |
| 574 | "description .TEXT", |
Thorsten Alteholz | a81055d | 2017-03-02 22:13:48 +0100 | [diff] [blame] | 575 | "Save human-readable description of the object\n" |
Holger Hans Peter Freyther | c9b3e06 | 2012-07-25 13:02:49 +0200 | [diff] [blame] | 576 | "Text until the end of the line\n") |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 577 | { |
| 578 | char **dptr = vty->index_sub; |
| 579 | |
| 580 | if (!dptr) { |
| 581 | vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); |
| 582 | return CMD_WARNING; |
| 583 | } |
| 584 | |
Holger Hans Peter Freyther | ff0670e | 2011-02-24 14:20:41 +0100 | [diff] [blame] | 585 | if (*dptr) |
| 586 | talloc_free(*dptr); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 587 | *dptr = argv_concat(argv, argc, 0); |
Holger Hans Peter Freyther | 6a75d16 | 2013-07-14 09:07:11 +0200 | [diff] [blame] | 588 | if (!*dptr) |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 589 | return CMD_WARNING; |
| 590 | |
| 591 | return CMD_SUCCESS; |
| 592 | } |
| 593 | |
| 594 | gDEFUN(cfg_no_description, cfg_no_description_cmd, |
| 595 | "no description", |
| 596 | NO_STR |
| 597 | "Remove description of the object\n") |
| 598 | { |
| 599 | char **dptr = vty->index_sub; |
| 600 | |
| 601 | if (!dptr) { |
| 602 | vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE); |
| 603 | return CMD_WARNING; |
| 604 | } |
| 605 | |
| 606 | if (*dptr) { |
| 607 | talloc_free(*dptr); |
| 608 | *dptr = NULL; |
| 609 | } |
| 610 | |
| 611 | return CMD_SUCCESS; |
| 612 | } |
| 613 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 614 | /* Support for configuration of log targets != the current vty */ |
| 615 | |
| 616 | struct cmd_node cfg_log_node = { |
| 617 | CFG_LOG_NODE, |
| 618 | "%s(config-log)# ", |
| 619 | 1 |
| 620 | }; |
| 621 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 622 | #ifdef HAVE_SYSLOG_H |
| 623 | |
| 624 | #include <syslog.h> |
| 625 | |
| 626 | static const int local_sysl_map[] = { |
| 627 | [0] = LOG_LOCAL0, |
| 628 | [1] = LOG_LOCAL1, |
| 629 | [2] = LOG_LOCAL2, |
| 630 | [3] = LOG_LOCAL3, |
| 631 | [4] = LOG_LOCAL4, |
| 632 | [5] = LOG_LOCAL5, |
| 633 | [6] = LOG_LOCAL6, |
| 634 | [7] = LOG_LOCAL7 |
| 635 | }; |
| 636 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 637 | /* From VTY core code */ |
| 638 | extern struct host host; |
| 639 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 640 | static int _cfg_log_syslog(struct vty *vty, int facility) |
| 641 | { |
| 642 | struct log_target *tgt; |
| 643 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 644 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 645 | /* First delete the old syslog target, if any */ |
| 646 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 647 | if (tgt) |
| 648 | log_target_destroy(tgt); |
| 649 | |
Harald Welte | de79cee | 2011-02-24 23:47:57 +0100 | [diff] [blame] | 650 | tgt = log_target_create_syslog(host.app_info->name, 0, facility); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 651 | if (!tgt) { |
| 652 | vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 653 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 654 | } |
| 655 | log_add_target(tgt); |
| 656 | |
| 657 | vty->index = tgt; |
| 658 | vty->node = CFG_LOG_NODE; |
| 659 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 660 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd, |
| 664 | "log syslog local <0-7>", |
| 665 | LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n" |
| 666 | "Local facility number\n") |
| 667 | { |
| 668 | int local = atoi(argv[0]); |
| 669 | int facility = local_sysl_map[local]; |
| 670 | |
| 671 | return _cfg_log_syslog(vty, facility); |
| 672 | } |
| 673 | |
| 674 | static struct value_string sysl_level_names[] = { |
| 675 | { LOG_AUTHPRIV, "authpriv" }, |
| 676 | { LOG_CRON, "cron" }, |
| 677 | { LOG_DAEMON, "daemon" }, |
| 678 | { LOG_FTP, "ftp" }, |
| 679 | { LOG_LPR, "lpr" }, |
| 680 | { LOG_MAIL, "mail" }, |
| 681 | { LOG_NEWS, "news" }, |
| 682 | { LOG_USER, "user" }, |
| 683 | { LOG_UUCP, "uucp" }, |
| 684 | /* only for value -> string conversion */ |
| 685 | { LOG_LOCAL0, "local 0" }, |
| 686 | { LOG_LOCAL1, "local 1" }, |
| 687 | { LOG_LOCAL2, "local 2" }, |
| 688 | { LOG_LOCAL3, "local 3" }, |
| 689 | { LOG_LOCAL4, "local 4" }, |
| 690 | { LOG_LOCAL5, "local 5" }, |
| 691 | { LOG_LOCAL6, "local 6" }, |
| 692 | { LOG_LOCAL7, "local 7" }, |
| 693 | { 0, NULL } |
| 694 | }; |
| 695 | |
| 696 | DEFUN(cfg_log_syslog, cfg_log_syslog_cmd, |
| 697 | "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] | 698 | LOG_STR "Logging via syslog\n" |
| 699 | "Security/authorization messages facility\n" |
| 700 | "Clock daemon (cron/at) facility\n" |
| 701 | "General system daemon facility\n" |
| 702 | "Ftp daemon facility\n" |
| 703 | "Line printer facility\n" |
| 704 | "Mail facility\n" |
| 705 | "News facility\n" |
| 706 | "Generic facility\n" |
| 707 | "UUCP facility\n") |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 708 | { |
| 709 | int facility = get_string_value(sysl_level_names, argv[0]); |
| 710 | |
| 711 | return _cfg_log_syslog(vty, facility); |
| 712 | } |
| 713 | |
| 714 | DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd, |
| 715 | "no log syslog", |
| 716 | NO_STR LOG_STR "Logging via syslog\n") |
| 717 | { |
| 718 | struct log_target *tgt; |
| 719 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 720 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 721 | tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL); |
| 722 | if (!tgt) { |
| 723 | vty_out(vty, "%% No syslog target found%s", |
| 724 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 725 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | log_target_destroy(tgt); |
| 729 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 730 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 731 | } |
| 732 | #endif /* HAVE_SYSLOG_H */ |
| 733 | |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 734 | DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd, |
| 735 | "log gsmtap [HOSTNAME]", |
Neels Hofmeyr | fd9ec3b | 2016-12-11 01:48:26 +0100 | [diff] [blame] | 736 | LOG_STR "Logging via GSMTAP\n" |
| 737 | "Host name to send the GSMTAP logging to (UDP port 4729)\n") |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 738 | { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 739 | const char *hostname = argc ? argv[0] : "127.0.0.1"; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 740 | struct log_target *tgt; |
| 741 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 742 | log_tgt_mutex_lock(); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 743 | tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname); |
| 744 | if (!tgt) { |
| 745 | tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT, |
| 746 | host.app_info->name, false, |
| 747 | true); |
| 748 | if (!tgt) { |
Max | 2f153b5 | 2018-01-04 12:25:57 +0100 | [diff] [blame] | 749 | vty_out(vty, "%% Unable to create GSMTAP log for %s%s", |
| 750 | hostname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 751 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 752 | } |
| 753 | log_add_target(tgt); |
| 754 | } |
| 755 | |
| 756 | vty->index = tgt; |
| 757 | vty->node = CFG_LOG_NODE; |
| 758 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 759 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 762 | DEFUN(cfg_log_stderr, cfg_log_stderr_cmd, |
| 763 | "log stderr", |
| 764 | LOG_STR "Logging via STDERR of the process\n") |
| 765 | { |
| 766 | struct log_target *tgt; |
| 767 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 768 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 769 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 770 | if (!tgt) { |
| 771 | tgt = log_target_create_stderr(); |
| 772 | if (!tgt) { |
| 773 | vty_out(vty, "%% Unable to create stderr log%s", |
| 774 | VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 775 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 776 | } |
| 777 | log_add_target(tgt); |
| 778 | } |
| 779 | |
| 780 | vty->index = tgt; |
| 781 | vty->node = CFG_LOG_NODE; |
| 782 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 783 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd, |
| 787 | "no log stderr", |
| 788 | NO_STR LOG_STR "Logging via STDERR of the process\n") |
| 789 | { |
| 790 | struct log_target *tgt; |
| 791 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 792 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 793 | tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL); |
| 794 | if (!tgt) { |
| 795 | vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 796 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | log_target_destroy(tgt); |
| 800 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 801 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | DEFUN(cfg_log_file, cfg_log_file_cmd, |
| 805 | "log file .FILENAME", |
| 806 | LOG_STR "Logging to text file\n" "Filename\n") |
| 807 | { |
| 808 | const char *fname = argv[0]; |
| 809 | struct log_target *tgt; |
| 810 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 811 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 812 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 813 | if (!tgt) { |
| 814 | tgt = log_target_create_file(fname); |
| 815 | if (!tgt) { |
| 816 | vty_out(vty, "%% Unable to create file `%s'%s", |
| 817 | fname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 818 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 819 | } |
| 820 | log_add_target(tgt); |
| 821 | } |
| 822 | |
| 823 | vty->index = tgt; |
| 824 | vty->node = CFG_LOG_NODE; |
| 825 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 826 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
| 830 | DEFUN(cfg_no_log_file, cfg_no_log_file_cmd, |
| 831 | "no log file .FILENAME", |
| 832 | NO_STR LOG_STR "Logging to text file\n" "Filename\n") |
| 833 | { |
| 834 | const char *fname = argv[0]; |
| 835 | struct log_target *tgt; |
| 836 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 837 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 838 | tgt = log_target_find(LOG_TGT_TYPE_FILE, fname); |
| 839 | if (!tgt) { |
| 840 | vty_out(vty, "%% No such log file `%s'%s", |
| 841 | fname, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 842 | RET_WITH_UNLOCK(CMD_WARNING); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | log_target_destroy(tgt); |
| 846 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 847 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 850 | DEFUN(cfg_log_alarms, cfg_log_alarms_cmd, |
| 851 | "log alarms <2-32700>", |
| 852 | LOG_STR "Logging alarms to osmo_strrb\n" |
| 853 | "Maximum number of messages to log\n") |
| 854 | { |
| 855 | struct log_target *tgt; |
| 856 | unsigned int rbsize = atoi(argv[0]); |
| 857 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 858 | |
| 859 | log_tgt_mutex_lock(); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 860 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 861 | if (tgt) |
| 862 | log_target_destroy(tgt); |
| 863 | |
| 864 | tgt = log_target_create_rb(rbsize); |
| 865 | if (!tgt) { |
| 866 | vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s", |
| 867 | rbsize, VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 868 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 869 | } |
| 870 | log_add_target(tgt); |
| 871 | |
| 872 | vty->index = tgt; |
| 873 | vty->node = CFG_LOG_NODE; |
| 874 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 875 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd, |
| 879 | "no log alarms", |
| 880 | NO_STR LOG_STR "Logging alarms to osmo_strrb\n") |
| 881 | { |
| 882 | struct log_target *tgt; |
| 883 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 884 | log_tgt_mutex_lock(); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 885 | tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL); |
| 886 | if (!tgt) { |
| 887 | vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 888 | RET_WITH_UNLOCK(CMD_WARNING); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | log_target_destroy(tgt); |
| 892 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 893 | RET_WITH_UNLOCK(CMD_SUCCESS); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 896 | static int config_write_log_single(struct vty *vty, struct log_target *tgt) |
| 897 | { |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 898 | char level_buf[128]; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 899 | int i; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 900 | |
| 901 | switch (tgt->type) { |
| 902 | case LOG_TGT_TYPE_VTY: |
| 903 | return 1; |
| 904 | break; |
| 905 | case LOG_TGT_TYPE_STDERR: |
| 906 | vty_out(vty, "log stderr%s", VTY_NEWLINE); |
| 907 | break; |
| 908 | case LOG_TGT_TYPE_SYSLOG: |
| 909 | #ifdef HAVE_SYSLOG_H |
| 910 | vty_out(vty, "log syslog %s%s", |
| 911 | get_value_string(sysl_level_names, |
| 912 | tgt->tgt_syslog.facility), |
| 913 | VTY_NEWLINE); |
| 914 | #endif |
| 915 | break; |
| 916 | case LOG_TGT_TYPE_FILE: |
| 917 | vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE); |
| 918 | break; |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 919 | case LOG_TGT_TYPE_STRRB: |
| 920 | vty_out(vty, "log alarms %zu%s", |
| 921 | log_target_rb_avail_size(tgt), VTY_NEWLINE); |
| 922 | break; |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 923 | case LOG_TGT_TYPE_GSMTAP: |
| 924 | vty_out(vty, "log gsmtap %s%s", |
| 925 | tgt->tgt_gsmtap.hostname, VTY_NEWLINE); |
| 926 | break; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 929 | vty_out(vty, " logging filter all %u%s", |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 930 | tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE); |
Harald Welte | fb84f32 | 2013-06-06 07:33:54 +0200 | [diff] [blame] | 931 | /* save filters outside of libosmocore, i.e. in app code */ |
| 932 | if (osmo_log_info->save_fn) |
| 933 | osmo_log_info->save_fn(vty, osmo_log_info, tgt); |
Harald Welte | 2da47f1 | 2012-10-22 19:31:54 +0200 | [diff] [blame] | 934 | |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 935 | vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0, |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 936 | VTY_NEWLINE); |
Vadim Yanitskiy | 5c4b985 | 2019-07-28 04:36:37 +0700 | [diff] [blame] | 937 | vty_out(vty, " logging print category-hex %d%s", |
| 938 | tgt->print_category_hex ? 1 : 0, VTY_NEWLINE); |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 939 | vty_out(vty, " logging print category %d%s", |
Michael McTernan | 7893346 | 2015-03-20 15:29:25 +0100 | [diff] [blame] | 940 | tgt->print_category ? 1 : 0, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 941 | if (tgt->print_ext_timestamp) |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 942 | 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] | 943 | else |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 944 | vty_out(vty, " logging timestamp %u%s", |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 945 | tgt->print_timestamp ? 1 : 0, VTY_NEWLINE); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 946 | if (tgt->print_level) |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 947 | vty_out(vty, " logging print level 1%s", VTY_NEWLINE); |
| 948 | vty_out(vty, " logging print file %s%s", |
Neels Hofmeyr | 22772cc | 2018-02-06 00:52:08 +0100 | [diff] [blame] | 949 | get_value_string(logging_print_file_args, tgt->print_filename2), |
| 950 | VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 951 | |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 952 | if (tgt->loglevel) { |
| 953 | 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] | 954 | if (!level_str) { |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 955 | vty_out(vty, "%% Invalid log level %u for 'force-all'%s", |
| 956 | tgt->loglevel, VTY_NEWLINE); |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 957 | } else { |
| 958 | osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); |
| 959 | vty_out(vty, " logging level force-all %s%s", level_buf, VTY_NEWLINE); |
| 960 | } |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 961 | } |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 962 | |
| 963 | for (i = 0; i < osmo_log_info->num_cat; i++) { |
| 964 | const struct log_category *cat = &tgt->categories[i]; |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 965 | char cat_name[128]; |
Neels Hofmeyr | 098038a | 2018-09-11 23:49:13 +0200 | [diff] [blame] | 966 | const char *level_str; |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 967 | |
Harald Welte | 1a02cfc | 2013-03-19 10:37:39 +0100 | [diff] [blame] | 968 | /* skip empty entries in the array */ |
| 969 | if (!osmo_log_info->cat[i].name) |
| 970 | continue; |
| 971 | |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 972 | 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] | 973 | |
| 974 | level_str = get_value_string_or_null(loglevel_strs, cat->loglevel); |
| 975 | if (!level_str) { |
| 976 | vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name, |
| 977 | VTY_NEWLINE); |
| 978 | continue; |
| 979 | } |
| 980 | |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 981 | osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); |
Harald Welte | 0d67f48 | 2018-09-25 20:16:14 +0200 | [diff] [blame] | 982 | vty_out(vty, " logging level %s", cat_name); |
Pau Espin Pedrol | c21ba15 | 2019-08-02 20:32:34 +0200 | [diff] [blame] | 983 | vty_out(vty, " %s%s", level_buf, VTY_NEWLINE); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 986 | return 1; |
| 987 | } |
| 988 | |
| 989 | static int config_write_log(struct vty *vty) |
| 990 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 991 | log_tgt_mutex_lock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 992 | struct log_target *dbg = vty->index; |
| 993 | |
| 994 | llist_for_each_entry(dbg, &osmo_log_target_list, entry) |
| 995 | config_write_log_single(vty, dbg); |
| 996 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 997 | log_tgt_mutex_unlock(); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 998 | return 1; |
| 999 | } |
| 1000 | |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1001 | static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[]) |
| 1002 | { |
| 1003 | vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE); |
Vadim Yanitskiy | 4abda9e | 2019-11-21 00:19:36 +0700 | [diff] [blame] | 1004 | return CMD_SUCCESS; /* Otherwise the process would terminate */ |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | void logging_vty_add_deprecated_subsys(void *ctx, const char *name) |
| 1008 | { |
| 1009 | struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element); |
| 1010 | OSMO_ASSERT(cmd); |
Vadim Yanitskiy | 75c242e | 2019-11-21 00:06:53 +0700 | [diff] [blame] | 1011 | cmd->string = talloc_asprintf(cmd, "logging level %s " LOG_LEVEL_ARGS, name); |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1012 | cmd->func = log_deprecated_func; |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1013 | cmd->doc = LEVEL_STR |
Harald Welte | 11eb4b5 | 2018-06-09 17:41:31 +0200 | [diff] [blame] | 1014 | "Deprecated Category\n"; |
| 1015 | cmd->attr = CMD_ATTR_DEPRECATED; |
| 1016 | |
| 1017 | install_element(CFG_LOG_NODE, cmd); |
| 1018 | } |
| 1019 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1020 | /* logp (<categories>) (debug|...|fatal) .LOGMESSAGE*/ |
| 1021 | DEFUN(vty_logp, |
| 1022 | vty_logp_cmd, |
| 1023 | NULL, /* cmdstr is dynamically set in gen_vty_logp_cmd_strs(). */ |
| 1024 | NULL) /* same thing for helpstr. */ |
| 1025 | { |
| 1026 | int category = log_parse_category(argv[0]); |
| 1027 | int level = log_parse_level(argv[1]); |
| 1028 | char *str = argv_concat(argv, argc, 2); |
| 1029 | LOGP(category, level, "%s\n", str); |
| 1030 | return CMD_SUCCESS; |
| 1031 | } |
| 1032 | |
| 1033 | static void gen_vty_logp_cmd_strs(struct cmd_element *cmd) |
| 1034 | { |
| 1035 | char *cmd_str = NULL; |
| 1036 | char *doc_str = NULL; |
| 1037 | |
| 1038 | assert_loginfo(__func__); |
| 1039 | |
| 1040 | OSMO_ASSERT(cmd->string == NULL); |
| 1041 | OSMO_ASSERT(cmd->doc == NULL); |
| 1042 | |
| 1043 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logp ("); |
| 1044 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 1045 | "Print a message on all log outputs; useful for placing markers in test logs\n"); |
| 1046 | add_category_strings(&cmd_str, &doc_str, osmo_log_info); |
| 1047 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", LOG_LEVEL_ARGS); |
| 1048 | osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", LOG_LEVEL_STRS); |
| 1049 | |
| 1050 | osmo_talloc_asprintf(tall_log_ctx, cmd_str, " .LOGMESSAGE"); |
| 1051 | osmo_talloc_asprintf(tall_log_ctx, doc_str, |
| 1052 | "Arbitrary message to log on given category and log level\n"); |
| 1053 | |
Harald Welte | bebec21 | 2020-07-15 12:21:29 +0200 | [diff] [blame] | 1054 | talloc_set_name_const(cmd_str, "vty_logp_cmd_str"); |
| 1055 | talloc_set_name_const(doc_str, "vty_logp_doc_str"); |
| 1056 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1057 | cmd->string = cmd_str; |
| 1058 | cmd->doc = doc_str; |
| 1059 | } |
| 1060 | |
Harald Welte | 8c64825 | 2017-10-16 15:17:03 +0200 | [diff] [blame] | 1061 | /*! Register logging related commands to the VTY. Call this once from |
| 1062 | * your application if you want to support those commands. */ |
Max | c65c5b4 | 2017-03-15 13:20:23 +0100 | [diff] [blame] | 1063 | void logging_vty_add_cmds() |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1064 | { |
| 1065 | install_element_ve(&enable_logging_cmd); |
| 1066 | install_element_ve(&disable_logging_cmd); |
| 1067 | install_element_ve(&logging_fltr_all_cmd); |
| 1068 | install_element_ve(&logging_use_clr_cmd); |
| 1069 | install_element_ve(&logging_prnt_timestamp_cmd); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 1070 | install_element_ve(&logging_prnt_ext_timestamp_cmd); |
| 1071 | install_element_ve(&logging_prnt_cat_cmd); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 1072 | install_element_ve(&logging_prnt_cat_hex_cmd); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 1073 | install_element_ve(&logging_prnt_level_cmd); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 1074 | install_element_ve(&logging_prnt_file_cmd); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1075 | install_element_ve(&logging_set_category_mask_cmd); |
Holger Hans Peter Freyther | 146d1d3 | 2011-10-03 23:15:41 +0200 | [diff] [blame] | 1076 | install_element_ve(&logging_set_category_mask_old_cmd); |
Pablo Neira Ayuso | 04139f1 | 2011-03-09 13:05:08 +0100 | [diff] [blame] | 1077 | |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1078 | /* logging level (<categories>) (debug|...|fatal) */ |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1079 | gen_logging_level_cmd_strs(&logging_level_cmd, |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1080 | LOG_LEVEL_ARGS, |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1081 | LOG_LEVEL_STRS); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1082 | /* logging level (<categories>) everything */ |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1083 | gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd, |
| 1084 | "everything", EVERYTHING_STR); |
Neels Hofmeyr | ba0762d | 2018-09-10 13:56:03 +0200 | [diff] [blame] | 1085 | |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1086 | install_element_ve(&logging_level_cmd); |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 1087 | install_element_ve(&logging_level_set_all_cmd); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1088 | install_element_ve(&logging_level_force_all_cmd); |
| 1089 | install_element_ve(&no_logging_level_force_all_cmd); |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1090 | install_element_ve(&deprecated_logging_level_everything_cmd); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1091 | install_element_ve(&deprecated_logging_level_all_cmd); |
| 1092 | install_element_ve(&deprecated_logging_level_all_everything_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1093 | |
Neels Hofmeyr | d0b3b9e | 2019-07-29 19:28:08 +0200 | [diff] [blame] | 1094 | gen_vty_logp_cmd_strs(&vty_logp_cmd); |
| 1095 | install_element_ve(&vty_logp_cmd); |
| 1096 | |
Pau Espin Pedrol | 0c2a46d | 2019-08-20 10:39:05 +0200 | [diff] [blame] | 1097 | install_element_ve(&show_logging_vty_cmd); |
| 1098 | install_element_ve(&show_alarms_cmd); |
| 1099 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1100 | install_node(&cfg_log_node, config_write_log); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 1101 | install_element(CFG_LOG_NODE, &logging_fltr_all_cmd); |
| 1102 | install_element(CFG_LOG_NODE, &logging_use_clr_cmd); |
| 1103 | install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd); |
Holger Hans Peter Freyther | 2d6ad13 | 2014-12-05 09:35:30 +0100 | [diff] [blame] | 1104 | install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd); |
| 1105 | install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd); |
Neels Hofmeyr | bd7bd39 | 2018-01-16 01:52:29 +0100 | [diff] [blame] | 1106 | install_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd); |
Neels Hofmeyr | 886e548 | 2018-01-16 01:49:37 +0100 | [diff] [blame] | 1107 | install_element(CFG_LOG_NODE, &logging_prnt_level_cmd); |
Neels Hofmeyr | c6fd245 | 2018-01-16 01:57:38 +0100 | [diff] [blame] | 1108 | install_element(CFG_LOG_NODE, &logging_prnt_file_cmd); |
Harald Welte | a62648b | 2011-02-18 21:03:27 +0100 | [diff] [blame] | 1109 | install_element(CFG_LOG_NODE, &logging_level_cmd); |
Neels Hofmeyr | 28fc078 | 2018-09-12 02:32:02 +0200 | [diff] [blame] | 1110 | install_element(CFG_LOG_NODE, &logging_level_set_all_cmd); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1111 | install_element(CFG_LOG_NODE, &logging_level_force_all_cmd); |
| 1112 | install_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd); |
Neels Hofmeyr | 7e0686c | 2018-09-10 20:58:52 +0200 | [diff] [blame] | 1113 | install_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd); |
Neels Hofmeyr | 9540c24 | 2018-09-12 00:20:50 +0200 | [diff] [blame] | 1114 | install_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd); |
| 1115 | install_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1116 | |
| 1117 | install_element(CONFIG_NODE, &cfg_log_stderr_cmd); |
| 1118 | install_element(CONFIG_NODE, &cfg_no_log_stderr_cmd); |
| 1119 | install_element(CONFIG_NODE, &cfg_log_file_cmd); |
| 1120 | install_element(CONFIG_NODE, &cfg_no_log_file_cmd); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 1121 | install_element(CONFIG_NODE, &cfg_log_alarms_cmd); |
| 1122 | install_element(CONFIG_NODE, &cfg_no_log_alarms_cmd); |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 1123 | #ifdef HAVE_SYSLOG_H |
| 1124 | install_element(CONFIG_NODE, &cfg_log_syslog_cmd); |
| 1125 | install_element(CONFIG_NODE, &cfg_log_syslog_local_cmd); |
| 1126 | install_element(CONFIG_NODE, &cfg_no_log_syslog_cmd); |
| 1127 | #endif |
Harald Welte | aa00f99 | 2016-12-02 15:30:02 +0100 | [diff] [blame] | 1128 | install_element(CONFIG_NODE, &cfg_log_gsmtap_cmd); |
Harald Welte | 3fb0b6f | 2010-05-19 19:02:52 +0200 | [diff] [blame] | 1129 | } |