blob: f3e1419c8e9185b000ecf92e83a45e6132f649e4 [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 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdlib.h>
25#include <string.h>
26
Harald Welte28222962011-02-18 20:37:04 +010027#include "../../config.h"
28
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010029#include <osmocom/core/talloc.h>
30#include <osmocom/core/logging.h>
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020031#include <osmocom/core/logging_internal.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010032#include <osmocom/core/utils.h>
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000033#include <osmocom/core/strrb.h>
34#include <osmocom/core/loggingrb.h>
Harald Welteaa00f992016-12-02 15:30:02 +010035#include <osmocom/core/gsmtap.h>
Harald Welte3fb0b6f2010-05-19 19:02:52 +020036
37#include <osmocom/vty/command.h>
38#include <osmocom/vty/buffer.h>
39#include <osmocom/vty/vty.h>
40#include <osmocom/vty/telnet_interface.h>
41#include <osmocom/vty/logging.h>
42
Harald Welte28222962011-02-18 20:37:04 +010043#define LOG_STR "Configure logging sub-system\n"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020044#define LEVEL_STR "Set the log level for a specified category\n"
45
Neels Hofmeyr9540c242018-09-12 00:20:50 +020046#define CATEGORY_ALL_STR "Deprecated alias for 'force-all'\n"
47#define FORCE_ALL_STR \
48 "Globally force all logging categories to a specific level. This is released by the" \
49 " 'no logging level force-all' command. Note: any 'logging level <category> <level>'" \
50 " commands will have no visible effect after this, until the forced level is released.\n"
51#define NO_FORCE_ALL_STR \
52 "Release any globally forced log level set with 'logging level force-all <level>'\n"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020053
Neels Hofmeyr9540c242018-09-12 00:20:50 +020054#define LOG_LEVEL_ARGS "(debug|info|notice|error|fatal)"
Neels Hofmeyrba0762d2018-09-10 13:56:03 +020055#define LOG_LEVEL_STRS \
56 "Log debug messages and higher levels\n" \
57 "Log informational messages and higher levels\n" \
58 "Log noticeable messages and higher levels\n" \
59 "Log error messages and higher levels\n" \
60 "Log only fatal messages\n"
61
Neels Hofmeyr9540c242018-09-12 00:20:50 +020062#define EVERYTHING_STR "Deprecated alias for 'no logging level force-all'\n"
Harald Welte28222962011-02-18 20:37:04 +010063
Harald Welte8c648252017-10-16 15:17:03 +020064/*! \file logging_vty.c
Neels Hofmeyr87e45502017-06-20 00:17:59 +020065 * Configuration of logging from VTY
Harald Welte96e2a002017-06-12 21:44:18 +020066 *
Harald Welte8c648252017-10-16 15:17:03 +020067 * This module implements
68 * - functions that permit configuration of the libosmocore logging
69 * framework from VTY commands in the configure -> logging node.
70 *
71 * - functions that permit logging *to* a VTY session. Basically each
72 * VTY session gets its own log target, with configurable
73 * per-subsystem log levels. This is performed internally via the
74 * \ref log_target_create_vty function.
75 *
76 * You have to call \ref logging_vty_add_cmds from your application
77 * once to enable both of the above.
78 *
Harald Welte96e2a002017-06-12 21:44:18 +020079 */
80
Harald Welte76e72ab2011-02-17 15:52:39 +010081static void _vty_output(struct log_target *tgt,
82 unsigned int level, const char *line)
Harald Welte3fb0b6f2010-05-19 19:02:52 +020083{
84 struct vty *vty = tgt->tgt_vty.vty;
85 vty_out(vty, "%s", line);
86 /* This is an ugly hack, but there is no easy way... */
87 if (strchr(line, '\n'))
88 vty_out(vty, "\r");
89}
90
91struct log_target *log_target_create_vty(struct vty *vty)
92{
93 struct log_target *target;
94
95 target = log_target_create();
96 if (!target)
97 return NULL;
98
99 target->tgt_vty.vty = vty;
100 target->output = _vty_output;
101 return target;
102}
103
104DEFUN(enable_logging,
105 enable_logging_cmd,
106 "logging enable",
107 LOGGING_STR
108 "Enables logging to this vty\n")
109{
110 struct telnet_connection *conn;
111
112 conn = (struct telnet_connection *) vty->priv;
113 if (conn->dbg) {
114 vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
115 return CMD_WARNING;
116 }
117
118 conn->dbg = log_target_create_vty(vty);
119 if (!conn->dbg)
120 return CMD_WARNING;
121
122 log_add_target(conn->dbg);
123 return CMD_SUCCESS;
124}
125
Harald Weltea62648b2011-02-18 21:03:27 +0100126struct log_target *osmo_log_vty2tgt(struct vty *vty)
127{
128 struct telnet_connection *conn;
129
130 if (vty->node == CFG_LOG_NODE)
131 return vty->index;
132
133
134 conn = (struct telnet_connection *) vty->priv;
135 if (!conn->dbg)
136 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
137
138 return conn->dbg;
139}
140
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200141DEFUN(logging_fltr_all,
142 logging_fltr_all_cmd,
143 "logging filter all (0|1)",
144 LOGGING_STR FILTER_STR
145 "Do you want to log all messages?\n"
146 "Only print messages matched by other filters\n"
147 "Bypass filter and print all messages\n")
148{
Harald Weltea62648b2011-02-18 21:03:27 +0100149 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200150
Harald Weltea62648b2011-02-18 21:03:27 +0100151 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200152 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200153
Harald Weltea62648b2011-02-18 21:03:27 +0100154 log_set_all_filter(tgt, atoi(argv[0]));
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200155 return CMD_SUCCESS;
156}
157
158DEFUN(logging_use_clr,
159 logging_use_clr_cmd,
160 "logging color (0|1)",
161 LOGGING_STR "Configure color-printing for log messages\n"
162 "Don't use color for printing messages\n"
163 "Use color for printing messages\n")
164{
Harald Weltea62648b2011-02-18 21:03:27 +0100165 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200166
Harald Weltea62648b2011-02-18 21:03:27 +0100167 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200168 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200169
Harald Weltea62648b2011-02-18 21:03:27 +0100170 log_set_use_color(tgt, atoi(argv[0]));
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200171 return CMD_SUCCESS;
172}
173
174DEFUN(logging_prnt_timestamp,
175 logging_prnt_timestamp_cmd,
176 "logging timestamp (0|1)",
177 LOGGING_STR "Configure log message timestamping\n"
178 "Don't prefix each log message\n"
179 "Prefix each log message with current timestamp\n")
180{
Harald Weltea62648b2011-02-18 21:03:27 +0100181 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200182
Harald Weltea62648b2011-02-18 21:03:27 +0100183 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200184 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200185
Harald Weltea62648b2011-02-18 21:03:27 +0100186 log_set_print_timestamp(tgt, atoi(argv[0]));
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200187 return CMD_SUCCESS;
188}
189
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100190DEFUN(logging_prnt_ext_timestamp,
191 logging_prnt_ext_timestamp_cmd,
192 "logging print extended-timestamp (0|1)",
193 LOGGING_STR "Log output settings\n"
194 "Configure log message timestamping\n"
195 "Don't prefix each log message\n"
196 "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n")
197{
198 struct log_target *tgt = osmo_log_vty2tgt(vty);
199
200 if (!tgt)
201 return CMD_WARNING;
202
203 log_set_print_extended_timestamp(tgt, atoi(argv[0]));
204 return CMD_SUCCESS;
205}
206
207DEFUN(logging_prnt_cat,
208 logging_prnt_cat_cmd,
209 "logging print category (0|1)",
210 LOGGING_STR "Log output settings\n"
211 "Configure log message\n"
212 "Don't prefix each log message\n"
213 "Prefix each log message with category/subsystem name\n")
214{
215 struct log_target *tgt = osmo_log_vty2tgt(vty);
216
217 if (!tgt)
218 return CMD_WARNING;
219
220 log_set_print_category(tgt, atoi(argv[0]));
221 return CMD_SUCCESS;
222}
223
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100224DEFUN(logging_prnt_cat_hex,
225 logging_prnt_cat_hex_cmd,
226 "logging print category-hex (0|1)",
227 LOGGING_STR "Log output settings\n"
228 "Configure log message\n"
229 "Don't prefix each log message\n"
230 "Prefix each log message with category/subsystem nr in hex ('<000b>')\n")
231{
232 struct log_target *tgt = osmo_log_vty2tgt(vty);
233
234 if (!tgt)
235 return CMD_WARNING;
236
237 log_set_print_category_hex(tgt, atoi(argv[0]));
238 return CMD_SUCCESS;
239}
240
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100241DEFUN(logging_prnt_level,
242 logging_prnt_level_cmd,
243 "logging print level (0|1)",
244 LOGGING_STR "Log output settings\n"
245 "Configure log message\n"
246 "Don't prefix each log message\n"
247 "Prefix each log message with the log level name\n")
248{
249 struct log_target *tgt = osmo_log_vty2tgt(vty);
250
251 if (!tgt)
252 return CMD_WARNING;
253
254 log_set_print_level(tgt, atoi(argv[0]));
255 return CMD_SUCCESS;
256}
257
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100258static const struct value_string logging_print_file_args[] = {
259 { LOG_FILENAME_NONE, "0" },
260 { LOG_FILENAME_PATH, "1" },
261 { LOG_FILENAME_BASENAME, "basename" },
262 { 0, NULL }
263};
264
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100265DEFUN(logging_prnt_file,
266 logging_prnt_file_cmd,
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200267 "logging print file (0|1|basename) [last]",
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100268 LOGGING_STR "Log output settings\n"
269 "Configure log message\n"
270 "Don't prefix each log message\n"
271 "Prefix each log message with the source file and line\n"
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200272 "Prefix each log message with the source file's basename (strip leading paths) and line\n"
273 "Log source file info at the end of a log line. If omitted, log source file info just"
274 " before the log text.\n")
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100275{
276 struct log_target *tgt = osmo_log_vty2tgt(vty);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100277
278 if (!tgt)
279 return CMD_WARNING;
280
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100281 log_set_print_filename2(tgt, get_string_value(logging_print_file_args, argv[0]));
Neels Hofmeyr77ae45d2018-08-27 20:32:36 +0200282 if (argc > 1)
283 log_set_print_filename_pos(tgt, LOG_FILENAME_POS_LINE_END);
284 else
285 log_set_print_filename_pos(tgt, LOG_FILENAME_POS_HEADER_END);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100286 return CMD_SUCCESS;
287}
288
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200289static void add_category_strings(char **cmd_str_p, char **doc_str_p,
290 const struct log_info *categories)
291{
292 int i;
293 for (i = 0; i < categories->num_cat; i++) {
294 if (categories->cat[i].name == NULL)
295 continue;
296 /* skip the leading 'D' in each category name, hence '+ 1' */
297 osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s",
298 i ? "|" : "",
299 osmo_str_tolower(categories->cat[i].name + 1));
300 osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n",
301 categories->cat[i].description);
302 }
303}
304
305static void gen_logging_level_cmd_strs(struct cmd_element *cmd,
306 const char *level_args, const char *level_strs)
307{
308 char *cmd_str = NULL;
309 char *doc_str = NULL;
310
311 assert_loginfo(__func__);
312
313 OSMO_ASSERT(cmd->string == NULL);
314 OSMO_ASSERT(cmd->doc == NULL);
315
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200316 osmo_talloc_asprintf(tall_log_ctx, cmd_str, "logging level (");
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200317 osmo_talloc_asprintf(tall_log_ctx, doc_str,
318 LOGGING_STR
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200319 LEVEL_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200320 add_category_strings(&cmd_str, &doc_str, osmo_log_info);
321 osmo_talloc_asprintf(tall_log_ctx, cmd_str, ") %s", level_args);
322 osmo_talloc_asprintf(tall_log_ctx, doc_str, "%s", level_strs);
323
324 cmd->string = cmd_str;
325 cmd->doc = doc_str;
326}
327
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200328/* logging level (<categories>) (debug|...|fatal) */
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200329DEFUN(logging_level,
330 logging_level_cmd,
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +0100331 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
332 NULL) /* same thing for helpstr. */
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200333{
Harald Weltea62648b2011-02-18 21:03:27 +0100334 int category = log_parse_category(argv[0]);
335 int level = log_parse_level(argv[1]);
336 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200337
Harald Weltea62648b2011-02-18 21:03:27 +0100338 if (!tgt)
339 return CMD_WARNING;
340
341 if (level < 0) {
342 vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200343 return CMD_WARNING;
344 }
345
Harald Weltea62648b2011-02-18 21:03:27 +0100346 if (category < 0) {
347 vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
348 return CMD_WARNING;
349 }
350
351 tgt->categories[category].enabled = 1;
352 tgt->categories[category].loglevel = level;
353
354 return CMD_SUCCESS;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200355}
356
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200357DEFUN(logging_level_set_all, logging_level_set_all_cmd,
358 "logging level set-all " LOG_LEVEL_ARGS,
359 LOGGING_STR LEVEL_STR
360 "Once-off set all categories to the given log level. There is no single command"
361 " to take back these changes -- each category is set to the given level, period.\n"
362 LOG_LEVEL_STRS)
363{
364 struct log_target *tgt = osmo_log_vty2tgt(vty);
365 int level = log_parse_level(argv[0]);
366 int i;
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200367
368 if (!tgt)
369 return CMD_WARNING;
370
Neels Hofmeyr28fc0782018-09-12 02:32:02 +0200371 for (i = 0; i < osmo_log_info->num_cat; i++) {
372 struct log_category *cat = &tgt->categories[i];
373 /* skip empty entries in the array */
374 if (!osmo_log_info->cat[i].name)
375 continue;
376
377 cat->enabled = 1;
378 cat->loglevel = level;
379 }
380 return CMD_SUCCESS;
381}
382
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200383/* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200384DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd,
385 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
386 NULL) /* same thing for helpstr. */
387{
388 vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE);
389 return CMD_SUCCESS;
390}
391
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200392DEFUN(logging_level_force_all, logging_level_force_all_cmd,
393 "logging level force-all " LOG_LEVEL_ARGS,
394 LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS)
395{
396 struct log_target *tgt = osmo_log_vty2tgt(vty);
397 int level = log_parse_level(argv[0]);
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200398 if (!tgt)
399 return CMD_WARNING;
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200400 log_set_log_level(tgt, level);
401 return CMD_SUCCESS;
402}
403
404DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd,
405 "no logging level force-all",
406 NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)
407{
408 struct log_target *tgt = osmo_log_vty2tgt(vty);
Neels Hofmeyrea6f5192018-10-01 15:51:18 +0200409 if (!tgt)
410 return CMD_WARNING;
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200411 log_set_log_level(tgt, 0);
412 return CMD_SUCCESS;
413}
414
415/* 'logging level all (debug|...|fatal)' */
416ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd,
417 "logging level all " LOG_LEVEL_ARGS,
418 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS);
419
420/* 'logging level all everything' */
421ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd,
422 "logging level all everything",
423 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR);
424
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200425DEFUN(logging_set_category_mask,
426 logging_set_category_mask_cmd,
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200427 "logging set-log-mask MASK",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200428 LOGGING_STR
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200429 "Set the logmask of this logging target\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100430 "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific"
431 " application, refer to the 'logging level' command. Optionally add individual log levels like"
432 " 'abc,1:mno,3:xyz,5', where the level numbers are"
433 " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG)
434 " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO)
435 " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE)
436 " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR)
437 " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL)
438 "\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200439{
Harald Weltea62648b2011-02-18 21:03:27 +0100440 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200441
Harald Weltea62648b2011-02-18 21:03:27 +0100442 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200443 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200444
Harald Weltea62648b2011-02-18 21:03:27 +0100445 log_parse_category_mask(tgt, argv[0]);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200446 return CMD_SUCCESS;
447}
448
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200449ALIAS_DEPRECATED(logging_set_category_mask,
450 logging_set_category_mask_old_cmd,
451 "logging set log mask MASK",
452 LOGGING_STR
453 "Decide which categories to output.\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100454 "Log commands\n" "Mask commands\n"
455 "'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 +0200456
457
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200458DEFUN(diable_logging,
459 disable_logging_cmd,
460 "logging disable",
461 LOGGING_STR
462 "Disables logging to this vty\n")
463{
Harald Weltea62648b2011-02-18 21:03:27 +0100464 struct log_target *tgt = osmo_log_vty2tgt(vty);
465 struct telnet_connection *conn = (struct telnet_connection *) vty->priv;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200466
Harald Weltea62648b2011-02-18 21:03:27 +0100467 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200468 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200469
Harald Weltea62648b2011-02-18 21:03:27 +0100470 log_del_target(tgt);
471 talloc_free(tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200472 conn->dbg = NULL;
Harald Weltea62648b2011-02-18 21:03:27 +0100473
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200474 return CMD_SUCCESS;
475}
476
477static void vty_print_logtarget(struct vty *vty, const struct log_info *info,
478 const struct log_target *tgt)
479{
480 unsigned int i;
481
482 vty_out(vty, " Global Loglevel: %s%s",
483 log_level_str(tgt->loglevel), VTY_NEWLINE);
484 vty_out(vty, " Use color: %s, Print Timestamp: %s%s",
485 tgt->use_color ? "On" : "Off",
486 tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE);
487
488 vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE);
489
490 for (i = 0; i < info->num_cat; i++) {
491 const struct log_category *cat = &tgt->categories[i];
Daniel Willmann55363a92016-11-15 10:05:51 +0100492 /* Skip categories that were not initialized */
493 if (!info->cat[i].name)
494 continue;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200495 vty_out(vty, " %-10s %-10s %-8s %s%s",
496 info->cat[i].name+1, log_level_str(cat->loglevel),
497 cat->enabled ? "Enabled" : "Disabled",
498 info->cat[i].description,
499 VTY_NEWLINE);
500 }
Harald Welte6d2d4d62013-03-10 09:53:24 +0000501
502 vty_out(vty, " Log Filter 'ALL': %s%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100503 tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled",
Harald Welte6d2d4d62013-03-10 09:53:24 +0000504 VTY_NEWLINE);
505
Harald Weltefb84f322013-06-06 07:33:54 +0200506 /* print application specific filters */
507 if (info->print_fn)
508 info->print_fn(vty, info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200509}
510
511#define SHOW_LOG_STR "Show current logging configuration\n"
512
513DEFUN(show_logging_vty,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000514 show_logging_vty_cmd,
515 "show logging vty",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200516 SHOW_STR SHOW_LOG_STR
517 "Show current logging configuration for this vty\n")
518{
Harald Weltea62648b2011-02-18 21:03:27 +0100519 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200520
Harald Weltea62648b2011-02-18 21:03:27 +0100521 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200522 return CMD_WARNING;
Harald Weltea62648b2011-02-18 21:03:27 +0100523
524 vty_print_logtarget(vty, osmo_log_info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200525
526 return CMD_SUCCESS;
527}
528
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000529DEFUN(show_alarms,
530 show_alarms_cmd,
531 "show alarms",
532 SHOW_STR SHOW_LOG_STR
533 "Show the contents of the logging ringbuffer\n")
534{
535 int i, num_alarms;
536 struct osmo_strrb *rb;
537 struct log_target *tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
538 if (!tgt) {
539 vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s",
540 VTY_NEWLINE);
541 return CMD_WARNING;
542 }
543
544 rb = tgt->tgt_rb.rb;
545 num_alarms = osmo_strrb_elements(rb);
546
547 vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE);
548
549 for (i = 0; i < num_alarms; i++)
550 vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i),
551 VTY_NEWLINE);
552
553 return CMD_SUCCESS;
554}
555
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200556gDEFUN(cfg_description, cfg_description_cmd,
557 "description .TEXT",
Thorsten Alteholza81055d2017-03-02 22:13:48 +0100558 "Save human-readable description of the object\n"
Holger Hans Peter Freytherc9b3e062012-07-25 13:02:49 +0200559 "Text until the end of the line\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200560{
561 char **dptr = vty->index_sub;
562
563 if (!dptr) {
564 vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
565 return CMD_WARNING;
566 }
567
Holger Hans Peter Freytherff0670e2011-02-24 14:20:41 +0100568 if (*dptr)
569 talloc_free(*dptr);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200570 *dptr = argv_concat(argv, argc, 0);
Holger Hans Peter Freyther6a75d162013-07-14 09:07:11 +0200571 if (!*dptr)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200572 return CMD_WARNING;
573
574 return CMD_SUCCESS;
575}
576
577gDEFUN(cfg_no_description, cfg_no_description_cmd,
578 "no description",
579 NO_STR
580 "Remove description of the object\n")
581{
582 char **dptr = vty->index_sub;
583
584 if (!dptr) {
585 vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
586 return CMD_WARNING;
587 }
588
589 if (*dptr) {
590 talloc_free(*dptr);
591 *dptr = NULL;
592 }
593
594 return CMD_SUCCESS;
595}
596
Harald Welte28222962011-02-18 20:37:04 +0100597/* Support for configuration of log targets != the current vty */
598
599struct cmd_node cfg_log_node = {
600 CFG_LOG_NODE,
601 "%s(config-log)# ",
602 1
603};
604
Harald Welte28222962011-02-18 20:37:04 +0100605#ifdef HAVE_SYSLOG_H
606
607#include <syslog.h>
608
609static const int local_sysl_map[] = {
610 [0] = LOG_LOCAL0,
611 [1] = LOG_LOCAL1,
612 [2] = LOG_LOCAL2,
613 [3] = LOG_LOCAL3,
614 [4] = LOG_LOCAL4,
615 [5] = LOG_LOCAL5,
616 [6] = LOG_LOCAL6,
617 [7] = LOG_LOCAL7
618};
619
Harald Weltede79cee2011-02-24 23:47:57 +0100620/* From VTY core code */
621extern struct host host;
622
Harald Welte28222962011-02-18 20:37:04 +0100623static int _cfg_log_syslog(struct vty *vty, int facility)
624{
625 struct log_target *tgt;
626
627 /* First delete the old syslog target, if any */
628 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
629 if (tgt)
630 log_target_destroy(tgt);
631
Harald Weltede79cee2011-02-24 23:47:57 +0100632 tgt = log_target_create_syslog(host.app_info->name, 0, facility);
Harald Welte28222962011-02-18 20:37:04 +0100633 if (!tgt) {
634 vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE);
635 return CMD_WARNING;
636 }
637 log_add_target(tgt);
638
639 vty->index = tgt;
640 vty->node = CFG_LOG_NODE;
641
642 return CMD_SUCCESS;
643}
644
645DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd,
646 "log syslog local <0-7>",
647 LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n"
648 "Local facility number\n")
649{
650 int local = atoi(argv[0]);
651 int facility = local_sysl_map[local];
652
653 return _cfg_log_syslog(vty, facility);
654}
655
656static struct value_string sysl_level_names[] = {
657 { LOG_AUTHPRIV, "authpriv" },
658 { LOG_CRON, "cron" },
659 { LOG_DAEMON, "daemon" },
660 { LOG_FTP, "ftp" },
661 { LOG_LPR, "lpr" },
662 { LOG_MAIL, "mail" },
663 { LOG_NEWS, "news" },
664 { LOG_USER, "user" },
665 { LOG_UUCP, "uucp" },
666 /* only for value -> string conversion */
667 { LOG_LOCAL0, "local 0" },
668 { LOG_LOCAL1, "local 1" },
669 { LOG_LOCAL2, "local 2" },
670 { LOG_LOCAL3, "local 3" },
671 { LOG_LOCAL4, "local 4" },
672 { LOG_LOCAL5, "local 5" },
673 { LOG_LOCAL6, "local 6" },
674 { LOG_LOCAL7, "local 7" },
675 { 0, NULL }
676};
677
678DEFUN(cfg_log_syslog, cfg_log_syslog_cmd,
679 "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)",
Holger Hans Peter Freythera4463fd2011-10-03 23:17:36 +0200680 LOG_STR "Logging via syslog\n"
681 "Security/authorization messages facility\n"
682 "Clock daemon (cron/at) facility\n"
683 "General system daemon facility\n"
684 "Ftp daemon facility\n"
685 "Line printer facility\n"
686 "Mail facility\n"
687 "News facility\n"
688 "Generic facility\n"
689 "UUCP facility\n")
Harald Welte28222962011-02-18 20:37:04 +0100690{
691 int facility = get_string_value(sysl_level_names, argv[0]);
692
693 return _cfg_log_syslog(vty, facility);
694}
695
696DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd,
697 "no log syslog",
698 NO_STR LOG_STR "Logging via syslog\n")
699{
700 struct log_target *tgt;
701
702 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
703 if (!tgt) {
704 vty_out(vty, "%% No syslog target found%s",
705 VTY_NEWLINE);
706 return CMD_WARNING;
707 }
708
709 log_target_destroy(tgt);
710
711 return CMD_SUCCESS;
712}
713#endif /* HAVE_SYSLOG_H */
714
Harald Welteaa00f992016-12-02 15:30:02 +0100715DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
716 "log gsmtap [HOSTNAME]",
Neels Hofmeyrfd9ec3b2016-12-11 01:48:26 +0100717 LOG_STR "Logging via GSMTAP\n"
718 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
Harald Welteaa00f992016-12-02 15:30:02 +0100719{
Max2f153b52018-01-04 12:25:57 +0100720 const char *hostname = argc ? argv[0] : "127.0.0.1";
Harald Welteaa00f992016-12-02 15:30:02 +0100721 struct log_target *tgt;
722
723 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
724 if (!tgt) {
725 tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT,
726 host.app_info->name, false,
727 true);
728 if (!tgt) {
Max2f153b52018-01-04 12:25:57 +0100729 vty_out(vty, "%% Unable to create GSMTAP log for %s%s",
730 hostname, VTY_NEWLINE);
Harald Welteaa00f992016-12-02 15:30:02 +0100731 return CMD_WARNING;
732 }
733 log_add_target(tgt);
734 }
735
736 vty->index = tgt;
737 vty->node = CFG_LOG_NODE;
738
739 return CMD_SUCCESS;
740}
741
Harald Welte28222962011-02-18 20:37:04 +0100742DEFUN(cfg_log_stderr, cfg_log_stderr_cmd,
743 "log stderr",
744 LOG_STR "Logging via STDERR of the process\n")
745{
746 struct log_target *tgt;
747
748 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
749 if (!tgt) {
750 tgt = log_target_create_stderr();
751 if (!tgt) {
752 vty_out(vty, "%% Unable to create stderr log%s",
753 VTY_NEWLINE);
754 return CMD_WARNING;
755 }
756 log_add_target(tgt);
757 }
758
759 vty->index = tgt;
760 vty->node = CFG_LOG_NODE;
761
762 return CMD_SUCCESS;
763}
764
765DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd,
766 "no log stderr",
767 NO_STR LOG_STR "Logging via STDERR of the process\n")
768{
769 struct log_target *tgt;
770
771 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
772 if (!tgt) {
773 vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE);
774 return CMD_WARNING;
775 }
776
777 log_target_destroy(tgt);
778
779 return CMD_SUCCESS;
780}
781
782DEFUN(cfg_log_file, cfg_log_file_cmd,
783 "log file .FILENAME",
784 LOG_STR "Logging to text file\n" "Filename\n")
785{
786 const char *fname = argv[0];
787 struct log_target *tgt;
788
789 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
790 if (!tgt) {
791 tgt = log_target_create_file(fname);
792 if (!tgt) {
793 vty_out(vty, "%% Unable to create file `%s'%s",
794 fname, VTY_NEWLINE);
795 return CMD_WARNING;
796 }
797 log_add_target(tgt);
798 }
799
800 vty->index = tgt;
801 vty->node = CFG_LOG_NODE;
802
803 return CMD_SUCCESS;
804}
805
806
807DEFUN(cfg_no_log_file, cfg_no_log_file_cmd,
808 "no log file .FILENAME",
809 NO_STR LOG_STR "Logging to text file\n" "Filename\n")
810{
811 const char *fname = argv[0];
812 struct log_target *tgt;
813
814 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
815 if (!tgt) {
816 vty_out(vty, "%% No such log file `%s'%s",
817 fname, VTY_NEWLINE);
818 return CMD_WARNING;
819 }
820
821 log_target_destroy(tgt);
822
823 return CMD_SUCCESS;
824}
825
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000826DEFUN(cfg_log_alarms, cfg_log_alarms_cmd,
827 "log alarms <2-32700>",
828 LOG_STR "Logging alarms to osmo_strrb\n"
829 "Maximum number of messages to log\n")
830{
831 struct log_target *tgt;
832 unsigned int rbsize = atoi(argv[0]);
833
834 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
835 if (tgt)
836 log_target_destroy(tgt);
837
838 tgt = log_target_create_rb(rbsize);
839 if (!tgt) {
840 vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s",
841 rbsize, VTY_NEWLINE);
842 return CMD_WARNING;
843 }
844 log_add_target(tgt);
845
846 vty->index = tgt;
847 vty->node = CFG_LOG_NODE;
848
849 return CMD_SUCCESS;
850}
851
852DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd,
853 "no log alarms",
854 NO_STR LOG_STR "Logging alarms to osmo_strrb\n")
855{
856 struct log_target *tgt;
857
858 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
859 if (!tgt) {
860 vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE);
861 return CMD_WARNING;
862 }
863
864 log_target_destroy(tgt);
865
866 return CMD_SUCCESS;
867}
868
Harald Welte28222962011-02-18 20:37:04 +0100869static int config_write_log_single(struct vty *vty, struct log_target *tgt)
870{
871 int i;
Harald Welte28222962011-02-18 20:37:04 +0100872
873 switch (tgt->type) {
874 case LOG_TGT_TYPE_VTY:
875 return 1;
876 break;
877 case LOG_TGT_TYPE_STDERR:
878 vty_out(vty, "log stderr%s", VTY_NEWLINE);
879 break;
880 case LOG_TGT_TYPE_SYSLOG:
881#ifdef HAVE_SYSLOG_H
882 vty_out(vty, "log syslog %s%s",
883 get_value_string(sysl_level_names,
884 tgt->tgt_syslog.facility),
885 VTY_NEWLINE);
886#endif
887 break;
888 case LOG_TGT_TYPE_FILE:
889 vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE);
890 break;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000891 case LOG_TGT_TYPE_STRRB:
892 vty_out(vty, "log alarms %zu%s",
893 log_target_rb_avail_size(tgt), VTY_NEWLINE);
894 break;
Harald Welteaa00f992016-12-02 15:30:02 +0100895 case LOG_TGT_TYPE_GSMTAP:
896 vty_out(vty, "log gsmtap %s%s",
897 tgt->tgt_gsmtap.hostname, VTY_NEWLINE);
898 break;
Harald Welte28222962011-02-18 20:37:04 +0100899 }
900
Harald Welte0d67f482018-09-25 20:16:14 +0200901 vty_out(vty, " logging filter all %u%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100902 tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE);
Harald Weltefb84f322013-06-06 07:33:54 +0200903 /* save filters outside of libosmocore, i.e. in app code */
904 if (osmo_log_info->save_fn)
905 osmo_log_info->save_fn(vty, osmo_log_info, tgt);
Harald Welte2da47f12012-10-22 19:31:54 +0200906
Harald Welte0d67f482018-09-25 20:16:14 +0200907 vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0,
Harald Welte28222962011-02-18 20:37:04 +0100908 VTY_NEWLINE);
Harald Welte0d67f482018-09-25 20:16:14 +0200909 vty_out(vty, " logging print category %d%s",
Michael McTernan78933462015-03-20 15:29:25 +0100910 tgt->print_category ? 1 : 0, VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100911 if (tgt->print_ext_timestamp)
Harald Welte0d67f482018-09-25 20:16:14 +0200912 vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100913 else
Harald Welte0d67f482018-09-25 20:16:14 +0200914 vty_out(vty, " logging timestamp %u%s",
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100915 tgt->print_timestamp ? 1 : 0, VTY_NEWLINE);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100916 if (tgt->print_level)
Harald Welte0d67f482018-09-25 20:16:14 +0200917 vty_out(vty, " logging print level 1%s", VTY_NEWLINE);
918 vty_out(vty, " logging print file %s%s",
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100919 get_value_string(logging_print_file_args, tgt->print_filename2),
920 VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +0100921
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200922 if (tgt->loglevel) {
923 const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel);
924 level_str = osmo_str_tolower(level_str);
925 if (!level_str)
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200926 vty_out(vty, "%% Invalid log level %u for 'force-all'%s",
927 tgt->loglevel, VTY_NEWLINE);
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200928 else
Harald Welte0d67f482018-09-25 20:16:14 +0200929 vty_out(vty, " logging level force-all %s%s", level_str, VTY_NEWLINE);
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200930 }
Harald Welte28222962011-02-18 20:37:04 +0100931
932 for (i = 0; i < osmo_log_info->num_cat; i++) {
933 const struct log_category *cat = &tgt->categories[i];
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200934 const char *cat_name;
935 const char *level_str;
Harald Welte28222962011-02-18 20:37:04 +0100936
Harald Welte1a02cfc2013-03-19 10:37:39 +0100937 /* skip empty entries in the array */
938 if (!osmo_log_info->cat[i].name)
939 continue;
940
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200941 /* Note: cat_name references the static buffer returned by osmo_str_tolower(), will
942 * become invalid after next osmo_str_tolower() invocation. */
943 cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1);
944
945 level_str = get_value_string_or_null(loglevel_strs, cat->loglevel);
946 if (!level_str) {
947 vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
948 VTY_NEWLINE);
949 continue;
950 }
951
Harald Welte0d67f482018-09-25 20:16:14 +0200952 vty_out(vty, " logging level %s", cat_name);
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200953 vty_out(vty, " %s%s", osmo_str_tolower(level_str), VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +0100954 }
955
Harald Welte28222962011-02-18 20:37:04 +0100956 return 1;
957}
958
959static int config_write_log(struct vty *vty)
960{
961 struct log_target *dbg = vty->index;
962
963 llist_for_each_entry(dbg, &osmo_log_target_list, entry)
964 config_write_log_single(vty, dbg);
965
966 return 1;
967}
968
Harald Welte11eb4b52018-06-09 17:41:31 +0200969static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[])
970{
971 vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE);
972 return CMD_WARNING;
973}
974
975void logging_vty_add_deprecated_subsys(void *ctx, const char *name)
976{
977 struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element);
978 OSMO_ASSERT(cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200979 cmd->string = talloc_asprintf(cmd, "logging level %s (debug|info|notice|error|fatal)",
Harald Welte11eb4b52018-06-09 17:41:31 +0200980 name);
981 printf("%s\n", cmd->string);
982 cmd->func = log_deprecated_func;
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200983 cmd->doc = LEVEL_STR
Harald Welte11eb4b52018-06-09 17:41:31 +0200984 "Deprecated Category\n";
985 cmd->attr = CMD_ATTR_DEPRECATED;
986
987 install_element(CFG_LOG_NODE, cmd);
988}
989
Harald Welte8c648252017-10-16 15:17:03 +0200990/*! Register logging related commands to the VTY. Call this once from
991 * your application if you want to support those commands. */
Maxc65c5b42017-03-15 13:20:23 +0100992void logging_vty_add_cmds()
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200993{
994 install_element_ve(&enable_logging_cmd);
995 install_element_ve(&disable_logging_cmd);
996 install_element_ve(&logging_fltr_all_cmd);
997 install_element_ve(&logging_use_clr_cmd);
998 install_element_ve(&logging_prnt_timestamp_cmd);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100999 install_element_ve(&logging_prnt_ext_timestamp_cmd);
1000 install_element_ve(&logging_prnt_cat_cmd);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +01001001 install_element_ve(&logging_prnt_cat_hex_cmd);
Neels Hofmeyr886e5482018-01-16 01:49:37 +01001002 install_element_ve(&logging_prnt_level_cmd);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +01001003 install_element_ve(&logging_prnt_file_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001004 install_element_ve(&logging_set_category_mask_cmd);
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +02001005 install_element_ve(&logging_set_category_mask_old_cmd);
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +01001006
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001007 /* logging level (<categories>) (debug|...|fatal) */
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001008 gen_logging_level_cmd_strs(&logging_level_cmd,
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001009 LOG_LEVEL_ARGS,
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001010 LOG_LEVEL_STRS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001011 /* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001012 gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd,
1013 "everything", EVERYTHING_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001014
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001015 install_element_ve(&logging_level_cmd);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +02001016 install_element_ve(&logging_level_set_all_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001017 install_element_ve(&logging_level_force_all_cmd);
1018 install_element_ve(&no_logging_level_force_all_cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001019 install_element_ve(&deprecated_logging_level_everything_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001020 install_element_ve(&deprecated_logging_level_all_cmd);
1021 install_element_ve(&deprecated_logging_level_all_everything_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001022 install_element_ve(&show_logging_vty_cmd);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001023 install_element_ve(&show_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001024
1025 install_node(&cfg_log_node, config_write_log);
Harald Weltea62648b2011-02-18 21:03:27 +01001026 install_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
1027 install_element(CFG_LOG_NODE, &logging_use_clr_cmd);
1028 install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001029 install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd);
1030 install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +01001031 install_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd);
Neels Hofmeyr886e5482018-01-16 01:49:37 +01001032 install_element(CFG_LOG_NODE, &logging_prnt_level_cmd);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +01001033 install_element(CFG_LOG_NODE, &logging_prnt_file_cmd);
Harald Weltea62648b2011-02-18 21:03:27 +01001034 install_element(CFG_LOG_NODE, &logging_level_cmd);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +02001035 install_element(CFG_LOG_NODE, &logging_level_set_all_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001036 install_element(CFG_LOG_NODE, &logging_level_force_all_cmd);
1037 install_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001038 install_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001039 install_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd);
1040 install_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001041
1042 install_element(CONFIG_NODE, &cfg_log_stderr_cmd);
1043 install_element(CONFIG_NODE, &cfg_no_log_stderr_cmd);
1044 install_element(CONFIG_NODE, &cfg_log_file_cmd);
1045 install_element(CONFIG_NODE, &cfg_no_log_file_cmd);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001046 install_element(CONFIG_NODE, &cfg_log_alarms_cmd);
1047 install_element(CONFIG_NODE, &cfg_no_log_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001048#ifdef HAVE_SYSLOG_H
1049 install_element(CONFIG_NODE, &cfg_log_syslog_cmd);
1050 install_element(CONFIG_NODE, &cfg_log_syslog_local_cmd);
1051 install_element(CONFIG_NODE, &cfg_no_log_syslog_cmd);
1052#endif
Harald Welteaa00f992016-12-02 15:30:02 +01001053 install_element(CONFIG_NODE, &cfg_log_gsmtap_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001054}