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