libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
Loading...
Searching...
No Matches
Osmocom logging framework

Files

file  logging.h
 
file  logging_gsmtap.c
 
file  logging_syslog.c
 
file  loggingrb.c
 

Data Structures

struct  log_category
 
struct  log_info_cat
 Information regarding one logging category. More...
 
struct  log_context
 Log context information, passed to filter. More...
 
struct  log_info
 Logging configuration, passed to log_init. More...
 
struct  log_target
 structure representing a logging target More...
 

Macros

#define LOG_MAX_CTX   8
 Maximum number of logging contexts.
 
#define LOG_MAX_FILTERS   8
 Maximum number of logging filters.
 
#define DEBUG
 
#define DEBUGP(ss, fmt, args...)
 Log a debug message through the Osmocom logging framework.
 
#define DEBUGPC(ss, fmt, args...)
 
#define LOGP(ss, level, fmt, args...)
 Log a new message through the Osmocom logging framework.
 
#define LOGPC(ss, level, fmt, args...)
 Continue a log message through the Osmocom logging framework.
 
#define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...)
 Log through the Osmocom logging framework with explicit source. If caller_file is passed as NULL, BASE_FILE and LINE are used instead of caller_file and caller_line (so that this macro here defines both cases in the same place, and to catch cases where callers fail to pass a non-null filename string).
 
#define LOGL_DEBUG   1
 different log levels
 
#define LOGL_INFO   3
 general information
 
#define LOGL_NOTICE   5
 abnormal/unexpected condition
 
#define LOGL_ERROR   7
 error condition, requires user action
 
#define LOGL_FATAL   8
 fatal, program aborted
 
#define LOG_FILTER_ALL   0x0001
 
#define DLGLOBAL   -1
 
#define DLLAPD   -2
 
#define DLINP   -3
 
#define DLMUX   -4
 
#define DLMI   -5
 
#define DLMIB   -6
 
#define DLSMS   -7
 
#define DLCTRL   -8
 
#define DLGTP   -9
 
#define DLSTATS   -10
 
#define DLGSUP   -11
 
#define DLOAP   -12
 
#define OSMO_NUM_DLIB   12
 
#define GSMTAP_LOG_MAX_SIZE   4096
 

Typedefs

typedef int log_filter(const struct log_context *ctx, struct log_target *target)
 Log filter function.
 
typedef void log_print_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
 
typedef void log_save_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
 

Enumerations

enum  log_target_type {
  LOG_TGT_TYPE_VTY , LOG_TGT_TYPE_SYSLOG , LOG_TGT_TYPE_FILE , LOG_TGT_TYPE_STDERR ,
  LOG_TGT_TYPE_STRRB , LOG_TGT_TYPE_GSMTAP
}
 Type of logging target. More...
 

Functions

void osmo_vlogp (int subsys, int level, const char *file, int line, int cont, const char *format, va_list ap)
 vararg version of logging function
 
void logp (int subsys, const char *file, int line, int cont, const char *format,...) OSMO_DEPRECATED("Use DEBUGP* macros instead")
 logging function used by DEBUGP() macro
 
void logp2 (int subsys, unsigned int level, const char *file, int line, int cont, const char *format,...) __attribute__((format(printf
 
void int log_init (const struct log_info *inf, void *talloc_ctx)
 Initialize the Osmocom logging core.
 
void log_fini (void)
 
int log_check_level (int subsys, unsigned int level)
 Check whether a log entry will be generated.
 
void log_reset_context (void)
 Reset (clear) the logging context.
 
int log_set_context (uint8_t ctx, void *value)
 Set the logging context.
 
void log_set_all_filter (struct log_target *target, int)
 Enable the LOG_FILTER_ALL log filter.
 
void log_set_use_color (struct log_target *target, int)
 Enable or disable the use of colored output.
 
void log_set_print_extended_timestamp (struct log_target *target, int)
 Enable or disable printing of extended timestamps while logging.
 
void log_set_print_timestamp (struct log_target *target, int)
 Enable or disable printing of timestamps while logging.
 
void log_set_print_filename (struct log_target *target, int)
 Enable or disable printing of the filename while logging.
 
void log_set_print_category (struct log_target *target, int)
 Enable or disable printing of the category name.
 
void log_set_log_level (struct log_target *target, int log_level)
 Set the global log level for a given log target.
 
void log_parse_category_mask (struct log_target *target, const char *mask)
 parse the log category mask
 
const char * log_category_name (int subsys)
 
int log_parse_level (const char *lvl)
 Parse a human-readable log level into a numeric value.
 
const char * log_level_str (unsigned int lvl)
 convert a numeric log level into human-readable string
 
int log_parse_category (const char *category)
 parse a human-readable log category into numeric form
 
void log_set_category_filter (struct log_target *target, int category, int enable, int level)
 Set a category filter on a given log target.
 
struct log_targetlog_target_create (void)
 Create a new log target skeleton.
 
void log_target_destroy (struct log_target *target)
 Unregister, close and delete a log target.
 
struct log_targetlog_target_create_stderr (void)
 Create the STDERR log target.
 
struct log_targetlog_target_create_file (const char *fname)
 Create a new file-based log target.
 
struct log_targetlog_target_create_syslog (const char *ident, int option, int facility)
 Create a new logging target for syslog logging.
 
struct log_targetlog_target_create_gsmtap (const char *host, uint16_t port, const char *ident, bool ofd_wq_mode, bool add_sink)
 Create a new logging target for GSMTAP logging.
 
int log_target_file_reopen (struct log_target *tgt)
 close and re-open a log file (for log file rotation)
 
int log_targets_reopen (void)
 close and re-open all log files (for log file rotation)
 
void log_add_target (struct log_target *target)
 Register a new log target with the logging core.
 
void log_del_target (struct log_target *target)
 Unregister a log target from the logging core.
 
const char * log_vty_command_string (const struct log_info *info)
 Generates the logging command string for VTY.
 
const char * log_vty_command_description (const struct log_info *info)
 Generates the logging command description for VTY.
 
struct log_targetlog_target_find (int type, const char *fname)
 Find a registered log target.
 
static void _gsmtap_raw_output (struct log_target *target, int subsys, unsigned int level, const char *file, int line, int cont, const char *format, va_list ap)
 
static int logp2syslog_level (unsigned int level)
 
static void _syslog_output (struct log_target *target, unsigned int level, const char *log)
 
static void _rb_output (struct log_target *target, unsigned int level, const char *log)
 
size_t log_target_rb_used_size (struct log_target const *target)
 Return the number of log strings in the osmo_strrb-backed target.
 
size_t log_target_rb_avail_size (struct log_target const *target)
 Return the capacity of the osmo_strrb-backed target.
 
const char * log_target_rb_get (struct log_target const *target, size_t logindex)
 Return the nth log entry in a target.
 
struct log_targetlog_target_create_rb (size_t size)
 Create a new logging target for ringbuffer-backed logging.
 

Variables

struct llist_head osmo_log_target_list
 

Detailed Description

Macro Definition Documentation

◆ DEBUGP

#define DEBUGP ( ss,
fmt,
args... )
Value:
LOGP(ss, LOGL_DEBUG, fmt, ##args)
#define LOGP(ss, level, fmt, args...)
Log a new message through the Osmocom logging framework.
Definition logging.h:48
#define LOGL_DEBUG
different log levels
Definition logging.h:86

Log a debug message through the Osmocom logging framework.

Parameters
[in]sslogging subsystem (e.g. DLGLOBAL)
[in]fmtformat string
[in]argsvariable argument list

◆ DEBUGPC

#define DEBUGPC ( ss,
fmt,
args... )
Value:
LOGPC(ss, LOGL_DEBUG, fmt, ##args)
#define LOGPC(ss, level, fmt, args...)
Continue a log message through the Osmocom logging framework.
Definition logging.h:57

◆ DLCTRL

#define DLCTRL   -8

Control Interface

◆ DLGLOBAL

◆ DLGSUP

#define DLGSUP   -11

Generic Subscriber Update Protocol

◆ DLGTP

#define DLGTP   -9

GTP (GPRS Tunneling Protocol

◆ DLINP

#define DLINP   -3

(A-bis) Input sub-system

◆ DLLAPD

#define DLLAPD   -2

LAPD implementation

◆ DLMI

#define DLMI   -5

ISDN-layer below input sub-system

◆ DLMIB

#define DLMIB   -6

ISDN layer B-channel

◆ DLMUX

#define DLMUX   -4

Osmocom Multiplex (Osmux)

◆ DLOAP

#define DLOAP   -12

Osmocom Authentication Protocol

◆ DLSMS

#define DLSMS   -7

SMS sub-system

◆ DLSTATS

#define DLSTATS   -10

Statistics

◆ LOGL_DEBUG

#define LOGL_DEBUG   1

different log levels

debugging information

Referenced by logp().

◆ LOGP

#define LOGP ( ss,
level,
fmt,
args... )
Value:
LOGPSRC(ss, level, NULL, 0, fmt, ## args)
#define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...)
Log through the Osmocom logging framework with explicit source. If caller_file is passed as NULL,...
Definition logging.h:75

Log a new message through the Osmocom logging framework.

Parameters
[in]sslogging subsystem (e.g. DLGLOBAL)
[in]levellogging level (e.g. LOGL_NOTICE)
[in]fmtformat string
[in]argsvariable argument list

Referenced by osmo_sock_init(), osmo_sock_init_sa(), osmo_sock_unix_init(), osmo_sockaddr_is_local(), and osmo_wqueue_enqueue().

◆ LOGPC

#define LOGPC ( ss,
level,
fmt,
args... )
Value:
do { \
if (log_check_level(ss, level)) \
logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \
} while(0)
int log_check_level(int subsys, unsigned int level)
Check whether a log entry will be generated.
Definition logging.c:972

Continue a log message through the Osmocom logging framework.

Parameters
[in]sslogging subsystem (e.g. DLGLOBAL)
[in]levellogging level (e.g. LOGL_NOTICE)
[in]fmtformat string
[in]argsvariable argument list

◆ LOGPSRC

#define LOGPSRC ( ss,
level,
caller_file,
caller_line,
fmt,
args... )
Value:
do { \
if (log_check_level(ss, level)) {\
if (caller_file) \
logp2(ss, level, caller_file, caller_line, 0, fmt, ##args); \
else \
logp2(ss, level, __BASE_FILE__, __LINE__, 0, fmt, ##args); \
}\
} while(0)

Log through the Osmocom logging framework with explicit source. If caller_file is passed as NULL, BASE_FILE and LINE are used instead of caller_file and caller_line (so that this macro here defines both cases in the same place, and to catch cases where callers fail to pass a non-null filename string).

Parameters
[in]sslogging subsystem (e.g. DLGLOBAL)
[in]levellogging level (e.g. LOGL_NOTICE)
[in]caller_filecaller's source file string (e.g. BASE_FILE)
[in]caller_linecaller's source line nr (e.g. LINE)
[in]fmtformat string
[in]argsvariable argument list

Referenced by _osmo_fsm_inst_dispatch().

◆ OSMO_NUM_DLIB

#define OSMO_NUM_DLIB   12

Number of logging sub-systems in libraries

Enumeration Type Documentation

◆ log_target_type

Type of logging target.

Enumerator
LOG_TGT_TYPE_VTY 

VTY logging.

LOG_TGT_TYPE_SYSLOG 

syslog based logging

LOG_TGT_TYPE_FILE 

text file logging

LOG_TGT_TYPE_STDERR 

stderr logging

LOG_TGT_TYPE_STRRB 

osmo_strrb-backed logging

LOG_TGT_TYPE_GSMTAP 

GSMTAP network logging.

Function Documentation

◆ log_add_target()

void log_add_target ( struct log_target * target)

Register a new log target with the logging core.

Parameters
[in]targetLog target to be registered

References log_target::entry, and llist_add_tail().

Referenced by osmo_init_logging().

◆ log_check_level()

int log_check_level ( int subsys,
unsigned int level )

Check whether a log entry will be generated.

Returns
!= 0 if a log entry might get generated by at least one target

References log_target::entry, and llist_for_each_entry.

◆ log_del_target()

void log_del_target ( struct log_target * target)

Unregister a log target from the logging core.

Parameters
[in]targetLog target to be unregistered

References log_target::entry, and llist_del().

Referenced by log_target_destroy().

◆ log_init()

void int log_init ( const struct log_info * inf,
void * ctx )

Initialize the Osmocom logging core.

Parameters
[in]infInformation regarding logging categories
[in]ctxtalloc context for logging allocations
Returns
0 in case of success, negative in case of error

References ARRAY_SIZE, log_info::cat, log_info::num_cat, and log_info::num_cat_user.

Referenced by osmo_init_logging().

◆ log_level_str()

const char * log_level_str ( unsigned int lvl)

convert a numeric log level into human-readable string

Parameters
lvl[in]numeric log level
Returns
zero-terminated string (log level name)

References get_value_string().

◆ log_parse_category()

int log_parse_category ( const char * category)

parse a human-readable log category into numeric form

Parameters
[in]categoryhuman-readable log category name
Returns
numeric category value, or -EINVAL otherwise

References log_info::cat, log_info_cat::name, and log_info::num_cat.

◆ log_parse_category_mask()

void log_parse_category_mask ( struct log_target * target,
const char * _mask )

parse the log category mask

Parameters
[in]targetlog target to be configured
[in]_masklog category mask string

The format can be this: category1:category2:category3 or category1,2:category2,3:...

References log_info::cat, log_target::categories, log_category::enabled, log_category::loglevel, log_info_cat::name, log_info::num_cat, and OSMO_ASSERT.

◆ log_parse_level()

int log_parse_level ( const char * lvl)

Parse a human-readable log level into a numeric value.

Parameters
lvl[in]zero-terminated string containing log level name
Returns
numeric log level

References get_string_value().

◆ log_set_all_filter()

void log_set_all_filter ( struct log_target * target,
int all )

Enable the LOG_FILTER_ALL log filter.

Parameters
[in]targetLog target to be affected
[in]allenable (1) or disable (0) the ALL filter

When the LOG_FILTER_ALL filter is enabled, all log messages will be printed. It acts as a wildcard. Setting it to 1 means there is no filtering.

References log_target::filter_map.

Referenced by osmo_init_logging().

◆ log_set_category_filter()

void log_set_category_filter ( struct log_target * target,
int category,
int enable,
int level )

Set a category filter on a given log target.

Parameters
[in]targetLog target to be affected
[in]categoryLog category to be affected
[in]enablewhether to enable or disable the filter
[in]levelLog level of the filter

References log_target::categories, log_category::enabled, and log_category::loglevel.

◆ log_set_context()

int log_set_context ( uint8_t ctx_nr,
void * value )

Set the logging context.

Parameters
[in]ctx_nrlogging context number
[in]valuevalue to which the context is to be set
Returns
0 in case of success; negative otherwise

A logging context is something like the subscriber identity to which the currently processed message relates, or the BTS through which it was received. As soon as this data is known, it can be set using this function. The main use of context information is for logging filters.

References LOG_MAX_CTX.

◆ log_set_log_level()

void log_set_log_level ( struct log_target * target,
int log_level )

Set the global log level for a given log target.

Parameters
[in]targetLog target to be affected
[in]log_levelNew global log level

References log_target::loglevel.

◆ log_set_print_category()

void log_set_print_category ( struct log_target * target,
int print_category )

Enable or disable printing of the category name.

Parameters
[in]targetLog target to be affected
[in]print_catnameEnable (1) or disable (0) filenames

Print the category/subsys name in front of every log message.

References log_target::print_category.

◆ log_set_print_extended_timestamp()

void log_set_print_extended_timestamp ( struct log_target * target,
int print_timestamp )

Enable or disable printing of extended timestamps while logging.

Parameters
[in]targetLog target to be affected
[in]print_timestampEnable (1) or disable (0) timestamps

When both timestamp and extended timestamp is enabled then only the extended timestamp will be used. The format of the timestamp is YYYYMMDDhhmmssnnn.

References log_target::print_ext_timestamp, and log_target::print_timestamp.

◆ log_set_print_filename()

void log_set_print_filename ( struct log_target * target,
int print_filename )

Enable or disable printing of the filename while logging.

Parameters
[in]targetLog target to be affected
[in]print_filenameEnable (1) or disable (0) filenames

References log_target::print_filename.

◆ log_set_print_timestamp()

void log_set_print_timestamp ( struct log_target * target,
int print_timestamp )

Enable or disable printing of timestamps while logging.

Parameters
[in]targetLog target to be affected
[in]print_timestampEnable (1) or disable (0) timestamps

References log_target::print_timestamp.

◆ log_set_use_color()

void log_set_use_color ( struct log_target * target,
int use_color )

Enable or disable the use of colored output.

Parameters
[in]targetLog target to be affected
[in]use_colorUse color (1) or don't use color (0)

References log_target::use_color.

◆ log_target_create()

struct log_target * log_target_create ( void )

◆ log_target_create_file()

struct log_target * log_target_create_file ( const char * fname)

Create a new file-based log target.

Parameters
[in]fnameFile name of the new log file
Returns
Log target in case of success, NULL otherwise

References log_target_create(), LOG_TGT_TYPE_FILE, log_target::output, and log_target::type.

◆ log_target_create_gsmtap()

struct log_target * log_target_create_gsmtap ( const char * host,
uint16_t port,
const char * ident,
bool ofd_wq_mode,
bool add_sink )

Create a new logging target for GSMTAP logging.

Parameters
[in]identstring identifier
Returns
Log target in case of success, NULL in case of error

References gsmtap_source_add_sink(), gsmtap_source_init(), log_target_create(), log_target_destroy(), LOG_TGT_TYPE_GSMTAP, gsmtap_inst::ofd_wq_mode, log_target::raw_output, and log_target::type.

◆ log_target_create_rb()

struct log_target * log_target_create_rb ( size_t size)

Create a new logging target for ringbuffer-backed logging.

Parameters
[in]sizeThe capacity (number of messages) of the logging target.
Returns
A log target in case of success, NULL in case of error.

References log_target_create(), log_target_destroy(), LOG_TGT_TYPE_STRRB, osmo_strrb_create(), log_target::output, osmo_strrb::size, and log_target::type.

◆ log_target_create_stderr()

struct log_target * log_target_create_stderr ( void )

Create the STDERR log target.

Returns
dynamically-allocated log_target for STDERR

References log_target_create(), LOG_TGT_TYPE_STDERR, log_target::output, and log_target::type.

Referenced by osmo_init_logging().

◆ log_target_create_syslog()

struct log_target * log_target_create_syslog ( const char * ident,
int option,
int facility )

Create a new logging target for syslog logging.

Parameters
[in]identsyslog string identifier
[in]optionsyslog options
[in]facilitysyslog facility
Returns
Log target in case of success, NULL in case of error

References log_target_create(), LOG_TGT_TYPE_SYSLOG, log_target::output, and log_target::type.

◆ log_target_destroy()

void log_target_destroy ( struct log_target * target)

Unregister, close and delete a log target.

Parameters
target[in]log target to unregister, close and delete

References log_del_target(), and log_target::output.

Referenced by log_target_create_gsmtap(), and log_target_create_rb().

◆ log_target_file_reopen()

int log_target_file_reopen ( struct log_target * target)

close and re-open a log file (for log file rotation)

Parameters
[in]targetlog target to re-open
Returns
0 in case of success; negative otherwise

Referenced by log_targets_reopen().

◆ log_target_find()

struct log_target * log_target_find ( int type,
const char * fname )

Find a registered log target.

Parameters
[in]typeLog target type
[in]fnameFile name
Returns
Log target (if found), NULL otherwise

References log_target::entry, llist_for_each_entry, LOG_TGT_TYPE_FILE, and log_target::type.

◆ log_target_rb_avail_size()

size_t log_target_rb_avail_size ( struct log_target const * target)

Return the capacity of the osmo_strrb-backed target.

Parameters
[in]targetThe target to search.

Note that this is the capacity (aka max number of messages). It is not the number of unused message slots.

Returns
The number of log strings in the osmo_strrb-backed target.

References osmo_strrb::size.

◆ log_target_rb_get()

const char * log_target_rb_get ( struct log_target const * target,
size_t logindex )

Return the nth log entry in a target.

Parameters
[in]targetThe target to search.
[in]logindexThe index of the log entry/error message.
Returns
A pointer to the nth message, or NULL if logindex is invalid.

References osmo_strrb_get_nth().

◆ log_target_rb_used_size()

size_t log_target_rb_used_size ( struct log_target const * target)

Return the number of log strings in the osmo_strrb-backed target.

Parameters
[in]targetThe target to search.
Returns
The number of log strings in the osmo_strrb-backed target.

References osmo_strrb_elements().

◆ log_targets_reopen()

int log_targets_reopen ( void )

close and re-open all log files (for log file rotation)

Returns
0 in case of success; negative otherwise

References log_target::entry, llist_for_each_entry, log_target_file_reopen(), LOG_TGT_TYPE_FILE, and log_target::type.

◆ log_vty_command_description()

const char * log_vty_command_description ( const struct log_info * unused_info)

Generates the logging command description for VTY.

Parameters
[in]unused_infoDeprecated parameter, no longer used!
Returns
logging command description for use by VTY command node

References log_info::cat, log_info_cat::description, log_info_cat::name, and log_info::num_cat.

◆ log_vty_command_string()

const char * log_vty_command_string ( const struct log_info * unused_info)

Generates the logging command string for VTY.

Parameters
[in]unused_infoDeprecated parameter, no longer used!
Returns
vty command string for use by VTY command node

References log_info::cat, log_info_cat::name, and log_info::num_cat.

◆ logp()

void logp ( int subsys,
const char * file,
int line,
int cont,
const char * format,
... )

logging function used by DEBUGP() macro

Parameters
[in]subsysLogging sub-system
[in]filename of source code file
[in]contcontinuation (1) or new line (0)
[in]formatformat string

References LOGL_DEBUG, and osmo_vlogp().

◆ osmo_vlogp()

void osmo_vlogp ( int subsys,
int level,
const char * file,
int line,
int cont,
const char * format,
va_list ap )

vararg version of logging function

Parameters
[in]subsysLogging sub-system
[in]levelLog level
[in]filename of source code file
[in]contcontinuation (1) or new line (0)
[in]formatformat string
[in]apvararg-list containing format string arguments

References log_target::entry, llist_for_each_entry, and log_target::raw_output.

Referenced by logp().