blob: 2a074222d45ce54bb338852cb09199478f467e0e [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*
2 * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01003 * (C) 2009-2014 by Holger Hans Peter Freyther
Harald Welte3fb0b6f2010-05-19 19:02:52 +02004 * All Rights Reserved
5 *
Harald Weltee08da972017-11-13 01:00:26 +09006 * SPDX-License-Identifier: GPL-2.0+
7 *
Harald Welte3fb0b6f2010-05-19 19:02:52 +02008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
Harald Welte3fb0b6f2010-05-19 19:02:52 +020018 */
19
20#include <stdlib.h>
21#include <string.h>
22
Pau Espin Pedrol88955fb2023-01-18 18:54:00 +010023#include "config.h"
Harald Welte28222962011-02-18 20:37:04 +010024
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010025#include <osmocom/core/talloc.h>
26#include <osmocom/core/logging.h>
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020027#include <osmocom/core/logging_internal.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010028#include <osmocom/core/utils.h>
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000029#include <osmocom/core/strrb.h>
30#include <osmocom/core/loggingrb.h>
Harald Welteaa00f992016-12-02 15:30:02 +010031#include <osmocom/core/gsmtap.h>
Harald Weltee4d9a2c2020-09-27 11:28:58 +020032#include <osmocom/core/application.h>
Harald Welte3fb0b6f2010-05-19 19:02:52 +020033
34#include <osmocom/vty/command.h>
35#include <osmocom/vty/buffer.h>
36#include <osmocom/vty/vty.h>
37#include <osmocom/vty/telnet_interface.h>
38#include <osmocom/vty/logging.h>
39
Harald Welte28222962011-02-18 20:37:04 +010040#define LOG_STR "Configure logging sub-system\n"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020041#define LEVEL_STR "Set the log level for a specified category\n"
42
Neels Hofmeyr9540c242018-09-12 00:20:50 +020043#define CATEGORY_ALL_STR "Deprecated alias for 'force-all'\n"
44#define FORCE_ALL_STR \
45 "Globally force all logging categories to a specific level. This is released by the" \
46 " 'no logging level force-all' command. Note: any 'logging level <category> <level>'" \
47 " commands will have no visible effect after this, until the forced level is released.\n"
48#define NO_FORCE_ALL_STR \
49 "Release any globally forced log level set with 'logging level force-all <level>'\n"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020050
Neels Hofmeyr9540c242018-09-12 00:20:50 +020051#define LOG_LEVEL_ARGS "(debug|info|notice|error|fatal)"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020052#define LOG_LEVEL_STRS \
53 "Log debug messages and higher levels\n" \
54 "Log informational messages and higher levels\n" \
55 "Log noticeable messages and higher levels\n" \
56 "Log error messages and higher levels\n" \
57 "Log only fatal messages\n"
58
Neels Hofmeyr9540c242018-09-12 00:20:50 +020059#define EVERYTHING_STR "Deprecated alias for 'no logging level force-all'\n"
Harald Welte28222962011-02-18 20:37:04 +010060
Harald Welte8c648252017-10-16 15:17:03 +020061/*! \file logging_vty.c
Neels Hofmeyr87e45502017-06-20 00:17:59 +020062 * Configuration of logging from VTY
Harald Welte96e2a002017-06-12 21:44:18 +020063 *
Harald Welte8c648252017-10-16 15:17:03 +020064 * This module implements
65 * - functions that permit configuration of the libosmocore logging
66 * framework from VTY commands in the configure -> logging node.
67 *
68 * - functions that permit logging *to* a VTY session. Basically each
69 * VTY session gets its own log target, with configurable
70 * per-subsystem log levels. This is performed internally via the
71 * \ref log_target_create_vty function.
72 *
73 * You have to call \ref logging_vty_add_cmds from your application
74 * once to enable both of the above.
75 *
Harald Welte96e2a002017-06-12 21:44:18 +020076 */
77
Harald Welte76e72ab2011-02-17 15:52:39 +010078static void _vty_output(struct log_target *tgt,
79 unsigned int level, const char *line)
Harald Welte3fb0b6f2010-05-19 19:02:52 +020080{
81 struct vty *vty = tgt->tgt_vty.vty;
82 vty_out(vty, "%s", line);
83 /* This is an ugly hack, but there is no easy way... */
84 if (strchr(line, '\n'))
85 vty_out(vty, "\r");
86}
87
88struct log_target *log_target_create_vty(struct vty *vty)
89{
90 struct log_target *target;
91
92 target = log_target_create();
93 if (!target)
94 return NULL;
95
96 target->tgt_vty.vty = vty;
97 target->output = _vty_output;
98 return target;
99}
100
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200101/*! Get tgt with log lock acquired, return and release lock with warning if tgt
102 * is not found. Lock must be released later with log_tgt_mutex_unlock().
103 */
104#define ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt) \
105 do { \
106 log_tgt_mutex_lock(); \
107 tgt = osmo_log_vty2tgt(vty); \
108 if (!(tgt)) { \
109 log_tgt_mutex_unlock(); \
110 return CMD_WARNING; \
111 } \
112 } while (0)
113
114#define RET_WITH_UNLOCK(ret) \
115 do { \
116 log_tgt_mutex_unlock(); \
117 return (ret); \
118 } while (0)
119
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200120DEFUN(enable_logging,
121 enable_logging_cmd,
122 "logging enable",
123 LOGGING_STR
124 "Enables logging to this vty\n")
125{
126 struct telnet_connection *conn;
127
128 conn = (struct telnet_connection *) vty->priv;
129 if (conn->dbg) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200130 vty_out(vty, "%% Logging already enabled.%s", VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200131 return CMD_WARNING;
132 }
133
134 conn->dbg = log_target_create_vty(vty);
135 if (!conn->dbg)
136 return CMD_WARNING;
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200137 log_tgt_mutex_lock();
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200138 log_add_target(conn->dbg);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200139 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200140}
141
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200142/*! Get log target associated to VTY console.
143 * \param[in] vty Log target type
144 * \returns Log target (if logging enabled), NULL otherwise
145 * Must be called with mutex osmo_log_tgt_mutex held, see log_tgt_mutex_lock.
146 */
Harald Weltea62648b2011-02-18 21:03:27 +0100147struct log_target *osmo_log_vty2tgt(struct vty *vty)
148{
149 struct telnet_connection *conn;
150
151 if (vty->node == CFG_LOG_NODE)
152 return vty->index;
153
154
155 conn = (struct telnet_connection *) vty->priv;
156 if (!conn->dbg)
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200157 vty_out(vty, "%% Logging was not enabled.%s", VTY_NEWLINE);
Harald Weltea62648b2011-02-18 21:03:27 +0100158
159 return conn->dbg;
160}
161
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200162DEFUN(logging_fltr_all,
163 logging_fltr_all_cmd,
164 "logging filter all (0|1)",
165 LOGGING_STR FILTER_STR
166 "Do you want to log all messages?\n"
167 "Only print messages matched by other filters\n"
168 "Bypass filter and print all messages\n")
169{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200170 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200171
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200172 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200173
Harald Weltea62648b2011-02-18 21:03:27 +0100174 log_set_all_filter(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200175 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200176}
177
178DEFUN(logging_use_clr,
179 logging_use_clr_cmd,
180 "logging color (0|1)",
181 LOGGING_STR "Configure color-printing for log messages\n"
182 "Don't use color for printing messages\n"
183 "Use color for printing messages\n")
184{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200185 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200186
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200187 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200188
Harald Weltea62648b2011-02-18 21:03:27 +0100189 log_set_use_color(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200190 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200191}
192
193DEFUN(logging_prnt_timestamp,
194 logging_prnt_timestamp_cmd,
195 "logging timestamp (0|1)",
196 LOGGING_STR "Configure log message timestamping\n"
197 "Don't prefix each log message\n"
198 "Prefix each log message with current timestamp\n")
199{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200200 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200201
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200202 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200203
Harald Weltea62648b2011-02-18 21:03:27 +0100204 log_set_print_timestamp(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200205 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200206}
207
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100208DEFUN(logging_prnt_ext_timestamp,
209 logging_prnt_ext_timestamp_cmd,
210 "logging print extended-timestamp (0|1)",
211 LOGGING_STR "Log output settings\n"
212 "Configure log message timestamping\n"
213 "Don't prefix each log message\n"
214 "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n")
215{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200216 struct log_target *tgt;
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100217
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200218 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100219
220 log_set_print_extended_timestamp(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200221 RET_WITH_UNLOCK(CMD_SUCCESS);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100222}
223
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +0100224DEFUN(logging_prnt_tid,
225 logging_prnt_tid_cmd,
226 "logging print thread-id (0|1)",
227 LOGGING_STR "Log output settings\n"
228 "Configure log message logging Thread ID\n"
229 "Don't prefix each log message\n"
230 "Prefix each log message with current Thread ID\n")
231{
232 struct log_target *tgt;
233
234 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
235
236 log_set_print_tid(tgt, atoi(argv[0]));
237 RET_WITH_UNLOCK(CMD_SUCCESS);
238}
239
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100240DEFUN(logging_prnt_cat,
241 logging_prnt_cat_cmd,
242 "logging print category (0|1)",
243 LOGGING_STR "Log output settings\n"
244 "Configure log message\n"
245 "Don't prefix each log message\n"
246 "Prefix each log message with category/subsystem name\n")
247{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200248 struct log_target *tgt;
249 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100250
251 log_set_print_category(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200252 RET_WITH_UNLOCK(CMD_SUCCESS);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100253}
254
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100255DEFUN(logging_prnt_cat_hex,
256 logging_prnt_cat_hex_cmd,
257 "logging print category-hex (0|1)",
258 LOGGING_STR "Log output settings\n"
259 "Configure log message\n"
260 "Don't prefix each log message\n"
261 "Prefix each log message with category/subsystem nr in hex ('<000b>')\n")
262{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200263 struct log_target *tgt;
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100264
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200265 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100266
267 log_set_print_category_hex(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200268 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100269}
270
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100271DEFUN(logging_prnt_level,
272 logging_prnt_level_cmd,
273 "logging print level (0|1)",
274 LOGGING_STR "Log output settings\n"
275 "Configure log message\n"
276 "Don't prefix each log message\n"
277 "Prefix each log message with the log level name\n")
278{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200279 struct log_target *tgt;
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100280
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200281 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100282
283 log_set_print_level(tgt, atoi(argv[0]));
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200284 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100285}
286
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100287static const struct value_string logging_print_file_args[] = {
288 { LOG_FILENAME_NONE, "0" },
289 { LOG_FILENAME_PATH, "1" },
290 { LOG_FILENAME_BASENAME, "basename" },
291 { 0, NULL }
292};
293
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100294DEFUN(logging_prnt_file,
295 logging_prnt_file_cmd,
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200296 "logging print file (0|1|basename) [last]",
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100297 LOGGING_STR "Log output settings\n"
298 "Configure log message\n"
299 "Don't prefix each log message\n"
300 "Prefix each log message with the source file and line\n"
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200301 "Prefix each log message with the source file's basename (strip leading paths) and line\n"
302 "Log source file info at the end of a log line. If omitted, log source file info just"
303 " before the log text.\n")
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100304{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200305 struct log_target *tgt;
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100306
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200307 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100308
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100309 log_set_print_filename2(tgt, get_string_value(logging_print_file_args, argv[0]));
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200310 if (argc > 1)
311 log_set_print_filename_pos(tgt, LOG_FILENAME_POS_LINE_END);
312 else
313 log_set_print_filename_pos(tgt, LOG_FILENAME_POS_HEADER_END);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200314 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100315}
316
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200317static void add_category_strings(char **cmd_str_p, char **doc_str_p,
318 const struct log_info *categories)
319{
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +0200320 char buf[128];
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200321 int i;
322 for (i = 0; i < categories->num_cat; i++) {
323 if (categories->cat[i].name == NULL)
324 continue;
325 /* skip the leading 'D' in each category name, hence '+ 1' */
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +0200326 osmo_str_tolower_buf(buf, sizeof(buf), categories->cat[i].name + 1);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200327 osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s",
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +0200328 i ? "|" : "", buf);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200329 osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n",
330 categories->cat[i].description);
331 }
332}
333
334static void gen_logging_level_cmd_strs(struct cmd_element *cmd,
335 const char *level_args, const char *level_strs)
336{
337 char *cmd_str = NULL;
338 char *doc_str = NULL;
339
340 assert_loginfo(__func__);
341
342 OSMO_ASSERT(cmd->string == NULL);
343 OSMO_ASSERT(cmd->doc == NULL);
344
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200345 osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logging level (");
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200346 osmo_talloc_asprintf(tall_log_ctx, doc_str,
347 LOGGING_STR
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200348 LEVEL_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200349 add_category_strings(&cmd_str, &doc_str, osmo_log_info);
350 osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args);
351 osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs);
352
Harald Weltebebec212020-07-15 12:21:29 +0200353 talloc_set_name_const(cmd_str, "vty_log_level_cmd_str");
354 talloc_set_name_const(doc_str, "vty_log_level_doc_str");
355
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200356 cmd->string = cmd_str;
357 cmd->doc = doc_str;
358}
359
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200360/* logging level (<categories>) (debug|...|fatal) */
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200361DEFUN(logging_level,
362 logging_level_cmd,
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +0100363 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
364 NULL) /* same thing for helpstr. */
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200365{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200366 struct log_target *tgt;
Harald Weltea62648b2011-02-18 21:03:27 +0100367 int category = log_parse_category(argv[0]);
368 int level = log_parse_level(argv[1]);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200369
Harald Weltea62648b2011-02-18 21:03:27 +0100370 if (level < 0) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200371 vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE);
Pau Espin Pedrol57d11182020-01-02 16:21:14 +0100372 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200373 }
374
Harald Weltea62648b2011-02-18 21:03:27 +0100375 if (category < 0) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200376 vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE);
Pau Espin Pedrol57d11182020-01-02 16:21:14 +0100377 return CMD_WARNING;
Harald Weltea62648b2011-02-18 21:03:27 +0100378 }
379
Pau Espin Pedrol57d11182020-01-02 16:21:14 +0100380 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
381
Harald Weltea62648b2011-02-18 21:03:27 +0100382 tgt->categories[category].enabled = 1;
383 tgt->categories[category].loglevel = level;
384
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200385 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200386}
387
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200388DEFUN(logging_level_set_all, logging_level_set_all_cmd,
389 "logging level set-all " LOG_LEVEL_ARGS,
390 LOGGING_STR LEVEL_STR
391 "Once-off set all categories to the given log level. There is no single command"
392 " to take back these changes -- each category is set to the given level, period.\n"
393 LOG_LEVEL_STRS)
394{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200395 struct log_target *tgt;
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200396 int level = log_parse_level(argv[0]);
397 int i;
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200398
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200399 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200400
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200401 for (i = 0; i < osmo_log_info->num_cat; i++) {
402 struct log_category *cat = &tgt->categories[i];
403 /* skip empty entries in the array */
404 if (!osmo_log_info->cat[i].name)
405 continue;
406
407 cat->enabled = 1;
408 cat->loglevel = level;
409 }
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200410 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200411}
412
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200413/* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200414DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd,
415 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
416 NULL) /* same thing for helpstr. */
417{
418 vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE);
419 return CMD_SUCCESS;
420}
421
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200422DEFUN(logging_level_force_all, logging_level_force_all_cmd,
423 "logging level force-all " LOG_LEVEL_ARGS,
424 LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS)
425{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200426 struct log_target *tgt;
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200427 int level = log_parse_level(argv[0]);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200428
429 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
430
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200431 log_set_log_level(tgt, level);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200432 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200433}
434
435DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd,
436 "no logging level force-all",
437 NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)
438{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200439 struct log_target *tgt;
440
441 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
442
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200443 log_set_log_level(tgt, 0);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200444 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200445}
446
447/* 'logging level all (debug|...|fatal)' */
448ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd,
449 "logging level all " LOG_LEVEL_ARGS,
450 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS);
451
452/* 'logging level all everything' */
453ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd,
454 "logging level all everything",
455 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR);
456
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200457DEFUN(logging_set_category_mask,
458 logging_set_category_mask_cmd,
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200459 "logging set-log-mask MASK",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200460 LOGGING_STR
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200461 "Set the logmask of this logging target\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100462 "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific"
463 " application, refer to the 'logging level' command. Optionally add individual log levels like"
464 " 'abc,1:mno,3:xyz,5', where the level numbers are"
465 " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG)
466 " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO)
467 " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE)
468 " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR)
469 " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL)
470 "\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200471{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200472 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200473
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200474 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200475
Harald Weltea62648b2011-02-18 21:03:27 +0100476 log_parse_category_mask(tgt, argv[0]);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200477 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200478}
479
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200480ALIAS_DEPRECATED(logging_set_category_mask,
481 logging_set_category_mask_old_cmd,
482 "logging set log mask MASK",
483 LOGGING_STR
484 "Decide which categories to output.\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100485 "Log commands\n" "Mask commands\n"
486 "'set log mask' is deprecated, please refer to the docs of 'set-log-mask' instead\n");
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200487
488
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200489DEFUN(diable_logging,
490 disable_logging_cmd,
491 "logging disable",
492 LOGGING_STR
493 "Disables logging to this vty\n")
494{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200495 struct log_target *tgt;
Harald Weltea62648b2011-02-18 21:03:27 +0100496 struct telnet_connection *conn = (struct telnet_connection *) vty->priv;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200497
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200498 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200499
Harald Weltea62648b2011-02-18 21:03:27 +0100500 log_del_target(tgt);
501 talloc_free(tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200502 conn->dbg = NULL;
Harald Weltea62648b2011-02-18 21:03:27 +0100503
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200504 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200505}
506
507static void vty_print_logtarget(struct vty *vty, const struct log_info *info,
508 const struct log_target *tgt)
509{
510 unsigned int i;
511
512 vty_out(vty, " Global Loglevel: %s%s",
513 log_level_str(tgt->loglevel), VTY_NEWLINE);
514 vty_out(vty, " Use color: %s, Print Timestamp: %s%s",
515 tgt->use_color ? "On" : "Off",
516 tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE);
517
518 vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE);
519
520 for (i = 0; i < info->num_cat; i++) {
521 const struct log_category *cat = &tgt->categories[i];
Daniel Willmann55363a92016-11-15 10:05:51 +0100522 /* Skip categories that were not initialized */
523 if (!info->cat[i].name)
524 continue;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200525 vty_out(vty, " %-10s %-10s %-8s %s%s",
526 info->cat[i].name+1, log_level_str(cat->loglevel),
527 cat->enabled ? "Enabled" : "Disabled",
528 info->cat[i].description,
529 VTY_NEWLINE);
530 }
Harald Welte6d2d4d62013-03-10 09:53:24 +0000531
532 vty_out(vty, " Log Filter 'ALL': %s%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100533 tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled",
Harald Welte6d2d4d62013-03-10 09:53:24 +0000534 VTY_NEWLINE);
535
Harald Weltefb84f322013-06-06 07:33:54 +0200536 /* print application specific filters */
537 if (info->print_fn)
538 info->print_fn(vty, info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200539}
540
541#define SHOW_LOG_STR "Show current logging configuration\n"
542
543DEFUN(show_logging_vty,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000544 show_logging_vty_cmd,
545 "show logging vty",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200546 SHOW_STR SHOW_LOG_STR
547 "Show current logging configuration for this vty\n")
548{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200549 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200550
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200551 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Weltea62648b2011-02-18 21:03:27 +0100552
553 vty_print_logtarget(vty, osmo_log_info, tgt);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200554 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200555}
556
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000557DEFUN(show_alarms,
558 show_alarms_cmd,
559 "show alarms",
560 SHOW_STR SHOW_LOG_STR
561 "Show the contents of the logging ringbuffer\n")
562{
563 int i, num_alarms;
564 struct osmo_strrb *rb;
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200565 struct log_target *tgt;
566
567 log_tgt_mutex_lock();
568 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000569 if (!tgt) {
570 vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s",
571 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200572 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000573 }
574
575 rb = tgt->tgt_rb.rb;
576 num_alarms = osmo_strrb_elements(rb);
577
578 vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE);
579
580 for (i = 0; i < num_alarms; i++)
581 vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i),
582 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200583 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000584}
585
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200586gDEFUN(cfg_description, cfg_description_cmd,
587 "description .TEXT",
Thorsten Alteholza81055d2017-03-02 22:13:48 +0100588 "Save human-readable description of the object\n"
Holger Hans Peter Freytherc9b3e062012-07-25 13:02:49 +0200589 "Text until the end of the line\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200590{
591 char **dptr = vty->index_sub;
592
593 if (!dptr) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200594 vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200595 return CMD_WARNING;
596 }
597
Holger Hans Peter Freytherff0670e2011-02-24 14:20:41 +0100598 if (*dptr)
599 talloc_free(*dptr);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200600 *dptr = argv_concat(argv, argc, 0);
Holger Hans Peter Freyther6a75d162013-07-14 09:07:11 +0200601 if (!*dptr)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200602 return CMD_WARNING;
603
604 return CMD_SUCCESS;
605}
606
607gDEFUN(cfg_no_description, cfg_no_description_cmd,
608 "no description",
609 NO_STR
610 "Remove description of the object\n")
611{
612 char **dptr = vty->index_sub;
613
614 if (!dptr) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200615 vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200616 return CMD_WARNING;
617 }
618
619 if (*dptr) {
620 talloc_free(*dptr);
621 *dptr = NULL;
622 }
623
624 return CMD_SUCCESS;
625}
626
Harald Welte28222962011-02-18 20:37:04 +0100627/* Support for configuration of log targets != the current vty */
628
629struct cmd_node cfg_log_node = {
630 CFG_LOG_NODE,
631 "%s(config-log)# ",
632 1
633};
634
Harald Welte28222962011-02-18 20:37:04 +0100635#ifdef HAVE_SYSLOG_H
636
637#include <syslog.h>
638
639static const int local_sysl_map[] = {
640 [0] = LOG_LOCAL0,
641 [1] = LOG_LOCAL1,
642 [2] = LOG_LOCAL2,
643 [3] = LOG_LOCAL3,
644 [4] = LOG_LOCAL4,
645 [5] = LOG_LOCAL5,
646 [6] = LOG_LOCAL6,
647 [7] = LOG_LOCAL7
648};
649
Harald Weltede79cee2011-02-24 23:47:57 +0100650/* From VTY core code */
651extern struct host host;
652
Harald Welte28222962011-02-18 20:37:04 +0100653static int _cfg_log_syslog(struct vty *vty, int facility)
654{
655 struct log_target *tgt;
656
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200657 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100658 /* First delete the old syslog target, if any */
659 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
660 if (tgt)
661 log_target_destroy(tgt);
662
Harald Weltede79cee2011-02-24 23:47:57 +0100663 tgt = log_target_create_syslog(host.app_info->name, 0, facility);
Harald Welte28222962011-02-18 20:37:04 +0100664 if (!tgt) {
665 vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200666 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100667 }
668 log_add_target(tgt);
669
670 vty->index = tgt;
671 vty->node = CFG_LOG_NODE;
672
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200673 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100674}
675
676DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd,
677 "log syslog local <0-7>",
678 LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n"
679 "Local facility number\n")
680{
681 int local = atoi(argv[0]);
682 int facility = local_sysl_map[local];
683
684 return _cfg_log_syslog(vty, facility);
685}
686
687static struct value_string sysl_level_names[] = {
688 { LOG_AUTHPRIV, "authpriv" },
689 { LOG_CRON, "cron" },
690 { LOG_DAEMON, "daemon" },
691 { LOG_FTP, "ftp" },
692 { LOG_LPR, "lpr" },
693 { LOG_MAIL, "mail" },
694 { LOG_NEWS, "news" },
695 { LOG_USER, "user" },
696 { LOG_UUCP, "uucp" },
697 /* only for value -> string conversion */
698 { LOG_LOCAL0, "local 0" },
699 { LOG_LOCAL1, "local 1" },
700 { LOG_LOCAL2, "local 2" },
701 { LOG_LOCAL3, "local 3" },
702 { LOG_LOCAL4, "local 4" },
703 { LOG_LOCAL5, "local 5" },
704 { LOG_LOCAL6, "local 6" },
705 { LOG_LOCAL7, "local 7" },
706 { 0, NULL }
707};
708
709DEFUN(cfg_log_syslog, cfg_log_syslog_cmd,
710 "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)",
Holger Hans Peter Freythera4463fd2011-10-03 23:17:36 +0200711 LOG_STR "Logging via syslog\n"
712 "Security/authorization messages facility\n"
713 "Clock daemon (cron/at) facility\n"
714 "General system daemon facility\n"
715 "Ftp daemon facility\n"
716 "Line printer facility\n"
717 "Mail facility\n"
718 "News facility\n"
719 "Generic facility\n"
720 "UUCP facility\n")
Harald Welte28222962011-02-18 20:37:04 +0100721{
722 int facility = get_string_value(sysl_level_names, argv[0]);
723
724 return _cfg_log_syslog(vty, facility);
725}
726
727DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd,
728 "no log syslog",
729 NO_STR LOG_STR "Logging via syslog\n")
730{
731 struct log_target *tgt;
732
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200733 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100734 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
735 if (!tgt) {
736 vty_out(vty, "%% No syslog target found%s",
737 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200738 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100739 }
740
741 log_target_destroy(tgt);
742
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200743 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100744}
745#endif /* HAVE_SYSLOG_H */
746
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +0700747DEFUN(cfg_log_systemd_journal, cfg_log_systemd_journal_cmd,
748 "log systemd-journal [raw]",
749 LOG_STR "Logging to systemd-journal\n"
750 "Offload rendering of the meta information (location, category) to systemd\n")
751{
752#ifdef ENABLE_SYSTEMD_LOGGING
753 struct log_target *tgt;
754 bool raw = argc > 0;
755
756 log_tgt_mutex_lock();
757 tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL);
758 if (tgt == NULL) {
759 tgt = log_target_create_systemd(raw);
760 if (tgt == NULL) {
761 vty_out(vty, "%% Unable to create systemd-journal "
762 "log target%s", VTY_NEWLINE);
763 RET_WITH_UNLOCK(CMD_WARNING);
764 }
765 log_add_target(tgt);
766 } else if (tgt->sd_journal.raw != raw) {
767 log_target_systemd_set_raw(tgt, raw);
768 }
769
770 vty->index = tgt;
771 vty->node = CFG_LOG_NODE;
772
773 RET_WITH_UNLOCK(CMD_SUCCESS);
774#else
775 vty_out(vty, "%% systemd-journal logging is not available "
776 "in this build of libosmocore%s", VTY_NEWLINE);
777 return CMD_WARNING;
778#endif /* ENABLE_SYSTEMD_LOGGING */
779}
780
781DEFUN(cfg_no_log_systemd_journal, cfg_no_log_systemd_journal_cmd,
782 "no log systemd-journal",
783 NO_STR LOG_STR "Logging to systemd-journal\n")
784{
785#ifdef ENABLE_SYSTEMD_LOGGING
786 struct log_target *tgt;
787
788 log_tgt_mutex_lock();
789 tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL);
790 if (!tgt) {
791 vty_out(vty, "%% No systemd-journal logging active%s", VTY_NEWLINE);
792 RET_WITH_UNLOCK(CMD_WARNING);
793 }
794
795 log_target_destroy(tgt);
796
797 RET_WITH_UNLOCK(CMD_SUCCESS);
798#else
799 vty_out(vty, "%% systemd-journal logging is not available "
800 "in this build of libosmocore%s", VTY_NEWLINE);
801 return CMD_WARNING;
802#endif /* ENABLE_SYSTEMD_LOGGING */
803}
804
Harald Welteaa00f992016-12-02 15:30:02 +0100805DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
806 "log gsmtap [HOSTNAME]",
Neels Hofmeyrfd9ec3b2016-12-11 01:48:26 +0100807 LOG_STR "Logging via GSMTAP\n"
808 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
Harald Welteaa00f992016-12-02 15:30:02 +0100809{
Max2f153b52018-01-04 12:25:57 +0100810 const char *hostname = argc ? argv[0] : "127.0.0.1";
Harald Welteaa00f992016-12-02 15:30:02 +0100811 struct log_target *tgt;
812
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200813 log_tgt_mutex_lock();
Harald Welteaa00f992016-12-02 15:30:02 +0100814 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
815 if (!tgt) {
816 tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT,
817 host.app_info->name, false,
818 true);
819 if (!tgt) {
Max2f153b52018-01-04 12:25:57 +0100820 vty_out(vty, "%% Unable to create GSMTAP log for %s%s",
821 hostname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200822 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welteaa00f992016-12-02 15:30:02 +0100823 }
824 log_add_target(tgt);
825 }
826
827 vty->index = tgt;
828 vty->node = CFG_LOG_NODE;
829
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200830 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welteaa00f992016-12-02 15:30:02 +0100831}
832
Vadim Yanitskiy2f4186a2021-12-29 21:58:19 +0600833DEFUN(cfg_no_log_gsmtap, cfg_no_log_gsmtap_cmd,
834 "no log gsmtap [HOSTNAME]",
835 NO_STR LOG_STR "Logging via GSMTAP\n"
836 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
837{
838 const char *hostname = argc ? argv[0] : "127.0.0.1";
839 struct log_target *tgt;
840
841 log_tgt_mutex_lock();
842 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
843 if (tgt == NULL) {
844 vty_out(vty, "%% Unable to find GSMTAP log target for %s%s",
845 hostname, VTY_NEWLINE);
846 RET_WITH_UNLOCK(CMD_WARNING);
847 }
848
849 log_target_destroy(tgt);
850
851 RET_WITH_UNLOCK(CMD_SUCCESS);
852}
853
Harald Welte28222962011-02-18 20:37:04 +0100854DEFUN(cfg_log_stderr, cfg_log_stderr_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200855 "log stderr [blocking-io]",
856 LOG_STR "Logging via STDERR of the process\n"
857 "Use blocking, synchronous I/O\n")
Harald Welte28222962011-02-18 20:37:04 +0100858{
859 struct log_target *tgt;
860
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200861 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100862 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
863 if (!tgt) {
864 tgt = log_target_create_stderr();
865 if (!tgt) {
866 vty_out(vty, "%% Unable to create stderr log%s",
867 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200868 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100869 }
870 log_add_target(tgt);
871 }
872
Harald Welteb72867f2020-09-26 21:45:16 +0200873 if (argc > 0 && !strcmp(argv[0], "blocking-io"))
874 log_target_file_switch_to_stream(tgt);
875 else
876 log_target_file_switch_to_wqueue(tgt);
877
Harald Welte28222962011-02-18 20:37:04 +0100878 vty->index = tgt;
879 vty->node = CFG_LOG_NODE;
880
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200881 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100882}
883
884DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd,
885 "no log stderr",
886 NO_STR LOG_STR "Logging via STDERR of the process\n")
887{
888 struct log_target *tgt;
889
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200890 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100891 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
892 if (!tgt) {
893 vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200894 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100895 }
896
897 log_target_destroy(tgt);
Harald Weltee4d9a2c2020-09-27 11:28:58 +0200898 osmo_stderr_target = NULL;
Harald Welte28222962011-02-18 20:37:04 +0100899
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200900 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100901}
902
903DEFUN(cfg_log_file, cfg_log_file_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200904 "log file FILENAME [blocking-io]",
905 LOG_STR "Logging to text file\n" "Filename\n"
906 "Use blocking, synchronous I/O\n")
Harald Welte28222962011-02-18 20:37:04 +0100907{
908 const char *fname = argv[0];
909 struct log_target *tgt;
910
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200911 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100912 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
913 if (!tgt) {
914 tgt = log_target_create_file(fname);
915 if (!tgt) {
Vadim Yanitskiyad344652021-04-05 03:05:31 +0200916 vty_out(vty, "%% Unable to create file '%s'%s",
Harald Welte28222962011-02-18 20:37:04 +0100917 fname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200918 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100919 }
920 log_add_target(tgt);
921 }
922
Harald Welteb72867f2020-09-26 21:45:16 +0200923 if (argc > 1 && !strcmp(argv[1], "blocking-io"))
924 log_target_file_switch_to_stream(tgt);
925 else
926 log_target_file_switch_to_wqueue(tgt);
927
Harald Welte28222962011-02-18 20:37:04 +0100928 vty->index = tgt;
929 vty->node = CFG_LOG_NODE;
930
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200931 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100932}
933
934
935DEFUN(cfg_no_log_file, cfg_no_log_file_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200936 "no log file FILENAME",
Harald Welte28222962011-02-18 20:37:04 +0100937 NO_STR LOG_STR "Logging to text file\n" "Filename\n")
938{
939 const char *fname = argv[0];
940 struct log_target *tgt;
941
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200942 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100943 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
944 if (!tgt) {
Vadim Yanitskiyad344652021-04-05 03:05:31 +0200945 vty_out(vty, "%% No such log file '%s'%s",
Harald Welte28222962011-02-18 20:37:04 +0100946 fname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200947 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100948 }
949
950 log_target_destroy(tgt);
951
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200952 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100953}
954
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000955DEFUN(cfg_log_alarms, cfg_log_alarms_cmd,
956 "log alarms <2-32700>",
957 LOG_STR "Logging alarms to osmo_strrb\n"
958 "Maximum number of messages to log\n")
959{
960 struct log_target *tgt;
961 unsigned int rbsize = atoi(argv[0]);
962
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200963
964 log_tgt_mutex_lock();
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000965 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
966 if (tgt)
967 log_target_destroy(tgt);
968
969 tgt = log_target_create_rb(rbsize);
970 if (!tgt) {
971 vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s",
972 rbsize, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200973 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000974 }
975 log_add_target(tgt);
976
977 vty->index = tgt;
978 vty->node = CFG_LOG_NODE;
979
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200980 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000981}
982
983DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd,
984 "no log alarms",
985 NO_STR LOG_STR "Logging alarms to osmo_strrb\n")
986{
987 struct log_target *tgt;
988
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200989 log_tgt_mutex_lock();
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000990 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
991 if (!tgt) {
992 vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200993 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000994 }
995
996 log_target_destroy(tgt);
997
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200998 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000999}
1000
Harald Welte28222962011-02-18 20:37:04 +01001001static int config_write_log_single(struct vty *vty, struct log_target *tgt)
1002{
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001003 char level_buf[128];
Harald Welte28222962011-02-18 20:37:04 +01001004 int i;
Harald Welte28222962011-02-18 20:37:04 +01001005
1006 switch (tgt->type) {
1007 case LOG_TGT_TYPE_VTY:
1008 return 1;
1009 break;
1010 case LOG_TGT_TYPE_STDERR:
Harald Welteb72867f2020-09-26 21:45:16 +02001011 if (tgt->tgt_file.wqueue)
1012 vty_out(vty, "log stderr%s", VTY_NEWLINE);
1013 else
1014 vty_out(vty, "log stderr blocking-io%s", VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001015 break;
1016 case LOG_TGT_TYPE_SYSLOG:
1017#ifdef HAVE_SYSLOG_H
1018 vty_out(vty, "log syslog %s%s",
1019 get_value_string(sysl_level_names,
1020 tgt->tgt_syslog.facility),
1021 VTY_NEWLINE);
1022#endif
1023 break;
1024 case LOG_TGT_TYPE_FILE:
Harald Welteb72867f2020-09-26 21:45:16 +02001025 if (tgt->tgt_file.wqueue)
1026 vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE);
1027 else
1028 vty_out(vty, "log file %s blocking-io%s", tgt->tgt_file.fname, VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001029 break;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001030 case LOG_TGT_TYPE_STRRB:
1031 vty_out(vty, "log alarms %zu%s",
1032 log_target_rb_avail_size(tgt), VTY_NEWLINE);
1033 break;
Harald Welteaa00f992016-12-02 15:30:02 +01001034 case LOG_TGT_TYPE_GSMTAP:
1035 vty_out(vty, "log gsmtap %s%s",
1036 tgt->tgt_gsmtap.hostname, VTY_NEWLINE);
1037 break;
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +07001038 case LOG_TGT_TYPE_SYSTEMD:
1039 vty_out(vty, "log systemd-journal%s%s",
1040 tgt->sd_journal.raw ? " raw" : "",
1041 VTY_NEWLINE);
1042 break;
Harald Welte28222962011-02-18 20:37:04 +01001043 }
1044
Harald Welte0d67f482018-09-25 20:16:14 +02001045 vty_out(vty, " logging filter all %u%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +01001046 tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE);
Harald Weltefb84f322013-06-06 07:33:54 +02001047 /* save filters outside of libosmocore, i.e. in app code */
1048 if (osmo_log_info->save_fn)
1049 osmo_log_info->save_fn(vty, osmo_log_info, tgt);
Harald Welte2da47f12012-10-22 19:31:54 +02001050
Harald Welte0d67f482018-09-25 20:16:14 +02001051 vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0,
Harald Welte28222962011-02-18 20:37:04 +01001052 VTY_NEWLINE);
Vadim Yanitskiy5c4b9852019-07-28 04:36:37 +07001053 vty_out(vty, " logging print category-hex %d%s",
1054 tgt->print_category_hex ? 1 : 0, VTY_NEWLINE);
Harald Welte0d67f482018-09-25 20:16:14 +02001055 vty_out(vty, " logging print category %d%s",
Michael McTernan78933462015-03-20 15:29:25 +01001056 tgt->print_category ? 1 : 0, VTY_NEWLINE);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001057 vty_out(vty, " logging print thread-id %d%s",
1058 tgt->print_tid ? 1 : 0, VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001059 if (tgt->print_ext_timestamp)
Harald Welte0d67f482018-09-25 20:16:14 +02001060 vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001061 else
Harald Welte0d67f482018-09-25 20:16:14 +02001062 vty_out(vty, " logging timestamp %u%s",
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001063 tgt->print_timestamp ? 1 : 0, VTY_NEWLINE);
Neels Hofmeyr886e5482018-01-16 01:49:37 +01001064 if (tgt->print_level)
Harald Welte0d67f482018-09-25 20:16:14 +02001065 vty_out(vty, " logging print level 1%s", VTY_NEWLINE);
Harald Welte8d6ca692021-01-20 17:04:23 +01001066 vty_out(vty, " logging print file %s%s%s",
Neels Hofmeyr22772cc2018-02-06 00:52:08 +01001067 get_value_string(logging_print_file_args, tgt->print_filename2),
Harald Welte8d6ca692021-01-20 17:04:23 +01001068 tgt->print_filename_pos == LOG_FILENAME_POS_LINE_END ? " last" : "",
Neels Hofmeyr22772cc2018-02-06 00:52:08 +01001069 VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001070
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001071 if (tgt->loglevel) {
1072 const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001073 if (!level_str) {
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001074 vty_out(vty, "%% Invalid log level %u for 'force-all'%s",
1075 tgt->loglevel, VTY_NEWLINE);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001076 } else {
1077 osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str);
1078 vty_out(vty, " logging level force-all %s%s", level_buf, VTY_NEWLINE);
1079 }
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001080 }
Harald Welte28222962011-02-18 20:37:04 +01001081
1082 for (i = 0; i < osmo_log_info->num_cat; i++) {
1083 const struct log_category *cat = &tgt->categories[i];
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001084 char cat_name[128];
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001085 const char *level_str;
Harald Welte28222962011-02-18 20:37:04 +01001086
Harald Welte1a02cfc2013-03-19 10:37:39 +01001087 /* skip empty entries in the array */
1088 if (!osmo_log_info->cat[i].name)
1089 continue;
1090
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001091 osmo_str_tolower_buf(cat_name, sizeof(cat_name), osmo_log_info->cat[i].name + 1);
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001092
1093 level_str = get_value_string_or_null(loglevel_strs, cat->loglevel);
1094 if (!level_str) {
1095 vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
1096 VTY_NEWLINE);
1097 continue;
1098 }
1099
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001100 osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str);
Harald Welte0d67f482018-09-25 20:16:14 +02001101 vty_out(vty, " logging level %s", cat_name);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001102 vty_out(vty, " %s%s", level_buf, VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001103 }
1104
Harald Welte28222962011-02-18 20:37:04 +01001105 return 1;
1106}
1107
1108static int config_write_log(struct vty *vty)
1109{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001110 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +01001111 struct log_target *dbg = vty->index;
1112
1113 llist_for_each_entry(dbg, &osmo_log_target_list, entry)
1114 config_write_log_single(vty, dbg);
1115
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001116 log_tgt_mutex_unlock();
Harald Welte28222962011-02-18 20:37:04 +01001117 return 1;
1118}
1119
Harald Welte11eb4b52018-06-09 17:41:31 +02001120static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[])
1121{
1122 vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE);
Vadim Yanitskiy4abda9e2019-11-21 00:19:36 +07001123 return CMD_SUCCESS; /* Otherwise the process would terminate */
Harald Welte11eb4b52018-06-09 17:41:31 +02001124}
1125
1126void logging_vty_add_deprecated_subsys(void *ctx, const char *name)
1127{
1128 struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element);
1129 OSMO_ASSERT(cmd);
Vadim Yanitskiy75c242e2019-11-21 00:06:53 +07001130 cmd->string = talloc_asprintf(cmd, "logging level %s " LOG_LEVEL_ARGS, name);
Harald Welte11eb4b52018-06-09 17:41:31 +02001131 cmd->func = log_deprecated_func;
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001132 cmd->doc = LEVEL_STR
Harald Welte11eb4b52018-06-09 17:41:31 +02001133 "Deprecated Category\n";
1134 cmd->attr = CMD_ATTR_DEPRECATED;
1135
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001136 install_lib_element(CFG_LOG_NODE, cmd);
Harald Welte11eb4b52018-06-09 17:41:31 +02001137}
1138
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001139/* logp (<categories>) (debug|...|fatal) .LOGMESSAGE*/
1140DEFUN(vty_logp,
1141 vty_logp_cmd,
1142 NULL, /* cmdstr is dynamically set in gen_vty_logp_cmd_strs(). */
1143 NULL) /* same thing for helpstr. */
1144{
1145 int category = log_parse_category(argv[0]);
1146 int level = log_parse_level(argv[1]);
1147 char *str = argv_concat(argv, argc, 2);
Vadim Yanitskiy4b46b7e2021-04-05 03:45:15 +02001148
1149 if (level < 0) {
1150 vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE);
1151 return CMD_WARNING;
1152 }
1153
1154 if (category < 0) {
1155 vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE);
1156 return CMD_WARNING;
1157 }
1158
1159 /* Properly handle library specific sub-systems */
1160 if ((unsigned int) category >= osmo_log_info->num_cat_user) {
1161 category -= osmo_log_info->num_cat_user - 1;
1162 category *= -1;
1163 }
1164
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001165 LOGP(category, level, "%s\n", str);
1166 return CMD_SUCCESS;
1167}
1168
1169static void gen_vty_logp_cmd_strs(struct cmd_element *cmd)
1170{
1171 char *cmd_str = NULL;
1172 char *doc_str = NULL;
1173
1174 assert_loginfo(__func__);
1175
1176 OSMO_ASSERT(cmd->string == NULL);
1177 OSMO_ASSERT(cmd->doc == NULL);
1178
1179 osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logp (");
1180 osmo_talloc_asprintf(tall_log_ctx, doc_str,
1181 "Print a message on all log outputs; useful for placing markers in test logs\n");
1182 add_category_strings(&cmd_str, &doc_str, osmo_log_info);
1183 osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", LOG_LEVEL_ARGS);
1184 osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", LOG_LEVEL_STRS);
1185
1186 osmo_talloc_asprintf(tall_log_ctx, cmd_str, " .LOGMESSAGE");
1187 osmo_talloc_asprintf(tall_log_ctx, doc_str,
1188 "Arbitrary message to log on given category and log level\n");
1189
Harald Weltebebec212020-07-15 12:21:29 +02001190 talloc_set_name_const(cmd_str, "vty_logp_cmd_str");
1191 talloc_set_name_const(doc_str, "vty_logp_doc_str");
1192
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001193 cmd->string = cmd_str;
1194 cmd->doc = doc_str;
1195}
1196
Harald Welte8c648252017-10-16 15:17:03 +02001197/*! Register logging related commands to the VTY. Call this once from
1198 * your application if you want to support those commands. */
Harald Weltee61d4592022-11-03 11:05:58 +01001199void logging_vty_add_cmds(void)
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001200{
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001201 install_lib_element_ve(&enable_logging_cmd);
1202 install_lib_element_ve(&disable_logging_cmd);
1203 install_lib_element_ve(&logging_fltr_all_cmd);
1204 install_lib_element_ve(&logging_use_clr_cmd);
1205 install_lib_element_ve(&logging_prnt_timestamp_cmd);
1206 install_lib_element_ve(&logging_prnt_ext_timestamp_cmd);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001207 install_lib_element_ve(&logging_prnt_tid_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001208 install_lib_element_ve(&logging_prnt_cat_cmd);
1209 install_lib_element_ve(&logging_prnt_cat_hex_cmd);
1210 install_lib_element_ve(&logging_prnt_level_cmd);
1211 install_lib_element_ve(&logging_prnt_file_cmd);
1212 install_lib_element_ve(&logging_set_category_mask_cmd);
1213 install_lib_element_ve(&logging_set_category_mask_old_cmd);
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +01001214
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001215 /* logging level (<categories>) (debug|...|fatal) */
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001216 gen_logging_level_cmd_strs(&logging_level_cmd,
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001217 LOG_LEVEL_ARGS,
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001218 LOG_LEVEL_STRS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001219 /* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001220 gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd,
1221 "everything", EVERYTHING_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001222
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001223 install_lib_element_ve(&logging_level_cmd);
1224 install_lib_element_ve(&logging_level_set_all_cmd);
1225 install_lib_element_ve(&logging_level_force_all_cmd);
1226 install_lib_element_ve(&no_logging_level_force_all_cmd);
1227 install_lib_element_ve(&deprecated_logging_level_everything_cmd);
1228 install_lib_element_ve(&deprecated_logging_level_all_cmd);
1229 install_lib_element_ve(&deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001230
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001231 gen_vty_logp_cmd_strs(&vty_logp_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001232 install_lib_element_ve(&vty_logp_cmd);
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001233
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001234 install_lib_element_ve(&show_logging_vty_cmd);
1235 install_lib_element_ve(&show_alarms_cmd);
Pau Espin Pedrol0c2a46d2019-08-20 10:39:05 +02001236
Harald Welte28222962011-02-18 20:37:04 +01001237 install_node(&cfg_log_node, config_write_log);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001238 install_lib_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
1239 install_lib_element(CFG_LOG_NODE, &logging_use_clr_cmd);
1240 install_lib_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
1241 install_lib_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001242 install_lib_element(CFG_LOG_NODE, &logging_prnt_tid_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001243 install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);
1244 install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd);
1245 install_lib_element(CFG_LOG_NODE, &logging_prnt_level_cmd);
1246 install_lib_element(CFG_LOG_NODE, &logging_prnt_file_cmd);
1247 install_lib_element(CFG_LOG_NODE, &logging_level_cmd);
1248 install_lib_element(CFG_LOG_NODE, &logging_level_set_all_cmd);
1249 install_lib_element(CFG_LOG_NODE, &logging_level_force_all_cmd);
1250 install_lib_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd);
1251 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd);
1252 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd);
1253 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001254
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001255 install_lib_element(CONFIG_NODE, &cfg_log_stderr_cmd);
1256 install_lib_element(CONFIG_NODE, &cfg_no_log_stderr_cmd);
1257 install_lib_element(CONFIG_NODE, &cfg_log_file_cmd);
1258 install_lib_element(CONFIG_NODE, &cfg_no_log_file_cmd);
1259 install_lib_element(CONFIG_NODE, &cfg_log_alarms_cmd);
1260 install_lib_element(CONFIG_NODE, &cfg_no_log_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001261#ifdef HAVE_SYSLOG_H
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001262 install_lib_element(CONFIG_NODE, &cfg_log_syslog_cmd);
1263 install_lib_element(CONFIG_NODE, &cfg_log_syslog_local_cmd);
1264 install_lib_element(CONFIG_NODE, &cfg_no_log_syslog_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001265#endif
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +07001266 install_lib_element(CONFIG_NODE, &cfg_log_systemd_journal_cmd);
1267 install_lib_element(CONFIG_NODE, &cfg_no_log_systemd_journal_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001268 install_lib_element(CONFIG_NODE, &cfg_log_gsmtap_cmd);
Vadim Yanitskiy2f4186a2021-12-29 21:58:19 +06001269 install_lib_element(CONFIG_NODE, &cfg_no_log_gsmtap_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001270}