libosmovty  0.9.6.20171026
Osmocom VTY library
logging_vty.c File Reference

Configuration of logging from VTY. More...

#include <stdlib.h>
#include <string.h>
#include "../../config.h"
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/strrb.h>
#include <osmocom/core/loggingrb.h>
#include <osmocom/core/gsmtap.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
#include <syslog.h>

Macros

#define LOG_STR   "Configure logging sub-system\n"
 
#define SHOW_LOG_STR   "Show current logging configuration\n"
 

Functions

static void _vty_output (struct log_target *tgt, unsigned int level, const char *line)
 
struct log_targetlog_target_create_vty (struct vty *vty)
 
 DEFUN (enable_logging, enable_logging_cmd, "logging enable", LOGGING_STR "Enables logging to this vty\)
 
struct log_targetosmo_log_vty2tgt (struct vty *vty)
 
 DEFUN (logging_fltr_all, logging_fltr_all_cmd, "logging filter all (0|1)", LOGGING_STR FILTER_STR "Do you want to log all messages?\ "Only print messages matched by other filters\" "Bypass filter and print all messages\")
 
 DEFUN (logging_use_clr, logging_use_clr_cmd, "logging color (0|1)", LOGGING_STR "Configure color-printing for log messages\ "Don 't use color for printing messages\" "Use color for printing messages\")
 
 DEFUN (logging_prnt_timestamp, logging_prnt_timestamp_cmd, "logging timestamp (0|1)", LOGGING_STR "Configure log message timestamping\ "Don 't prefix each log message\" "Prefix each log message with current timestamp\")
 
 DEFUN (logging_prnt_ext_timestamp, logging_prnt_ext_timestamp_cmd, "logging print extended-timestamp (0|1)", LOGGING_STR "Log output settings\ "Configure log message timestamping\" "Don 't prefix each log message\" "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\")
 
 DEFUN (logging_prnt_cat, logging_prnt_cat_cmd, "logging print category (0|1)", LOGGING_STR "Log output settings\ "Configure log message\" "Don 't prefix each log message\" "Prefix each log message with category/subsystem name\")
 
 DEFUN (logging_level, logging_level_cmd, NULL, NULL)
 
 DEFUN (logging_set_category_mask, logging_set_category_mask_cmd, "logging set-log-mask MASK", LOGGING_STR "Set the logmask of this logging target\ "The logmask to use\")
 
 ALIAS_DEPRECATED (logging_set_category_mask, logging_set_category_mask_old_cmd, "logging set log mask MASK", LOGGING_STR "Decide which categories to output.\ "Log commands\" "Mask commands\" "The logmask to use\")
 
 DEFUN (diable_logging, disable_logging_cmd, "logging disable", LOGGING_STR "Disables logging to this vty\)
 
static void vty_print_logtarget (struct vty *vty, const struct log_info *info, const struct log_target *tgt)
 
 DEFUN (show_logging_vty, show_logging_vty_cmd, "show logging vty", SHOW_STR SHOW_LOG_STR "Show current logging configuration for this vty\)
 
 DEFUN (show_alarms, show_alarms_cmd, "show alarms", SHOW_STR SHOW_LOG_STR "Show the contents of the logging ringbuffer\)
 
 gDEFUN (cfg_description, cfg_description_cmd, "description .TEXT", "Save human-readable description of the object\ "Text until the end of the line\")
 
 gDEFUN (cfg_no_description, cfg_no_description_cmd, "no description", NO_STR "Remove description of the object\)
 
static int _cfg_log_syslog (struct vty *vty, int facility)
 
 DEFUN (cfg_log_syslog_local, cfg_log_syslog_local_cmd, "log syslog local <0-7>", LOG_STR "Logging via syslog\ "Syslog LOCAL facility\" "Local facility number\")
 
 DEFUN (cfg_log_syslog, cfg_log_syslog_cmd, "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)", LOG_STR "Logging via syslog\ "Security/authorization messages facility\" "Clock daemon(cron/at) facility\" "General system daemon facility\" "Ftp daemon facility\" "Line printer facility\" "Mail facility\" "News facility\" "Generic facility\" "UUCP facility\")
 
 DEFUN (cfg_no_log_syslog, cfg_no_log_syslog_cmd, "no log syslog", NO_STR LOG_STR "Logging via syslog\)
 
 DEFUN (cfg_log_gsmtap, cfg_log_gsmtap_cmd, "log gsmtap [HOSTNAME]", LOG_STR "Logging via GSMTAP\ "Host name to send the GSMTAP logging to(UDP port 4729)\")
 
 DEFUN (cfg_log_stderr, cfg_log_stderr_cmd, "log stderr", LOG_STR "Logging via STDERR of the process\)
 
 DEFUN (cfg_no_log_stderr, cfg_no_log_stderr_cmd, "no log stderr", NO_STR LOG_STR "Logging via STDERR of the process\)
 
 DEFUN (cfg_log_file, cfg_log_file_cmd, "log file .FILENAME", LOG_STR "Logging to text file\ "Filename\")
 
 DEFUN (cfg_no_log_file, cfg_no_log_file_cmd, "no log file .FILENAME", NO_STR LOG_STR "Logging to text file\ "Filename\")
 
 DEFUN (cfg_log_alarms, cfg_log_alarms_cmd, "log alarms <2-32700>", LOG_STR "Logging alarms to osmo_strrb\ "Maximum number of messages to log\")
 
 DEFUN (cfg_no_log_alarms, cfg_no_log_alarms_cmd, "no log alarms", NO_STR LOG_STR "Logging alarms to osmo_strrb\)
 
static int config_write_log_single (struct vty *vty, struct log_target *tgt)
 
static int config_write_log (struct vty *vty)
 
void logging_vty_add_cmds ()
 Register logging related commands to the VTY. More...
 

Variables

const struct log_infoosmo_log_info
 
struct cmd_node cfg_log_node
 
static const int local_sysl_map []
 
struct host host
 
static struct value_string sysl_level_names []
 

Detailed Description

Configuration of logging from VTY.

This module implements

  • functions that permit configuration of the libosmocore logging framework from VTY commands in the configure -> logging node.
  • functions that permit logging to a VTY session. Basically each VTY session gets its own log target, with configurable per-subsystem log levels. This is performed internally via the log_target_create_vty function.

You have to call logging_vty_add_cmds from your application once to enable both of the above.

Macro Definition Documentation

◆ LOG_STR

#define LOG_STR   "Configure logging sub-system\n"

◆ SHOW_LOG_STR

#define SHOW_LOG_STR   "Show current logging configuration\n"

Function Documentation

◆ _cfg_log_syslog()

◆ _vty_output()

static void _vty_output ( struct log_target tgt,
unsigned int  level,
const char *  line 
)
static

References log_target::tgt_vty, and vty_out().

Referenced by log_target_create_vty().

◆ ALIAS_DEPRECATED()

ALIAS_DEPRECATED ( logging_set_category_mask  ,
logging_set_category_mask_old_cmd  ,
"logging set log mask MASK"  ,
LOGGING_STR "Decide which categories to output.\Log commands\ "Mask commands\" "The logmask to use\"   
)

Referenced by DEFUN().

◆ config_write_log()

static int config_write_log ( struct vty vty)
static

◆ config_write_log_single()

◆ DEFUN() [1/21]

DEFUN ( enable_logging  ,
enable_logging_cmd  ,
"logging enable"  ,
LOGGING_STR "Enables logging to this vty\   
)

◆ DEFUN() [2/21]

DEFUN ( logging_fltr_all  ,
logging_fltr_all_cmd  ,
"logging filter all (0|1)"  ,
LOGGING_STR FILTER_STR "Do you want to log all messages?\ "Only print messages matched by other filters\" "Bypass filter and print all messages\"   
)

◆ DEFUN() [3/21]

DEFUN ( logging_use_clr  ,
logging_use_clr_cmd  ,
"logging color (0|1)"  ,
LOGGING_STR "Configure color-printing for log messages\ "Don 't use color for printing messages\" "Use color for printing messages\"   
)

◆ DEFUN() [4/21]

DEFUN ( logging_prnt_timestamp  ,
logging_prnt_timestamp_cmd  ,
"logging timestamp (0|1)"  ,
LOGGING_STR "Configure log message timestamping\ "Don 't prefix each log message\" "Prefix each log message with current timestamp\"   
)

◆ DEFUN() [5/21]

DEFUN ( logging_prnt_ext_timestamp  ,
logging_prnt_ext_timestamp_cmd  ,
"logging print extended-timestamp (0|1)"  ,
LOGGING_STR "Log output settings\ "Configure log message timestamping\" "Don 't prefix each log message\" "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\"   
)

◆ DEFUN() [6/21]

DEFUN ( logging_prnt_cat  ,
logging_prnt_cat_cmd  ,
"logging print category (0|1)"  ,
LOGGING_STR "Log output settings\ "Configure log message\" "Don 't prefix each log message\" "Prefix each log message with category/subsystem name\"   
)

◆ DEFUN() [7/21]

◆ DEFUN() [8/21]

DEFUN ( logging_set_category_mask  ,
logging_set_category_mask_cmd  ,
"logging set-log-mask MASK"  ,
LOGGING_STR "Set the logmask of this logging target\ "The logmask to use\"   
)

◆ DEFUN() [9/21]

DEFUN ( diable_logging  ,
disable_logging_cmd  ,
"logging disable"  ,
LOGGING_STR "Disables logging to this vty\   
)

◆ DEFUN() [10/21]

DEFUN ( show_logging_vty  ,
show_logging_vty_cmd  ,
"show logging vty ,
SHOW_STR SHOW_LOG_STR "Show current logging configuration for this vty\   
)

◆ DEFUN() [11/21]

DEFUN ( show_alarms  ,
show_alarms_cmd  ,
"show alarms"  ,
SHOW_STR SHOW_LOG_STR "Show the contents of the logging ringbuffer\   
)

◆ DEFUN() [12/21]

DEFUN ( cfg_log_syslog_local  ,
cfg_log_syslog_local_cmd  ,
"log syslog local <0-7>"  ,
LOG_STR "Logging via syslog\ "Syslog LOCAL facility\" "Local facility number\"   
)

◆ DEFUN() [13/21]

DEFUN ( cfg_log_syslog  ,
cfg_log_syslog_cmd  ,
"log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)"  ,
LOG_STR "Logging via syslog\ "Security/authorization messages facility\" "Clock daemon(cron/at) facility\" "General system daemon facility\" "Ftp daemon facility\" "Line printer facility\" "Mail facility\" "News facility\" "Generic facility\" "UUCP facility\"   
)

◆ DEFUN() [14/21]

DEFUN ( cfg_no_log_syslog  ,
cfg_no_log_syslog_cmd  ,
"no log syslog"  ,
NO_STR LOG_STR "Logging via syslog\   
)

◆ DEFUN() [15/21]

DEFUN ( cfg_log_gsmtap  ,
cfg_log_gsmtap_cmd  ,
"log gsmtap "  [HOSTNAME],
LOG_STR "Logging via GSMTAP\ "Host name to send the GSMTAP logging to(UDP port 4729)\"   
)

◆ DEFUN() [16/21]

DEFUN ( cfg_log_stderr  ,
cfg_log_stderr_cmd  ,
"log stderr"  ,
LOG_STR "Logging via STDERR of the process\   
)

◆ DEFUN() [17/21]

DEFUN ( cfg_no_log_stderr  ,
cfg_no_log_stderr_cmd  ,
"no log stderr"  ,
NO_STR LOG_STR "Logging via STDERR of the process\   
)

◆ DEFUN() [18/21]

DEFUN ( cfg_log_file  ,
cfg_log_file_cmd  ,
"log file .FILENAME"  ,
LOG_STR "Logging to text file\ "Filename\"   
)

◆ DEFUN() [19/21]

DEFUN ( cfg_no_log_file  ,
cfg_no_log_file_cmd  ,
"no log file .FILENAME"  ,
NO_STR LOG_STR "Logging to text file\ "Filename\"   
)

◆ DEFUN() [20/21]

DEFUN ( cfg_log_alarms  ,
cfg_log_alarms_cmd  ,
"log alarms <2-32700>"  ,
LOG_STR "Logging alarms to osmo_strrb\ "Maximum number of messages to log\"   
)

◆ DEFUN() [21/21]

DEFUN ( cfg_no_log_alarms  ,
cfg_no_log_alarms_cmd  ,
"no log alarms"  ,
NO_STR LOG_STR "Logging alarms to osmo_strrb\   
)

◆ gDEFUN() [1/2]

gDEFUN ( cfg_description  ,
cfg_description_cmd  ,
"description .TEXT"  ,
"Save human-readable description of the object\ "Text until the end of the line\"   
)

◆ gDEFUN() [2/2]

gDEFUN ( cfg_no_description  ,
cfg_no_description_cmd  ,
"no description"  ,
NO_STR "Remove description of the object\   
)

◆ log_target_create_vty()

struct log_target* log_target_create_vty ( struct vty vty)

◆ logging_vty_add_cmds()

void logging_vty_add_cmds ( )

Register logging related commands to the VTY.

Call this once from your application if you want to support those commands.

References CFG_LOG_NODE, CONFIG_NODE, config_write_log(), install_element(), install_element_ve(), install_node(), log_vty_command_description(), and log_vty_command_string().

◆ osmo_log_vty2tgt()

struct log_target* osmo_log_vty2tgt ( struct vty vty)

◆ vty_print_logtarget()

Variable Documentation

◆ cfg_log_node

struct cmd_node cfg_log_node
Initial value:
= {
"%s(config-log)# ",
1
}
Configure the logging.
Definition: command.h:79

◆ local_sysl_map

const int local_sysl_map[]
static
Initial value:
= {
[0] = LOG_LOCAL0,
[1] = LOG_LOCAL1,
[2] = LOG_LOCAL2,
[3] = LOG_LOCAL3,
[4] = LOG_LOCAL4,
[5] = LOG_LOCAL5,
[6] = LOG_LOCAL6,
[7] = LOG_LOCAL7
}

Referenced by DEFUN().

◆ sysl_level_names

struct value_string sysl_level_names[]
static
Initial value:
= {
{ LOG_AUTHPRIV, "authpriv" },
{ LOG_CRON, "cron" },
{ LOG_DAEMON, "daemon" },
{ LOG_FTP, "ftp" },
{ LOG_LPR, "lpr" },
{ LOG_MAIL, "mail" },
{ LOG_NEWS, "news" },
{ LOG_USER, "user" },
{ LOG_UUCP, "uucp" },
{ LOG_LOCAL0, "local 0" },
{ LOG_LOCAL1, "local 1" },
{ LOG_LOCAL2, "local 2" },
{ LOG_LOCAL3, "local 3" },
{ LOG_LOCAL4, "local 4" },
{ LOG_LOCAL5, "local 5" },
{ LOG_LOCAL6, "local 6" },
{ LOG_LOCAL7, "local 7" },
{ 0, NULL }
}