blob: b2637a5fbfeddcc076d7a9bf7de114888adc7a2f [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;
367 for (i = 0; i < osmo_log_info->num_cat; i++) {
368 struct log_category *cat = &tgt->categories[i];
369 /* skip empty entries in the array */
370 if (!osmo_log_info->cat[i].name)
371 continue;
372
373 cat->enabled = 1;
374 cat->loglevel = level;
375 }
376 return CMD_SUCCESS;
377}
378
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200379/* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200380DEFUN_DEPRECATED(deprecated_logging_level_everything, deprecated_logging_level_everything_cmd,
381 NULL, /* cmdstr is dynamically set in logging_vty_add_cmds(). */
382 NULL) /* same thing for helpstr. */
383{
384 vty_out(vty, "%% Ignoring deprecated logging level 'everything' keyword%s", VTY_NEWLINE);
385 return CMD_SUCCESS;
386}
387
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200388DEFUN(logging_level_force_all, logging_level_force_all_cmd,
389 "logging level force-all " LOG_LEVEL_ARGS,
390 LOGGING_STR LEVEL_STR FORCE_ALL_STR LOG_LEVEL_STRS)
391{
392 struct log_target *tgt = osmo_log_vty2tgt(vty);
393 int level = log_parse_level(argv[0]);
394 log_set_log_level(tgt, level);
395 return CMD_SUCCESS;
396}
397
398DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd,
399 "no logging level force-all",
400 NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)
401{
402 struct log_target *tgt = osmo_log_vty2tgt(vty);
403 log_set_log_level(tgt, 0);
404 return CMD_SUCCESS;
405}
406
407/* 'logging level all (debug|...|fatal)' */
408ALIAS_DEPRECATED(logging_level_force_all, deprecated_logging_level_all_cmd,
409 "logging level all " LOG_LEVEL_ARGS,
410 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR LOG_LEVEL_STRS);
411
412/* 'logging level all everything' */
413ALIAS_DEPRECATED(no_logging_level_force_all, deprecated_logging_level_all_everything_cmd,
414 "logging level all everything",
415 LOGGING_STR LEVEL_STR CATEGORY_ALL_STR EVERYTHING_STR);
416
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200417DEFUN(logging_set_category_mask,
418 logging_set_category_mask_cmd,
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200419 "logging set-log-mask MASK",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200420 LOGGING_STR
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200421 "Set the logmask of this logging target\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100422 "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific"
423 " application, refer to the 'logging level' command. Optionally add individual log levels like"
424 " 'abc,1:mno,3:xyz,5', where the level numbers are"
425 " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG)
426 " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO)
427 " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE)
428 " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR)
429 " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL)
430 "\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200431{
Harald Weltea62648b2011-02-18 21:03:27 +0100432 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200433
Harald Weltea62648b2011-02-18 21:03:27 +0100434 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200435 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200436
Harald Weltea62648b2011-02-18 21:03:27 +0100437 log_parse_category_mask(tgt, argv[0]);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200438 return CMD_SUCCESS;
439}
440
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200441ALIAS_DEPRECATED(logging_set_category_mask,
442 logging_set_category_mask_old_cmd,
443 "logging set log mask MASK",
444 LOGGING_STR
445 "Decide which categories to output.\n"
Neels Hofmeyr84ea2e02017-12-09 05:53:18 +0100446 "Log commands\n" "Mask commands\n"
447 "'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 +0200448
449
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200450DEFUN(diable_logging,
451 disable_logging_cmd,
452 "logging disable",
453 LOGGING_STR
454 "Disables logging to this vty\n")
455{
Harald Weltea62648b2011-02-18 21:03:27 +0100456 struct log_target *tgt = osmo_log_vty2tgt(vty);
457 struct telnet_connection *conn = (struct telnet_connection *) vty->priv;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200458
Harald Weltea62648b2011-02-18 21:03:27 +0100459 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200460 return CMD_WARNING;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200461
Harald Weltea62648b2011-02-18 21:03:27 +0100462 log_del_target(tgt);
463 talloc_free(tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200464 conn->dbg = NULL;
Harald Weltea62648b2011-02-18 21:03:27 +0100465
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200466 return CMD_SUCCESS;
467}
468
469static void vty_print_logtarget(struct vty *vty, const struct log_info *info,
470 const struct log_target *tgt)
471{
472 unsigned int i;
473
474 vty_out(vty, " Global Loglevel: %s%s",
475 log_level_str(tgt->loglevel), VTY_NEWLINE);
476 vty_out(vty, " Use color: %s, Print Timestamp: %s%s",
477 tgt->use_color ? "On" : "Off",
478 tgt->print_timestamp ? "On" : "Off", VTY_NEWLINE);
479
480 vty_out(vty, " Log Level specific information:%s", VTY_NEWLINE);
481
482 for (i = 0; i < info->num_cat; i++) {
483 const struct log_category *cat = &tgt->categories[i];
Daniel Willmann55363a92016-11-15 10:05:51 +0100484 /* Skip categories that were not initialized */
485 if (!info->cat[i].name)
486 continue;
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200487 vty_out(vty, " %-10s %-10s %-8s %s%s",
488 info->cat[i].name+1, log_level_str(cat->loglevel),
489 cat->enabled ? "Enabled" : "Disabled",
490 info->cat[i].description,
491 VTY_NEWLINE);
492 }
Harald Welte6d2d4d62013-03-10 09:53:24 +0000493
494 vty_out(vty, " Log Filter 'ALL': %s%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100495 tgt->filter_map & (1 << LOG_FLT_ALL) ? "Enabled" : "Disabled",
Harald Welte6d2d4d62013-03-10 09:53:24 +0000496 VTY_NEWLINE);
497
Harald Weltefb84f322013-06-06 07:33:54 +0200498 /* print application specific filters */
499 if (info->print_fn)
500 info->print_fn(vty, info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200501}
502
503#define SHOW_LOG_STR "Show current logging configuration\n"
504
505DEFUN(show_logging_vty,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000506 show_logging_vty_cmd,
507 "show logging vty",
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200508 SHOW_STR SHOW_LOG_STR
509 "Show current logging configuration for this vty\n")
510{
Harald Weltea62648b2011-02-18 21:03:27 +0100511 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200512
Harald Weltea62648b2011-02-18 21:03:27 +0100513 if (!tgt)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200514 return CMD_WARNING;
Harald Weltea62648b2011-02-18 21:03:27 +0100515
516 vty_print_logtarget(vty, osmo_log_info, tgt);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200517
518 return CMD_SUCCESS;
519}
520
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000521DEFUN(show_alarms,
522 show_alarms_cmd,
523 "show alarms",
524 SHOW_STR SHOW_LOG_STR
525 "Show the contents of the logging ringbuffer\n")
526{
527 int i, num_alarms;
528 struct osmo_strrb *rb;
529 struct log_target *tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
530 if (!tgt) {
531 vty_out(vty, "%% No alarms, run 'log alarms <2-32700>'%s",
532 VTY_NEWLINE);
533 return CMD_WARNING;
534 }
535
536 rb = tgt->tgt_rb.rb;
537 num_alarms = osmo_strrb_elements(rb);
538
539 vty_out(vty, "%% Showing %i alarms%s", num_alarms, VTY_NEWLINE);
540
541 for (i = 0; i < num_alarms; i++)
542 vty_out(vty, "%% %s%s", osmo_strrb_get_nth(rb, i),
543 VTY_NEWLINE);
544
545 return CMD_SUCCESS;
546}
547
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200548gDEFUN(cfg_description, cfg_description_cmd,
549 "description .TEXT",
Thorsten Alteholza81055d2017-03-02 22:13:48 +0100550 "Save human-readable description of the object\n"
Holger Hans Peter Freytherc9b3e062012-07-25 13:02:49 +0200551 "Text until the end of the line\n")
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200552{
553 char **dptr = vty->index_sub;
554
555 if (!dptr) {
556 vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
557 return CMD_WARNING;
558 }
559
Holger Hans Peter Freytherff0670e2011-02-24 14:20:41 +0100560 if (*dptr)
561 talloc_free(*dptr);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200562 *dptr = argv_concat(argv, argc, 0);
Holger Hans Peter Freyther6a75d162013-07-14 09:07:11 +0200563 if (!*dptr)
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200564 return CMD_WARNING;
565
566 return CMD_SUCCESS;
567}
568
569gDEFUN(cfg_no_description, cfg_no_description_cmd,
570 "no description",
571 NO_STR
572 "Remove description of the object\n")
573{
574 char **dptr = vty->index_sub;
575
576 if (!dptr) {
577 vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
578 return CMD_WARNING;
579 }
580
581 if (*dptr) {
582 talloc_free(*dptr);
583 *dptr = NULL;
584 }
585
586 return CMD_SUCCESS;
587}
588
Harald Welte28222962011-02-18 20:37:04 +0100589/* Support for configuration of log targets != the current vty */
590
591struct cmd_node cfg_log_node = {
592 CFG_LOG_NODE,
593 "%s(config-log)# ",
594 1
595};
596
Harald Welte28222962011-02-18 20:37:04 +0100597#ifdef HAVE_SYSLOG_H
598
599#include <syslog.h>
600
601static const int local_sysl_map[] = {
602 [0] = LOG_LOCAL0,
603 [1] = LOG_LOCAL1,
604 [2] = LOG_LOCAL2,
605 [3] = LOG_LOCAL3,
606 [4] = LOG_LOCAL4,
607 [5] = LOG_LOCAL5,
608 [6] = LOG_LOCAL6,
609 [7] = LOG_LOCAL7
610};
611
Harald Weltede79cee2011-02-24 23:47:57 +0100612/* From VTY core code */
613extern struct host host;
614
Harald Welte28222962011-02-18 20:37:04 +0100615static int _cfg_log_syslog(struct vty *vty, int facility)
616{
617 struct log_target *tgt;
618
619 /* First delete the old syslog target, if any */
620 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
621 if (tgt)
622 log_target_destroy(tgt);
623
Harald Weltede79cee2011-02-24 23:47:57 +0100624 tgt = log_target_create_syslog(host.app_info->name, 0, facility);
Harald Welte28222962011-02-18 20:37:04 +0100625 if (!tgt) {
626 vty_out(vty, "%% Unable to open syslog%s", VTY_NEWLINE);
627 return CMD_WARNING;
628 }
629 log_add_target(tgt);
630
631 vty->index = tgt;
632 vty->node = CFG_LOG_NODE;
633
634 return CMD_SUCCESS;
635}
636
637DEFUN(cfg_log_syslog_local, cfg_log_syslog_local_cmd,
638 "log syslog local <0-7>",
639 LOG_STR "Logging via syslog\n" "Syslog LOCAL facility\n"
640 "Local facility number\n")
641{
642 int local = atoi(argv[0]);
643 int facility = local_sysl_map[local];
644
645 return _cfg_log_syslog(vty, facility);
646}
647
648static struct value_string sysl_level_names[] = {
649 { LOG_AUTHPRIV, "authpriv" },
650 { LOG_CRON, "cron" },
651 { LOG_DAEMON, "daemon" },
652 { LOG_FTP, "ftp" },
653 { LOG_LPR, "lpr" },
654 { LOG_MAIL, "mail" },
655 { LOG_NEWS, "news" },
656 { LOG_USER, "user" },
657 { LOG_UUCP, "uucp" },
658 /* only for value -> string conversion */
659 { LOG_LOCAL0, "local 0" },
660 { LOG_LOCAL1, "local 1" },
661 { LOG_LOCAL2, "local 2" },
662 { LOG_LOCAL3, "local 3" },
663 { LOG_LOCAL4, "local 4" },
664 { LOG_LOCAL5, "local 5" },
665 { LOG_LOCAL6, "local 6" },
666 { LOG_LOCAL7, "local 7" },
667 { 0, NULL }
668};
669
670DEFUN(cfg_log_syslog, cfg_log_syslog_cmd,
671 "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)",
Holger Hans Peter Freythera4463fd2011-10-03 23:17:36 +0200672 LOG_STR "Logging via syslog\n"
673 "Security/authorization messages facility\n"
674 "Clock daemon (cron/at) facility\n"
675 "General system daemon facility\n"
676 "Ftp daemon facility\n"
677 "Line printer facility\n"
678 "Mail facility\n"
679 "News facility\n"
680 "Generic facility\n"
681 "UUCP facility\n")
Harald Welte28222962011-02-18 20:37:04 +0100682{
683 int facility = get_string_value(sysl_level_names, argv[0]);
684
685 return _cfg_log_syslog(vty, facility);
686}
687
688DEFUN(cfg_no_log_syslog, cfg_no_log_syslog_cmd,
689 "no log syslog",
690 NO_STR LOG_STR "Logging via syslog\n")
691{
692 struct log_target *tgt;
693
694 tgt = log_target_find(LOG_TGT_TYPE_SYSLOG, NULL);
695 if (!tgt) {
696 vty_out(vty, "%% No syslog target found%s",
697 VTY_NEWLINE);
698 return CMD_WARNING;
699 }
700
701 log_target_destroy(tgt);
702
703 return CMD_SUCCESS;
704}
705#endif /* HAVE_SYSLOG_H */
706
Harald Welteaa00f992016-12-02 15:30:02 +0100707DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
708 "log gsmtap [HOSTNAME]",
Neels Hofmeyrfd9ec3b2016-12-11 01:48:26 +0100709 LOG_STR "Logging via GSMTAP\n"
710 "Host name to send the GSMTAP logging to (UDP port 4729)\n")
Harald Welteaa00f992016-12-02 15:30:02 +0100711{
Max2f153b52018-01-04 12:25:57 +0100712 const char *hostname = argc ? argv[0] : "127.0.0.1";
Harald Welteaa00f992016-12-02 15:30:02 +0100713 struct log_target *tgt;
714
715 tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
716 if (!tgt) {
717 tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT,
718 host.app_info->name, false,
719 true);
720 if (!tgt) {
Max2f153b52018-01-04 12:25:57 +0100721 vty_out(vty, "%% Unable to create GSMTAP log for %s%s",
722 hostname, VTY_NEWLINE);
Harald Welteaa00f992016-12-02 15:30:02 +0100723 return CMD_WARNING;
724 }
725 log_add_target(tgt);
726 }
727
728 vty->index = tgt;
729 vty->node = CFG_LOG_NODE;
730
731 return CMD_SUCCESS;
732}
733
Harald Welte28222962011-02-18 20:37:04 +0100734DEFUN(cfg_log_stderr, cfg_log_stderr_cmd,
735 "log stderr",
736 LOG_STR "Logging via STDERR of the process\n")
737{
738 struct log_target *tgt;
739
740 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
741 if (!tgt) {
742 tgt = log_target_create_stderr();
743 if (!tgt) {
744 vty_out(vty, "%% Unable to create stderr log%s",
745 VTY_NEWLINE);
746 return CMD_WARNING;
747 }
748 log_add_target(tgt);
749 }
750
751 vty->index = tgt;
752 vty->node = CFG_LOG_NODE;
753
754 return CMD_SUCCESS;
755}
756
757DEFUN(cfg_no_log_stderr, cfg_no_log_stderr_cmd,
758 "no log stderr",
759 NO_STR LOG_STR "Logging via STDERR of the process\n")
760{
761 struct log_target *tgt;
762
763 tgt = log_target_find(LOG_TGT_TYPE_STDERR, NULL);
764 if (!tgt) {
765 vty_out(vty, "%% No stderr logging active%s", VTY_NEWLINE);
766 return CMD_WARNING;
767 }
768
769 log_target_destroy(tgt);
770
771 return CMD_SUCCESS;
772}
773
774DEFUN(cfg_log_file, cfg_log_file_cmd,
775 "log file .FILENAME",
776 LOG_STR "Logging to text file\n" "Filename\n")
777{
778 const char *fname = argv[0];
779 struct log_target *tgt;
780
781 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
782 if (!tgt) {
783 tgt = log_target_create_file(fname);
784 if (!tgt) {
785 vty_out(vty, "%% Unable to create file `%s'%s",
786 fname, VTY_NEWLINE);
787 return CMD_WARNING;
788 }
789 log_add_target(tgt);
790 }
791
792 vty->index = tgt;
793 vty->node = CFG_LOG_NODE;
794
795 return CMD_SUCCESS;
796}
797
798
799DEFUN(cfg_no_log_file, cfg_no_log_file_cmd,
800 "no log file .FILENAME",
801 NO_STR LOG_STR "Logging to text file\n" "Filename\n")
802{
803 const char *fname = argv[0];
804 struct log_target *tgt;
805
806 tgt = log_target_find(LOG_TGT_TYPE_FILE, fname);
807 if (!tgt) {
808 vty_out(vty, "%% No such log file `%s'%s",
809 fname, VTY_NEWLINE);
810 return CMD_WARNING;
811 }
812
813 log_target_destroy(tgt);
814
815 return CMD_SUCCESS;
816}
817
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000818DEFUN(cfg_log_alarms, cfg_log_alarms_cmd,
819 "log alarms <2-32700>",
820 LOG_STR "Logging alarms to osmo_strrb\n"
821 "Maximum number of messages to log\n")
822{
823 struct log_target *tgt;
824 unsigned int rbsize = atoi(argv[0]);
825
826 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
827 if (tgt)
828 log_target_destroy(tgt);
829
830 tgt = log_target_create_rb(rbsize);
831 if (!tgt) {
832 vty_out(vty, "%% Unable to create osmo_strrb (size %u)%s",
833 rbsize, VTY_NEWLINE);
834 return CMD_WARNING;
835 }
836 log_add_target(tgt);
837
838 vty->index = tgt;
839 vty->node = CFG_LOG_NODE;
840
841 return CMD_SUCCESS;
842}
843
844DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd,
845 "no log alarms",
846 NO_STR LOG_STR "Logging alarms to osmo_strrb\n")
847{
848 struct log_target *tgt;
849
850 tgt = log_target_find(LOG_TGT_TYPE_STRRB, NULL);
851 if (!tgt) {
852 vty_out(vty, "%% No osmo_strrb target found%s", VTY_NEWLINE);
853 return CMD_WARNING;
854 }
855
856 log_target_destroy(tgt);
857
858 return CMD_SUCCESS;
859}
860
Harald Welte28222962011-02-18 20:37:04 +0100861static int config_write_log_single(struct vty *vty, struct log_target *tgt)
862{
863 int i;
Harald Welte28222962011-02-18 20:37:04 +0100864
865 switch (tgt->type) {
866 case LOG_TGT_TYPE_VTY:
867 return 1;
868 break;
869 case LOG_TGT_TYPE_STDERR:
870 vty_out(vty, "log stderr%s", VTY_NEWLINE);
871 break;
872 case LOG_TGT_TYPE_SYSLOG:
873#ifdef HAVE_SYSLOG_H
874 vty_out(vty, "log syslog %s%s",
875 get_value_string(sysl_level_names,
876 tgt->tgt_syslog.facility),
877 VTY_NEWLINE);
878#endif
879 break;
880 case LOG_TGT_TYPE_FILE:
881 vty_out(vty, "log file %s%s", tgt->tgt_file.fname, VTY_NEWLINE);
882 break;
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +0000883 case LOG_TGT_TYPE_STRRB:
884 vty_out(vty, "log alarms %zu%s",
885 log_target_rb_avail_size(tgt), VTY_NEWLINE);
886 break;
Harald Welteaa00f992016-12-02 15:30:02 +0100887 case LOG_TGT_TYPE_GSMTAP:
888 vty_out(vty, "log gsmtap %s%s",
889 tgt->tgt_gsmtap.hostname, VTY_NEWLINE);
890 break;
Harald Welte28222962011-02-18 20:37:04 +0100891 }
892
Harald Welte2da47f12012-10-22 19:31:54 +0200893 vty_out(vty, " logging filter all %u%s",
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +0100894 tgt->filter_map & (1 << LOG_FLT_ALL) ? 1 : 0, VTY_NEWLINE);
Harald Weltefb84f322013-06-06 07:33:54 +0200895 /* save filters outside of libosmocore, i.e. in app code */
896 if (osmo_log_info->save_fn)
897 osmo_log_info->save_fn(vty, osmo_log_info, tgt);
Harald Welte2da47f12012-10-22 19:31:54 +0200898
Harald Welte28222962011-02-18 20:37:04 +0100899 vty_out(vty, " logging color %u%s", tgt->use_color ? 1 : 0,
900 VTY_NEWLINE);
Holger Hans Peter Freyther879acef2015-01-27 11:06:51 +0100901 vty_out(vty, " logging print category %d%s",
Michael McTernan78933462015-03-20 15:29:25 +0100902 tgt->print_category ? 1 : 0, VTY_NEWLINE);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100903 if (tgt->print_ext_timestamp)
904 vty_out(vty, " logging print extended-timestamp 1%s", VTY_NEWLINE);
905 else
906 vty_out(vty, " logging timestamp %u%s",
907 tgt->print_timestamp ? 1 : 0, VTY_NEWLINE);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100908 if (tgt->print_level)
909 vty_out(vty, " logging print level 1%s", VTY_NEWLINE);
Neels Hofmeyr22772cc2018-02-06 00:52:08 +0100910 vty_out(vty, " logging print file %s%s",
911 get_value_string(logging_print_file_args, tgt->print_filename2),
912 VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +0100913
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200914 if (tgt->loglevel) {
915 const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel);
916 level_str = osmo_str_tolower(level_str);
917 if (!level_str)
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200918 vty_out(vty, "%% Invalid log level %u for 'force-all'%s",
919 tgt->loglevel, VTY_NEWLINE);
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200920 else
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200921 vty_out(vty, " logging level force-all %s%s", level_str, VTY_NEWLINE);
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200922 }
Harald Welte28222962011-02-18 20:37:04 +0100923
924 for (i = 0; i < osmo_log_info->num_cat; i++) {
925 const struct log_category *cat = &tgt->categories[i];
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200926 const char *cat_name;
927 const char *level_str;
Harald Welte28222962011-02-18 20:37:04 +0100928
Harald Welte1a02cfc2013-03-19 10:37:39 +0100929 /* skip empty entries in the array */
930 if (!osmo_log_info->cat[i].name)
931 continue;
932
Neels Hofmeyr098038a2018-09-11 23:49:13 +0200933 /* Note: cat_name references the static buffer returned by osmo_str_tolower(), will
934 * become invalid after next osmo_str_tolower() invocation. */
935 cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1);
936
937 level_str = get_value_string_or_null(loglevel_strs, cat->loglevel);
938 if (!level_str) {
939 vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
940 VTY_NEWLINE);
941 continue;
942 }
943
944 vty_out(vty, " logging level %s", cat_name);
945 vty_out(vty, " %s%s", osmo_str_tolower(level_str), VTY_NEWLINE);
Harald Welte28222962011-02-18 20:37:04 +0100946 }
947
Harald Welte28222962011-02-18 20:37:04 +0100948 return 1;
949}
950
951static int config_write_log(struct vty *vty)
952{
953 struct log_target *dbg = vty->index;
954
955 llist_for_each_entry(dbg, &osmo_log_target_list, entry)
956 config_write_log_single(vty, dbg);
957
958 return 1;
959}
960
Harald Welte11eb4b52018-06-09 17:41:31 +0200961static int log_deprecated_func(struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[])
962{
963 vty_out(vty, "%% Ignoring deprecated '%s'%s", cmd->string, VTY_NEWLINE);
964 return CMD_WARNING;
965}
966
967void logging_vty_add_deprecated_subsys(void *ctx, const char *name)
968{
969 struct cmd_element *cmd = talloc_zero(ctx, struct cmd_element);
970 OSMO_ASSERT(cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +0200971 cmd->string = talloc_asprintf(cmd, "logging level %s (debug|info|notice|error|fatal)",
Harald Welte11eb4b52018-06-09 17:41:31 +0200972 name);
973 printf("%s\n", cmd->string);
974 cmd->func = log_deprecated_func;
Neels Hofmeyrba0762d2018-09-10 13:56:03 +0200975 cmd->doc = LEVEL_STR
Harald Welte11eb4b52018-06-09 17:41:31 +0200976 "Deprecated Category\n";
977 cmd->attr = CMD_ATTR_DEPRECATED;
978
979 install_element(CFG_LOG_NODE, cmd);
980}
981
Harald Welte8c648252017-10-16 15:17:03 +0200982/*! Register logging related commands to the VTY. Call this once from
983 * your application if you want to support those commands. */
Maxc65c5b42017-03-15 13:20:23 +0100984void logging_vty_add_cmds()
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200985{
986 install_element_ve(&enable_logging_cmd);
987 install_element_ve(&disable_logging_cmd);
988 install_element_ve(&logging_fltr_all_cmd);
989 install_element_ve(&logging_use_clr_cmd);
990 install_element_ve(&logging_prnt_timestamp_cmd);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +0100991 install_element_ve(&logging_prnt_ext_timestamp_cmd);
992 install_element_ve(&logging_prnt_cat_cmd);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +0100993 install_element_ve(&logging_prnt_cat_hex_cmd);
Neels Hofmeyr886e5482018-01-16 01:49:37 +0100994 install_element_ve(&logging_prnt_level_cmd);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +0100995 install_element_ve(&logging_prnt_file_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +0200996 install_element_ve(&logging_set_category_mask_cmd);
Holger Hans Peter Freyther146d1d32011-10-03 23:15:41 +0200997 install_element_ve(&logging_set_category_mask_old_cmd);
Pablo Neira Ayuso04139f12011-03-09 13:05:08 +0100998
Neels Hofmeyr9540c242018-09-12 00:20:50 +0200999 /* logging level (<categories>) (debug|...|fatal) */
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001000 gen_logging_level_cmd_strs(&logging_level_cmd,
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001001 LOG_LEVEL_ARGS,
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001002 LOG_LEVEL_STRS);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001003 /* logging level (<categories>) everything */
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001004 gen_logging_level_cmd_strs(&deprecated_logging_level_everything_cmd,
1005 "everything", EVERYTHING_STR);
Neels Hofmeyrba0762d2018-09-10 13:56:03 +02001006
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001007 install_element_ve(&logging_level_cmd);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +02001008 install_element_ve(&logging_level_set_all_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001009 install_element_ve(&logging_level_force_all_cmd);
1010 install_element_ve(&no_logging_level_force_all_cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001011 install_element_ve(&deprecated_logging_level_everything_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001012 install_element_ve(&deprecated_logging_level_all_cmd);
1013 install_element_ve(&deprecated_logging_level_all_everything_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001014 install_element_ve(&show_logging_vty_cmd);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001015 install_element_ve(&show_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001016
1017 install_node(&cfg_log_node, config_write_log);
Harald Weltea62648b2011-02-18 21:03:27 +01001018 install_element(CFG_LOG_NODE, &logging_fltr_all_cmd);
1019 install_element(CFG_LOG_NODE, &logging_use_clr_cmd);
1020 install_element(CFG_LOG_NODE, &logging_prnt_timestamp_cmd);
Holger Hans Peter Freyther2d6ad132014-12-05 09:35:30 +01001021 install_element(CFG_LOG_NODE, &logging_prnt_ext_timestamp_cmd);
1022 install_element(CFG_LOG_NODE, &logging_prnt_cat_cmd);
Neels Hofmeyrbd7bd392018-01-16 01:52:29 +01001023 install_element(CFG_LOG_NODE, &logging_prnt_cat_hex_cmd);
Neels Hofmeyr886e5482018-01-16 01:49:37 +01001024 install_element(CFG_LOG_NODE, &logging_prnt_level_cmd);
Neels Hofmeyrc6fd2452018-01-16 01:57:38 +01001025 install_element(CFG_LOG_NODE, &logging_prnt_file_cmd);
Harald Weltea62648b2011-02-18 21:03:27 +01001026 install_element(CFG_LOG_NODE, &logging_level_cmd);
Neels Hofmeyr28fc0782018-09-12 02:32:02 +02001027 install_element(CFG_LOG_NODE, &logging_level_set_all_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001028 install_element(CFG_LOG_NODE, &logging_level_force_all_cmd);
1029 install_element(CFG_LOG_NODE, &no_logging_level_force_all_cmd);
Neels Hofmeyr7e0686c2018-09-10 20:58:52 +02001030 install_element(CFG_LOG_NODE, &deprecated_logging_level_everything_cmd);
Neels Hofmeyr9540c242018-09-12 00:20:50 +02001031 install_element(CFG_LOG_NODE, &deprecated_logging_level_all_cmd);
1032 install_element(CFG_LOG_NODE, &deprecated_logging_level_all_everything_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001033
1034 install_element(CONFIG_NODE, &cfg_log_stderr_cmd);
1035 install_element(CONFIG_NODE, &cfg_no_log_stderr_cmd);
1036 install_element(CONFIG_NODE, &cfg_log_file_cmd);
1037 install_element(CONFIG_NODE, &cfg_no_log_file_cmd);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001038 install_element(CONFIG_NODE, &cfg_log_alarms_cmd);
1039 install_element(CONFIG_NODE, &cfg_no_log_alarms_cmd);
Harald Welte28222962011-02-18 20:37:04 +01001040#ifdef HAVE_SYSLOG_H
1041 install_element(CONFIG_NODE, &cfg_log_syslog_cmd);
1042 install_element(CONFIG_NODE, &cfg_log_syslog_local_cmd);
1043 install_element(CONFIG_NODE, &cfg_no_log_syslog_cmd);
1044#endif
Harald Welteaa00f992016-12-02 15:30:02 +01001045 install_element(CONFIG_NODE, &cfg_log_gsmtap_cmd);
Harald Welte3fb0b6f2010-05-19 19:02:52 +02001046}