libosmovty  0.12.0
Osmocom VTY library
logging_vty.c File Reference
#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_target * log_target_create_vty (struct vty *vty)
 
 DEFUN (enable_logging, enable_logging_cmd, "logging enable", LOGGING_STR "Enables logging to this vty\n")
 
struct log_target * osmo_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?\n" "Only print messages matched by other filters\n" "Bypass filter and print all messages\n")
 
 DEFUN (logging_use_clr, logging_use_clr_cmd, "logging color (0|1)", LOGGING_STR "Configure color-printing for log messages\n" "Don't use color for printing messages\n" "Use color for printing messages\n")
 
 DEFUN (logging_prnt_timestamp, logging_prnt_timestamp_cmd, "logging timestamp (0|1)", LOGGING_STR "Configure log message timestamping\n" "Don't prefix each log message\n" "Prefix each log message with current timestamp\n")
 
 DEFUN (logging_prnt_ext_timestamp, logging_prnt_ext_timestamp_cmd, "logging print extended-timestamp (0|1)", LOGGING_STR "Log output settings\n" "Configure log message timestamping\n" "Don't prefix each log message\n" "Prefix each log message with current timestamp with YYYYMMDDhhmmssnnn\n")
 
 DEFUN (logging_prnt_cat, logging_prnt_cat_cmd, "logging print category (0|1)", LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with category/subsystem name\n")
 
 DEFUN (logging_prnt_cat_hex, logging_prnt_cat_hex_cmd, "logging print category-hex (0|1)", LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with category/subsystem nr in hex ('<000b>')\n")
 
 DEFUN (logging_prnt_level, logging_prnt_level_cmd, "logging print level (0|1)", LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with the log level name\n")
 
 DEFUN (logging_prnt_file, logging_prnt_file_cmd, "logging print file (0|1|basename)", LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with the source file and line\n" "Prefix each log message with the source file's basename (strip leading paths) and line\n")
 
 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\n" "List of logging categories to log, e.g. 'abc:mno:xyz'. Available log categories depend on the specific" " application, refer to the 'logging level' command. Optionally add individual log levels like" " 'abc,1:mno,3:xyz,5', where the level numbers are" " " OSMO_STRINGIFY(LOGL_DEBUG) "=" OSMO_STRINGIFY_VAL(LOGL_DEBUG) " " OSMO_STRINGIFY(LOGL_INFO) "=" OSMO_STRINGIFY_VAL(LOGL_INFO) " " OSMO_STRINGIFY(LOGL_NOTICE) "=" OSMO_STRINGIFY_VAL(LOGL_NOTICE) " " OSMO_STRINGIFY(LOGL_ERROR) "=" OSMO_STRINGIFY_VAL(LOGL_ERROR) " " OSMO_STRINGIFY(LOGL_FATAL) "=" OSMO_STRINGIFY_VAL(LOGL_FATAL) "\n")
 
 ALIAS_DEPRECATED (logging_set_category_mask, logging_set_category_mask_old_cmd, "logging set log mask MASK", LOGGING_STR "Decide which categories to output.\n" "Log commands\n" "Mask commands\n" "'set log mask' is deprecated, please refer to the docs of 'set-log-mask' instead\n")
 
 DEFUN (diable_logging, disable_logging_cmd, "logging disable", LOGGING_STR "Disables logging to this vty\n")
 
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\n")
 
 DEFUN (show_alarms, show_alarms_cmd, "show alarms", SHOW_STR SHOW_LOG_STR "Show the contents of the logging ringbuffer\n")
 
 gDEFUN (cfg_description, cfg_description_cmd, "description .TEXT", "Save human-readable description of the object\n" "Text until the end of the line\n")
 
 gDEFUN (cfg_no_description, cfg_no_description_cmd, "no description", NO_STR "Remove description of the object\n")
 
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\n" "Syslog LOCAL facility\n" "Local facility number\n")
 
 DEFUN (cfg_log_syslog, cfg_log_syslog_cmd, "log syslog (authpriv|cron|daemon|ftp|lpr|mail|news|user|uucp)", LOG_STR "Logging via syslog\n" "Security/authorization messages facility\n" "Clock daemon (cron/at) facility\n" "General system daemon facility\n" "Ftp daemon facility\n" "Line printer facility\n" "Mail facility\n" "News facility\n" "Generic facility\n" "UUCP facility\n")
 
 DEFUN (cfg_no_log_syslog, cfg_no_log_syslog_cmd, "no log syslog", NO_STR LOG_STR "Logging via syslog\n")
 
 DEFUN (cfg_log_gsmtap, cfg_log_gsmtap_cmd, "log gsmtap [HOSTNAME]", LOG_STR "Logging via GSMTAP\n" "Host name to send the GSMTAP logging to (UDP port 4729)\n")
 
 DEFUN (cfg_log_stderr, cfg_log_stderr_cmd, "log stderr", LOG_STR "Logging via STDERR of the process\n")
 
 DEFUN (cfg_no_log_stderr, cfg_no_log_stderr_cmd, "no log stderr", NO_STR LOG_STR "Logging via STDERR of the process\n")
 
 DEFUN (cfg_log_file, cfg_log_file_cmd, "log file .FILENAME", LOG_STR "Logging to text file\n" "Filename\n")
 
 DEFUN (cfg_no_log_file, cfg_no_log_file_cmd, "no log file .FILENAME", NO_STR LOG_STR "Logging to text file\n" "Filename\n")
 
 DEFUN (cfg_log_alarms, cfg_log_alarms_cmd, "log alarms <2-32700>", LOG_STR "Logging alarms to osmo_strrb\n" "Maximum number of messages to log\n")
 
 DEFUN (cfg_no_log_alarms, cfg_no_log_alarms_cmd, "no log alarms", NO_STR LOG_STR "Logging alarms to osmo_strrb\n")
 
static int config_write_log_single (struct vty *vty, struct log_target *tgt)
 
static int config_write_log (struct vty *vty)
 
static int log_deprecated_func (struct cmd_element *cmd, struct vty *vty, int argc, const char *argv[])
 
void logging_vty_add_deprecated_subsys (void *ctx, const char *name)
 
void logging_vty_add_cmds ()
 Register logging related commands to the VTY. More...
 

Variables

const struct log_info * osmo_log_info
 
static const struct value_string logging_print_file_args []
 
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()

static int _cfg_log_syslog ( struct vty vty,
int  facility 
)
static

◆ _vty_output()

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

References 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.\n" "Log commands\n" "Mask commands\n" "'set log mask' is  deprecated,
please refer to the docs of 'set-log-mask' instead\n  
)

◆ config_write_log()

static int config_write_log ( struct vty vty)
static

◆ config_write_log_single()

static int config_write_log_single ( struct vty vty,
struct log_target *  tgt 
)
static

◆ DEFUN() [1/24]

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

◆ DEFUN() [2/24]

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

◆ DEFUN() [3/24]

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

◆ DEFUN() [4/24]

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

◆ DEFUN() [5/24]

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

◆ DEFUN() [6/24]

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

◆ DEFUN() [7/24]

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

◆ DEFUN() [8/24]

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

◆ DEFUN() [9/24]

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

◆ DEFUN() [10/24]

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

◆ DEFUN() [11/24]

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

◆ DEFUN() [12/24]

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

◆ DEFUN() [13/24]

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

◆ DEFUN() [14/24]

DEFUN ( logging_level  ,
logging_level_cmd  ,
NULL  ,
NULL   
)

◆ DEFUN() [15/24]

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

◆ DEFUN() [16/24]

DEFUN ( logging_prnt_cat_hex  ,
logging_prnt_cat_hex_cmd  ,
"logging print category-hex (0|1)"  ,
LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with category/subsystem nr in hex ('<000b>')\n  
)

◆ DEFUN() [17/24]

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

◆ DEFUN() [18/24]

DEFUN ( logging_prnt_file  ,
logging_prnt_file_cmd  ,
"logging print file (0|1|basename)"  ,
LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with the source file and line\n" "Prefix each log message with the source file's basename (strip leading paths) and line\n  
)

◆ DEFUN() [19/24]

DEFUN ( logging_prnt_level  ,
logging_prnt_level_cmd  ,
"logging print level (0|1)"  ,
LOGGING_STR "Log output settings\n" "Configure log message\n" "Don't prefix each log message\n" "Prefix each log message with the log level name\n  
)

◆ DEFUN() [20/24]

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

◆ DEFUN() [21/24]

DEFUN ( logging_set_category_mask  ,
logging_set_category_mask_cmd  ,
"logging set-log-mask MASK"  ,
LOGGING_STR "Set the logmask of this logging target\n" "List of logging categories to  log,
e.g. 'abc:mno:xyz'. Available log categories depend on the specific" "  application,
refer to the 'logging level' command. Optionally add individual log levels like" " '  abc,
1:mno  ,
3:xyz  ,
5'   
)

◆ DEFUN() [22/24]

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

◆ DEFUN() [23/24]

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

◆ DEFUN() [24/24]

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

◆ gDEFUN() [1/2]

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

◆ gDEFUN() [2/2]

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

◆ log_deprecated_func()

static int log_deprecated_func ( struct cmd_element cmd,
struct vty vty,
int  argc,
const char *  argv[] 
)
static

◆ log_target_create_vty()

struct log_target* log_target_create_vty ( struct vty vty)

References _vty_output().

Referenced by DEFUN().

◆ 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, cfg_log_node, CONFIG_NODE, config_write_log(), install_element(), install_element_ve(), and install_node().

◆ logging_vty_add_deprecated_subsys()

void logging_vty_add_deprecated_subsys ( void *  ctx,
const char *  name 
)

◆ osmo_log_vty2tgt()

struct log_target* osmo_log_vty2tgt ( struct vty vty)

◆ vty_print_logtarget()

static void vty_print_logtarget ( struct vty vty,
const struct log_info *  info,
const struct log_target *  tgt 
)
static

References VTY_NEWLINE, and vty_out().

Referenced by DEFUN().

Variable Documentation

◆ cfg_log_node

struct cmd_node cfg_log_node
Initial value:
= {
"%s(config-log)# ",
1
}

Referenced by logging_vty_add_cmds().

◆ 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().

◆ logging_print_file_args

const struct value_string logging_print_file_args[]
static
Initial value:
= {
{ LOG_FILENAME_NONE, "0" },
{ LOG_FILENAME_PATH, "1" },
{ LOG_FILENAME_BASENAME, "basename" },
{ 0, NULL }
}

Referenced by config_write_log_single(), and DEFUN().

◆ osmo_log_info

const struct log_info* osmo_log_info

Referenced by config_write_log_single(), and 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 }
}

Referenced by config_write_log_single(), and DEFUN().

CFG_LOG_NODE
@ CFG_LOG_NODE
Configure the logging.
Definition: command.h:79