blob: 678ae68646459f3e7ebad21f64071b076dd70ed8 [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
Hoernchen43018ec2024-01-11 16:51:46 +0000385#if !defined(EMBEDDED)
386 log_cache_update(category, 1, level);
387#endif
388
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200389 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200390}
391
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200392DEFUN(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 Pedrold12f6982019-09-17 18:38:58 +0200399 struct log_target *tgt;
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200400 int level = log_parse_level(argv[0]);
401 int i;
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200402
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200403 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200404
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200405 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;
Hoernchen43018ec2024-01-11 16:51:46 +0000413#if !defined(EMBEDDED)
414 log_cache_update(i, 1, level);
415#endif
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200416 }
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200417 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200418}
419
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200420/* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200421DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd,
422 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
423 NULL) /* same thing for helpstr. */
424{
425 vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE);
426 return CMD_SUCCESS;
427}
428
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200429DEFUN(logging_level_force_all, logging_level_force_all_cmd,
430 "logging level force-all " LOG_LEVEL_ARGS,
431 LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS)
432{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200433 struct log_target *tgt;
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200434 int level = log_parse_level(argv[0]);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200435
436 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
437
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200438 log_set_log_level(tgt, level);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200439 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200440}
441
442DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd,
443 "no logging level force-all",
444 NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)
445{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200446 struct log_target *tgt;
447
448 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
449
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200450 log_set_log_level(tgt, 0);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200451 RET_WITH_UNLOCK(CMD_SUCCESS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200452}
453
454/* 'logging level all (debug|...|fatal)' */
455ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd,
456 "logging level all " LOG_LEVEL_ARGS,
457 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS);
458
459/* 'logging level all everything' */
460ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd,
461 "logging level all everything",
462 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR);
463
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200464DEFUN(logging_set_category_mask,
465 logging_set_category_mask_cmd,
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200466 "logging set-log-mask MASK",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200467 LOGGING_STR
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200468 "Set the logmask of this logging target\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100469 "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific"
470 " application, refer to the 'logging level' command. Optionally add individual log levels like"
471 " 'abc,1:mno,3:xyz,5', where the level numbers are"
472 " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG)
473 " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO)
474 " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE)
475 " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR)
476 " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL)
477 "\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200478{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200479 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200480
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200481 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200482
Harald Weltea62648b2011-02-18 21:03:27 +0100483 log_parse_category_mask(tgt, argv[0]);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200484 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200485}
486
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200487ALIAS_DEPRECATED(logging_set_category_mask,
488 logging_set_category_mask_old_cmd,
489 "logging set log mask MASK",
490 LOGGING_STR
491 "Decide which categories to output.\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100492 "Log commands\n" "Mask commands\n"
493 "'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 +0200494
495
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200496DEFUN(diable_logging,
497 disable_logging_cmd,
498 "logging disable",
499 LOGGING_STR
500 "Disables logging to this vty\n")
501{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200502 struct log_target *tgt;
Harald Weltea62648b2011-02-18 21:03:27 +0100503 struct telnet_connection *conn = (struct telnet_connection *) vty->priv;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200504
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200505 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200506
Harald Weltea62648b2011-02-18 21:03:27 +0100507 log_del_target(tgt);
508 talloc_free(tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200509 conn->dbg = NULL;
Harald Weltea62648b2011-02-18 21:03:27 +0100510
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200511 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200512}
513
514static void vty_print_logtarget(struct vty *vty, const struct log_info *info,
515 const struct log_target *tgt)
516{
517 unsigned int i;
518
519 vty_out(vty, " Global Loglevel: %s%s",
520 log_level_str(tgt->loglevel), VTY_NEWLINE);
521 vty_out(vty, " Use color: %s, Print Timestamp: %s%s",
522 tgt->use_color ? "On" : "Off",
523 tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE);
524
525 vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE);
526
527 for (i = 0; i < info->num_cat; i++) {
528 const struct log_category *cat = &tgt->categories[i];
Daniel Willmann55363a92016-11-15 10:05:51 +0100529 /* Skip categories that were not initialized */
530 if (!info->cat[i].name)
531 continue;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200532 vty_out(vty, " %-10s %-10s %-8s %s%s",
533 info->cat[i].name+1, log_level_str(cat->loglevel),
534 cat->enabled ? "Enabled" : "Disabled",
535 info->cat[i].description,
536 VTY_NEWLINE);
537 }
Harald Welte6d2d4d62013-03-10 09:53:24 +0000538
539 vty_out(vty, " Log Filter 'ALL': %s%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100540 tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled",
Harald Welte6d2d4d62013-03-10 09:53:24 +0000541 VTY_NEWLINE);
542
Harald Weltefb84f322013-06-06 07:33:54 +0200543 /* print application specific filters */
544 if (info->print_fn)
545 info->print_fn(vty, info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200546}
547
548#define SHOW_LOG_STR "Show current logging configuration\n"
549
550DEFUN(show_logging_vty,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000551 show_logging_vty_cmd,
552 "show logging vty",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200553 SHOW_STR SHOW_LOG_STR
554 "Show current logging configuration for this vty\n")
555{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200556 struct log_target *tgt;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200557
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200558 ACQUIRE_VTY_LOG_TGT_WITH_LOCK(vty, tgt);
Harald Weltea62648b2011-02-18 21:03:27 +0100559
560 vty_print_logtarget(vty, osmo_log_info, tgt);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200561 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200562}
563
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000564DEFUN(show_alarms,
565 show_alarms_cmd,
566 "show alarms",
567 SHOW_STR SHOW_LOG_STR
568 "Show the contents of the logging ringbuffer\n")
569{
570 int i, num_alarms;
571 struct osmo_strrb *rb;
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200572 struct log_target *tgt;
573
574 log_tgt_mutex_lock();
575 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000576 if (!tgt) {
577 vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s",
578 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200579 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000580 }
581
582 rb = tgt->tgt_rb.rb;
583 num_alarms = osmo_strrb_elements(rb);
584
585 vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE);
586
587 for (i = 0; i < num_alarms; i++)
588 vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i),
589 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200590 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000591}
592
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200593gDEFUN(cfg_description, cfg_description_cmd,
594 "description .TEXT",
Thorsten Alteholza81055d2017-03-02 22:13:48 +0100595 "Save human-readable description of the object\n"
Holger Hans Peter Freytherc9b3e062012-07-25 13:02:49 +0200596 "Text until the end of the line\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200597{
598 char **dptr = vty->index_sub;
599
600 if (!dptr) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200601 vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200602 return CMD_WARNING;
603 }
604
Holger Hans Peter Freytherff0670e2011-02-24 14:20:41 +0100605 if (*dptr)
606 talloc_free(*dptr);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200607 *dptr = argv_concat(argv, argc, 0);
Holger Hans Peter Freyther6a75d162013-07-14 09:07:11 +0200608 if (!*dptr)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200609 return CMD_WARNING;
610
611 return CMD_SUCCESS;
612}
613
614gDEFUN(cfg_no_description, cfg_no_description_cmd,
615 "no description",
616 NO_STR
617 "Remove description of the object\n")
618{
619 char **dptr = vty->index_sub;
620
621 if (!dptr) {
Vadim Yanitskiy2d1a9fa2021-04-05 03:08:26 +0200622 vty_out(vty, "%% vty->index_sub == NULL%s", VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200623 return CMD_WARNING;
624 }
625
626 if (*dptr) {
627 talloc_free(*dptr);
628 *dptr = NULL;
629 }
630
631 return CMD_SUCCESS;
632}
633
Harald Welte28222962011-02-18 20:37:04 +0100634/* Support for configuration of log targets != the current vty */
635
636struct cmd_node cfg_log_node = {
637 CFG_LOG_NODE,
638 "%s(config-log)# ",
639 1
640};
641
Harald Welte28222962011-02-18 20:37:04 +0100642#ifdef HAVE_SYSLOG_H
643
644#include <syslog.h>
645
646static const int local_sysl_map[] = {
647 [0] = LOG_LOCAL0,
648 [1] = LOG_LOCAL1,
649 [2] = LOG_LOCAL2,
650 [3] = LOG_LOCAL3,
651 [4] = LOG_LOCAL4,
652 [5] = LOG_LOCAL5,
653 [6] = LOG_LOCAL6,
654 [7] = LOG_LOCAL7
655};
656
Harald Weltede79cee2011-02-24 23:47:57 +0100657/* From VTY core code */
658extern struct host host;
659
Harald Welte28222962011-02-18 20:37:04 +0100660static int _cfg_log_syslog(struct vty *vty, int facility)
661{
662 struct log_target *tgt;
663
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200664 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100665 /* First delete the old syslog target, if any */
666 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
667 if (tgt)
668 log_target_destroy(tgt);
669
Harald Weltede79cee2011-02-24 23:47:57 +0100670 tgt = log_target_create_syslog(host.app_info->name, 0, facility);
Harald Welte28222962011-02-18 20:37:04 +0100671 if (!tgt) {
672 vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200673 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100674 }
675 log_add_target(tgt);
676
677 vty->index = tgt;
678 vty->node = CFG_LOG_NODE;
679
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200680 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100681}
682
683DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd,
684 "log syslog local <0-7>",
685 LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n"
686 "Local facility number\n")
687{
688 int local = atoi(argv[0]);
689 int facility = local_sysl_map[local];
690
691 return _cfg_log_syslog(vty, facility);
692}
693
694static struct value_string sysl_level_names[] = {
695 { LOG_AUTHPRIV, "authpriv" },
696 { LOG_CRON, "cron" },
697 { LOG_DAEMON, "daemon" },
698 { LOG_FTP, "ftp" },
699 { LOG_LPR, "lpr" },
700 { LOG_MAIL, "mail" },
701 { LOG_NEWS, "news" },
702 { LOG_USER, "user" },
703 { LOG_UUCP, "uucp" },
704 /* only for value -> string conversion */
705 { LOG_LOCAL0, "local 0" },
706 { LOG_LOCAL1, "local 1" },
707 { LOG_LOCAL2, "local 2" },
708 { LOG_LOCAL3, "local 3" },
709 { LOG_LOCAL4, "local 4" },
710 { LOG_LOCAL5, "local 5" },
711 { LOG_LOCAL6, "local 6" },
712 { LOG_LOCAL7, "local 7" },
713 { 0, NULL }
714};
715
716DEFUN(cfg_log_syslog, cfg_log_syslog_cmd,
717 "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)",
Holger Hans Peter Freythera4463fd2011-10-03 23:17:36 +0200718 LOG_STR "Logging via syslog\n"
719 "Security/authorization messages facility\n"
720 "Clock daemon (cron/at) facility\n"
721 "General system daemon facility\n"
722 "Ftp daemon facility\n"
723 "Line printer facility\n"
724 "Mail facility\n"
725 "News facility\n"
726 "Generic facility\n"
727 "UUCP facility\n")
Harald Welte28222962011-02-18 20:37:04 +0100728{
729 int facility = get_string_value(sysl_level_names, argv[0]);
730
731 return _cfg_log_syslog(vty, facility);
732}
733
734DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd,
735 "no log syslog",
736 NO_STR LOG_STR "Logging via syslog\n")
737{
738 struct log_target *tgt;
739
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200740 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100741 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
742 if (!tgt) {
743 vty_out(vty, "%% No syslog target found%s",
744 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200745 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100746 }
747
748 log_target_destroy(tgt);
749
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200750 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100751}
752#endif /* HAVE_SYSLOG_H */
753
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +0700754DEFUN(cfg_log_systemd_journal, cfg_log_systemd_journal_cmd,
755 "log systemd-journal [raw]",
756 LOG_STR "Logging to systemd-journal\n"
757 "Offload rendering of the meta information (location, category) to systemd\n")
758{
759#ifdef ENABLE_SYSTEMD_LOGGING
760 struct log_target *tgt;
761 bool raw = argc > 0;
762
763 log_tgt_mutex_lock();
764 tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL);
765 if (tgt == NULL) {
766 tgt = log_target_create_systemd(raw);
767 if (tgt == NULL) {
768 vty_out(vty, "%% Unable to create systemd-journal "
769 "log target%s", VTY_NEWLINE);
770 RET_WITH_UNLOCK(CMD_WARNING);
771 }
772 log_add_target(tgt);
773 } else if (tgt->sd_journal.raw != raw) {
774 log_target_systemd_set_raw(tgt, raw);
775 }
776
777 vty->index = tgt;
778 vty->node = CFG_LOG_NODE;
779
780 RET_WITH_UNLOCK(CMD_SUCCESS);
781#else
782 vty_out(vty, "%% systemd-journal logging is not available "
783 "in this build of libosmocore%s", VTY_NEWLINE);
784 return CMD_WARNING;
785#endif /* ENABLE_SYSTEMD_LOGGING */
786}
787
788DEFUN(cfg_no_log_systemd_journal, cfg_no_log_systemd_journal_cmd,
789 "no log systemd-journal",
790 NO_STR LOG_STR "Logging to systemd-journal\n")
791{
792#ifdef ENABLE_SYSTEMD_LOGGING
793 struct log_target *tgt;
794
795 log_tgt_mutex_lock();
796 tgt = log_target_find(LOG_TGT_TYPE_SYSTEMD, NULL);
797 if (!tgt) {
798 vty_out(vty, "%% No systemd-journal logging active%s", VTY_NEWLINE);
799 RET_WITH_UNLOCK(CMD_WARNING);
800 }
801
802 log_target_destroy(tgt);
803
804 RET_WITH_UNLOCK(CMD_SUCCESS);
805#else
806 vty_out(vty, "%% systemd-journal logging is not available "
807 "in this build of libosmocore%s", VTY_NEWLINE);
808 return CMD_WARNING;
809#endif /* ENABLE_SYSTEMD_LOGGING */
810}
811
Harald Welteaa00f992016-12-02 15:30:02 +0100812DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
813 "log gsmtap [HOSTNAME]",
Neels Hofmeyrfd9ec3b2016-12-11 01:48:26 +0100814 LOG_STR "Logging via GSMTAP\n"
815 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
Harald Welteaa00f992016-12-02 15:30:02 +0100816{
Max2f153b52018-01-04 12:25:57 +0100817 const char *hostname = argc ? argv[0] : "127.0.0.1";
Harald Welteaa00f992016-12-02 15:30:02 +0100818 struct log_target *tgt;
819
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200820 log_tgt_mutex_lock();
Harald Welteaa00f992016-12-02 15:30:02 +0100821 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
822 if (!tgt) {
823 tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT,
824 host.app_info->name, false,
825 true);
826 if (!tgt) {
Max2f153b52018-01-04 12:25:57 +0100827 vty_out(vty, "%% Unable to create GSMTAP log for %s%s",
828 hostname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200829 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welteaa00f992016-12-02 15:30:02 +0100830 }
831 log_add_target(tgt);
832 }
833
834 vty->index = tgt;
835 vty->node = CFG_LOG_NODE;
836
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200837 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welteaa00f992016-12-02 15:30:02 +0100838}
839
Vadim Yanitskiy2f4186a2021-12-29 21:58:19 +0600840DEFUN(cfg_no_log_gsmtap, cfg_no_log_gsmtap_cmd,
841 "no log gsmtap [HOSTNAME]",
842 NO_STR LOG_STR "Logging via GSMTAP\n"
843 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
844{
845 const char *hostname = argc ? argv[0] : "127.0.0.1";
846 struct log_target *tgt;
847
848 log_tgt_mutex_lock();
849 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
850 if (tgt == NULL) {
851 vty_out(vty, "%% Unable to find GSMTAP log target for %s%s",
852 hostname, VTY_NEWLINE);
853 RET_WITH_UNLOCK(CMD_WARNING);
854 }
855
856 log_target_destroy(tgt);
857
858 RET_WITH_UNLOCK(CMD_SUCCESS);
859}
860
Harald Welte28222962011-02-18 20:37:04 +0100861DEFUN(cfg_log_stderr, cfg_log_stderr_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200862 "log stderr [blocking-io]",
863 LOG_STR "Logging via STDERR of the process\n"
864 "Use blocking, synchronous I/O\n")
Harald Welte28222962011-02-18 20:37:04 +0100865{
866 struct log_target *tgt;
867
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200868 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100869 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
870 if (!tgt) {
871 tgt = log_target_create_stderr();
872 if (!tgt) {
873 vty_out(vty, "%% Unable to create stderr log%s",
874 VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200875 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100876 }
877 log_add_target(tgt);
878 }
879
Harald Welteb72867f2020-09-26 21:45:16 +0200880 if (argc > 0 && !strcmp(argv[0], "blocking-io"))
881 log_target_file_switch_to_stream(tgt);
882 else
883 log_target_file_switch_to_wqueue(tgt);
884
Harald Welte28222962011-02-18 20:37:04 +0100885 vty->index = tgt;
886 vty->node = CFG_LOG_NODE;
887
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200888 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100889}
890
891DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd,
892 "no log stderr",
893 NO_STR LOG_STR "Logging via STDERR of the process\n")
894{
895 struct log_target *tgt;
896
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200897 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100898 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
899 if (!tgt) {
900 vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200901 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100902 }
903
904 log_target_destroy(tgt);
Harald Weltee4d9a2c2020-09-27 11:28:58 +0200905 osmo_stderr_target = NULL;
Harald Welte28222962011-02-18 20:37:04 +0100906
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200907 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100908}
909
910DEFUN(cfg_log_file, cfg_log_file_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200911 "log file FILENAME [blocking-io]",
912 LOG_STR "Logging to text file\n" "Filename\n"
913 "Use blocking, synchronous I/O\n")
Harald Welte28222962011-02-18 20:37:04 +0100914{
915 const char *fname = argv[0];
916 struct log_target *tgt;
917
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200918 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100919 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
920 if (!tgt) {
921 tgt = log_target_create_file(fname);
922 if (!tgt) {
Vadim Yanitskiyad344652021-04-05 03:05:31 +0200923 vty_out(vty, "%% Unable to create file '%s'%s",
Harald Welte28222962011-02-18 20:37:04 +0100924 fname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200925 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100926 }
927 log_add_target(tgt);
928 }
929
Harald Welteb72867f2020-09-26 21:45:16 +0200930 if (argc > 1 && !strcmp(argv[1], "blocking-io"))
931 log_target_file_switch_to_stream(tgt);
932 else
933 log_target_file_switch_to_wqueue(tgt);
934
Harald Welte28222962011-02-18 20:37:04 +0100935 vty->index = tgt;
936 vty->node = CFG_LOG_NODE;
937
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200938 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100939}
940
941
942DEFUN(cfg_no_log_file, cfg_no_log_file_cmd,
Harald Welteb72867f2020-09-26 21:45:16 +0200943 "no log file FILENAME",
Harald Welte28222962011-02-18 20:37:04 +0100944 NO_STR LOG_STR "Logging to text file\n" "Filename\n")
945{
946 const char *fname = argv[0];
947 struct log_target *tgt;
948
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200949 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +0100950 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
951 if (!tgt) {
Vadim Yanitskiyad344652021-04-05 03:05:31 +0200952 vty_out(vty, "%% No such log file '%s'%s",
Harald Welte28222962011-02-18 20:37:04 +0100953 fname, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200954 RET_WITH_UNLOCK(CMD_WARNING);
Harald Welte28222962011-02-18 20:37:04 +0100955 }
956
957 log_target_destroy(tgt);
958
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200959 RET_WITH_UNLOCK(CMD_SUCCESS);
Harald Welte28222962011-02-18 20:37:04 +0100960}
961
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000962DEFUN(cfg_log_alarms, cfg_log_alarms_cmd,
963 "log alarms <2-32700>",
964 LOG_STR "Logging alarms to osmo_strrb\n"
965 "Maximum number of messages to log\n")
966{
967 struct log_target *tgt;
968 unsigned int rbsize = atoi(argv[0]);
969
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200970
971 log_tgt_mutex_lock();
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000972 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
973 if (tgt)
974 log_target_destroy(tgt);
975
976 tgt = log_target_create_rb(rbsize);
977 if (!tgt) {
978 vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s",
979 rbsize, VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200980 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000981 }
982 log_add_target(tgt);
983
984 vty->index = tgt;
985 vty->node = CFG_LOG_NODE;
986
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200987 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000988}
989
990DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd,
991 "no log alarms",
992 NO_STR LOG_STR "Logging alarms to osmo_strrb\n")
993{
994 struct log_target *tgt;
995
Pau Espin Pedrold12f6982019-09-17 18:38:58 +0200996 log_tgt_mutex_lock();
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000997 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
998 if (!tgt) {
999 vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE);
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001000 RET_WITH_UNLOCK(CMD_WARNING);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001001 }
1002
1003 log_target_destroy(tgt);
1004
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001005 RET_WITH_UNLOCK(CMD_SUCCESS);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001006}
1007
Harald Welte28222962011-02-18 20:37:04 +01001008static int config_write_log_single(struct vty *vty, struct log_target *tgt)
1009{
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001010 char level_buf[128];
Harald Welte28222962011-02-18 20:37:04 +01001011 int i;
Harald Welte28222962011-02-18 20:37:04 +01001012
1013 switch (tgt->type) {
1014 case LOG_TGT_TYPE_VTY:
1015 return 1;
1016 break;
1017 case LOG_TGT_TYPE_STDERR:
Harald Welteb72867f2020-09-26 21:45:16 +02001018 if (tgt->tgt_file.wqueue)
1019 vty_out(vty, "log stderr%s", VTY_NEWLINE);
1020 else
1021 vty_out(vty, "log stderr blocking-io%s", VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001022 break;
1023 case LOG_TGT_TYPE_SYSLOG:
1024#ifdef HAVE_SYSLOG_H
1025 vty_out(vty, "log syslog %s%s",
1026 get_value_string(sysl_level_names,
1027 tgt->tgt_syslog.facility),
1028 VTY_NEWLINE);
1029#endif
1030 break;
1031 case LOG_TGT_TYPE_FILE:
Harald Welteb72867f2020-09-26 21:45:16 +02001032 if (tgt->tgt_file.wqueue)
1033 vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE);
1034 else
1035 vty_out(vty, "log file %s blocking-io%s", tgt->tgt_file.fname, VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001036 break;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001037 case LOG_TGT_TYPE_STRRB:
1038 vty_out(vty, "log alarms %zu%s",
1039 log_target_rb_avail_size(tgt), VTY_NEWLINE);
1040 break;
Harald Welteaa00f992016-12-02 15:30:02 +01001041 case LOG_TGT_TYPE_GSMTAP:
1042 vty_out(vty, "log gsmtap %s%s",
1043 tgt->tgt_gsmtap.hostname, VTY_NEWLINE);
1044 break;
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +07001045 case LOG_TGT_TYPE_SYSTEMD:
1046 vty_out(vty, "log systemd-journal%s%s",
1047 tgt->sd_journal.raw ? " raw" : "",
1048 VTY_NEWLINE);
1049 break;
Harald Welte28222962011-02-18 20:37:04 +01001050 }
1051
Harald Welte0d67f482018-09-25 20:16:14 +02001052 vty_out(vty, " logging filter all %u%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +01001053 tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE);
Harald Weltefb84f322013-06-06 07:33:54 +02001054 /* save filters outside of libosmocore, i.e. in app code */
1055 if (osmo_log_info->save_fn)
1056 osmo_log_info->save_fn(vty, osmo_log_info, tgt);
Harald Welte2da47f12012-10-22 19:31:54 +02001057
Harald Welte0d67f482018-09-25 20:16:14 +02001058 vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0,
Harald Welte28222962011-02-18 20:37:04 +01001059 VTY_NEWLINE);
Vadim Yanitskiy5c4b9852019-07-28 04:36:37 +07001060 vty_out(vty, " logging print category-hex %d%s",
1061 tgt->print_category_hex ? 1 : 0, VTY_NEWLINE);
Harald Welte0d67f482018-09-25 20:16:14 +02001062 vty_out(vty, " logging print category %d%s",
Michael McTernan78933462015-03-20 15:29:25 +01001063 tgt->print_category ? 1 : 0, VTY_NEWLINE);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001064 vty_out(vty, " logging print thread-id %d%s",
1065 tgt->print_tid ? 1 : 0, VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001066 if (tgt->print_ext_timestamp)
Harald Welte0d67f482018-09-25 20:16:14 +02001067 vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001068 else
Harald Welte0d67f482018-09-25 20:16:14 +02001069 vty_out(vty, " logging timestamp %u%s",
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001070 tgt->print_timestamp ? 1 : 0, VTY_NEWLINE);
Neels Hofmeyr886e5482018-01-16 01:49:37 +01001071 if (tgt->print_level)
Harald Welte0d67f482018-09-25 20:16:14 +02001072 vty_out(vty, " logging print level 1%s", VTY_NEWLINE);
Harald Welte8d6ca692021-01-20 17:04:23 +01001073 vty_out(vty, " logging print file %s%s%s",
Neels Hofmeyr22772cc2018-02-06 00:52:08 +01001074 get_value_string(logging_print_file_args, tgt->print_filename2),
Harald Welte8d6ca692021-01-20 17:04:23 +01001075 tgt->print_filename_pos == LOG_FILENAME_POS_LINE_END ? " last" : "",
Neels Hofmeyr22772cc2018-02-06 00:52:08 +01001076 VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001077
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001078 if (tgt->loglevel) {
1079 const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001080 if (!level_str) {
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001081 vty_out(vty, "%% Invalid log level %u for 'force-all'%s",
1082 tgt->loglevel, VTY_NEWLINE);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001083 } else {
1084 osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str);
1085 vty_out(vty, " logging level force-all %s%s", level_buf, VTY_NEWLINE);
1086 }
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001087 }
Harald Welte28222962011-02-18 20:37:04 +01001088
1089 for (i = 0; i < osmo_log_info->num_cat; i++) {
1090 const struct log_category *cat = &tgt->categories[i];
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001091 char cat_name[128];
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001092 const char *level_str;
Harald Welte28222962011-02-18 20:37:04 +01001093
Harald Welte1a02cfc2013-03-19 10:37:39 +01001094 /* skip empty entries in the array */
1095 if (!osmo_log_info->cat[i].name)
1096 continue;
1097
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001098 osmo_str_tolower_buf(cat_name, sizeof(cat_name), osmo_log_info->cat[i].name + 1);
Neels Hofmeyr098038a2018-09-11 23:49:13 +02001099
1100 level_str = get_value_string_or_null(loglevel_strs, cat->loglevel);
1101 if (!level_str) {
1102 vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
1103 VTY_NEWLINE);
1104 continue;
1105 }
1106
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001107 osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str);
Harald Welte0d67f482018-09-25 20:16:14 +02001108 vty_out(vty, " logging level %s", cat_name);
Pau Espin Pedrolc21ba152019-08-02 20:32:34 +02001109 vty_out(vty, " %s%s", level_buf, VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +01001110 }
1111
Harald Welte28222962011-02-18 20:37:04 +01001112 return 1;
1113}
1114
1115static int config_write_log(struct vty *vty)
1116{
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001117 log_tgt_mutex_lock();
Harald Welte28222962011-02-18 20:37:04 +01001118 struct log_target *dbg = vty->index;
1119
1120 llist_for_each_entry(dbg, &osmo_log_target_list, entry)
1121 config_write_log_single(vty, dbg);
1122
Pau Espin Pedrold12f6982019-09-17 18:38:58 +02001123 log_tgt_mutex_unlock();
Harald Welte28222962011-02-18 20:37:04 +01001124 return 1;
1125}
1126
Harald Welte11eb4b52018-06-09 17:41:31 +02001127static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[])
1128{
1129 vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE);
Vadim Yanitskiy4abda9e2019-11-21 00:19:36 +07001130 return CMD_SUCCESS; /* Otherwise the process would terminate */
Harald Welte11eb4b52018-06-09 17:41:31 +02001131}
1132
1133void logging_vty_add_deprecated_subsys(void *ctx, const char *name)
1134{
1135 struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element);
1136 OSMO_ASSERT(cmd);
Vadim Yanitskiy75c242e2019-11-21 00:06:53 +07001137 cmd->string = talloc_asprintf(cmd, "logging level %s " LOG_LEVEL_ARGS, name);
Harald Welte11eb4b52018-06-09 17:41:31 +02001138 cmd->func = log_deprecated_func;
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001139 cmd->doc = LEVEL_STR
Harald Welte11eb4b52018-06-09 17:41:31 +02001140 "Deprecated Category\n";
1141 cmd->attr = CMD_ATTR_DEPRECATED;
1142
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001143 install_lib_element(CFG_LOG_NODE, cmd);
Harald Welte11eb4b52018-06-09 17:41:31 +02001144}
1145
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001146/* logp (<categories>) (debug|...|fatal) .LOGMESSAGE*/
1147DEFUN(vty_logp,
1148 vty_logp_cmd,
1149 NULL, /* cmdstr is dynamically set in gen_vty_logp_cmd_strs(). */
1150 NULL) /* same thing for helpstr. */
1151{
1152 int category = log_parse_category(argv[0]);
1153 int level = log_parse_level(argv[1]);
1154 char *str = argv_concat(argv, argc, 2);
Vadim Yanitskiy4b46b7e2021-04-05 03:45:15 +02001155
1156 if (level < 0) {
1157 vty_out(vty, "%% Invalid level '%s'%s", argv[1], VTY_NEWLINE);
1158 return CMD_WARNING;
1159 }
1160
1161 if (category < 0) {
1162 vty_out(vty, "%% Invalid category '%s'%s", argv[0], VTY_NEWLINE);
1163 return CMD_WARNING;
1164 }
1165
1166 /* Properly handle library specific sub-systems */
1167 if ((unsigned int) category >= osmo_log_info->num_cat_user) {
1168 category -= osmo_log_info->num_cat_user - 1;
1169 category *= -1;
1170 }
1171
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001172 LOGP(category, level, "%s\n", str);
1173 return CMD_SUCCESS;
1174}
1175
1176static void gen_vty_logp_cmd_strs(struct cmd_element *cmd)
1177{
1178 char *cmd_str = NULL;
1179 char *doc_str = NULL;
1180
1181 assert_loginfo(__func__);
1182
1183 OSMO_ASSERT(cmd->string == NULL);
1184 OSMO_ASSERT(cmd->doc == NULL);
1185
1186 osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logp (");
1187 osmo_talloc_asprintf(tall_log_ctx, doc_str,
1188 "Print a message on all log outputs; useful for placing markers in test logs\n");
1189 add_category_strings(&cmd_str, &doc_str, osmo_log_info);
1190 osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", LOG_LEVEL_ARGS);
1191 osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", LOG_LEVEL_STRS);
1192
1193 osmo_talloc_asprintf(tall_log_ctx, cmd_str, " .LOGMESSAGE");
1194 osmo_talloc_asprintf(tall_log_ctx, doc_str,
1195 "Arbitrary message to log on given category and log level\n");
1196
Harald Weltebebec212020-07-15 12:21:29 +02001197 talloc_set_name_const(cmd_str, "vty_logp_cmd_str");
1198 talloc_set_name_const(doc_str, "vty_logp_doc_str");
1199
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001200 cmd->string = cmd_str;
1201 cmd->doc = doc_str;
1202}
1203
Harald Welte8c648252017-10-16 15:17:03 +02001204/*! Register logging related commands to the VTY. Call this once from
1205 * your application if you want to support those commands. */
Harald Weltee61d4592022-11-03 11:05:58 +01001206void logging_vty_add_cmds(void)
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001207{
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001208 install_lib_element_ve(&enable_logging_cmd);
1209 install_lib_element_ve(&disable_logging_cmd);
1210 install_lib_element_ve(&logging_fltr_all_cmd);
1211 install_lib_element_ve(&logging_use_clr_cmd);
1212 install_lib_element_ve(&logging_prnt_timestamp_cmd);
1213 install_lib_element_ve(&logging_prnt_ext_timestamp_cmd);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001214 install_lib_element_ve(&logging_prnt_tid_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001215 install_lib_element_ve(&logging_prnt_cat_cmd);
1216 install_lib_element_ve(&logging_prnt_cat_hex_cmd);
1217 install_lib_element_ve(&logging_prnt_level_cmd);
1218 install_lib_element_ve(&logging_prnt_file_cmd);
1219 install_lib_element_ve(&logging_set_category_mask_cmd);
1220 install_lib_element_ve(&logging_set_category_mask_old_cmd);
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +01001221
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001222 /* logging level (<categories>) (debug|...|fatal) */
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001223 gen_logging_level_cmd_strs(&logging_level_cmd,
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001224 LOG_LEVEL_ARGS,
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001225 LOG_LEVEL_STRS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001226 /* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001227 gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd,
1228 "everything", EVERYTHING_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001229
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001230 install_lib_element_ve(&logging_level_cmd);
1231 install_lib_element_ve(&logging_level_set_all_cmd);
1232 install_lib_element_ve(&logging_level_force_all_cmd);
1233 install_lib_element_ve(&no_logging_level_force_all_cmd);
1234 install_lib_element_ve(&deprecated_logging_level_everything_cmd);
1235 install_lib_element_ve(&deprecated_logging_level_all_cmd);
1236 install_lib_element_ve(&deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001237
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001238 gen_vty_logp_cmd_strs(&vty_logp_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001239 install_lib_element_ve(&vty_logp_cmd);
Neels Hofmeyrd0b3b9e2019-07-29 19:28:08 +02001240
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001241 install_lib_element_ve(&show_logging_vty_cmd);
1242 install_lib_element_ve(&show_alarms_cmd);
Pau Espin Pedrol0c2a46d2019-08-20 10:39:05 +02001243
Harald Welte28222962011-02-18 20:37:04 +01001244 install_node(&cfg_log_node, config_write_log);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001245 install_lib_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
1246 install_lib_element(CFG_LOG_NODE, &logging_use_clr_cmd);
1247 install_lib_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
1248 install_lib_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd);
Pau Espin Pedrol662d10d2021-02-18 18:19:23 +01001249 install_lib_element(CFG_LOG_NODE, &logging_prnt_tid_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001250 install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);
1251 install_lib_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd);
1252 install_lib_element(CFG_LOG_NODE, &logging_prnt_level_cmd);
1253 install_lib_element(CFG_LOG_NODE, &logging_prnt_file_cmd);
1254 install_lib_element(CFG_LOG_NODE, &logging_level_cmd);
1255 install_lib_element(CFG_LOG_NODE, &logging_level_set_all_cmd);
1256 install_lib_element(CFG_LOG_NODE, &logging_level_force_all_cmd);
1257 install_lib_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd);
1258 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd);
1259 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd);
1260 install_lib_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001261
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001262 install_lib_element(CONFIG_NODE, &cfg_log_stderr_cmd);
1263 install_lib_element(CONFIG_NODE, &cfg_no_log_stderr_cmd);
1264 install_lib_element(CONFIG_NODE, &cfg_log_file_cmd);
1265 install_lib_element(CONFIG_NODE, &cfg_no_log_file_cmd);
1266 install_lib_element(CONFIG_NODE, &cfg_log_alarms_cmd);
1267 install_lib_element(CONFIG_NODE, &cfg_no_log_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001268#ifdef HAVE_SYSLOG_H
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001269 install_lib_element(CONFIG_NODE, &cfg_log_syslog_cmd);
1270 install_lib_element(CONFIG_NODE, &cfg_log_syslog_local_cmd);
1271 install_lib_element(CONFIG_NODE, &cfg_no_log_syslog_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001272#endif
Vadim Yanitskiye7bf4352020-09-09 03:36:48 +07001273 install_lib_element(CONFIG_NODE, &cfg_log_systemd_journal_cmd);
1274 install_lib_element(CONFIG_NODE, &cfg_no_log_systemd_journal_cmd);
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +07001275 install_lib_element(CONFIG_NODE, &cfg_log_gsmtap_cmd);
Vadim Yanitskiy2f4186a2021-12-29 21:58:19 +06001276 install_lib_element(CONFIG_NODE, &cfg_no_log_gsmtap_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001277}