libosmocore 0.3.6
Osmocom core library
Osmocom logging framework

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...

Files

file  logging.h
file  logging_syslog.c

Typedefs

typedef int log_filter (const struct log_context *ctx, struct log_target *target)
 Log filter function.

Enumerations

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

Functions

void logp (int subsys, char *file, int line, int cont, const char *format,...) __attribute__((format(printf
void logp2 (int subsys, unsigned int level, 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_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_timestamp (struct log_target *target, int)
 Enable or disable printing of timestamps while logging.
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
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)
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.
int log_target_file_reopen (struct log_target *tgt)
 close and re-open a log file (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 const int logp2syslog_level (unsigned int level)
static void _syslog_output (struct log_target *target, unsigned int level, const char *log)

Variables

uint8_t log_category::enabled
const char * log_info_cat::color
const char * log_info_cat::description
uint8_t log_info_cat::loglevel
uint8_t log_info_cat::enabled
struct log_info_catlog_info::cat
 per-category information
unsigned int log_info::num_cat
 total number of categories
unsigned int log_info::num_cat_user
 total number of user categories (not library)
int log_target::filter_map
 Internal data for filtering.
void * log_target::filter_data [LOG_MAX_FILTERS+1]
 Internal data for filtering.
struct log_categorylog_target::categories
 logging categories
uint8_t log_target::loglevel
 global log level
unsigned int log_target::use_color:1
 should color be used when printing log messages?
unsigned int log_target::print_timestamp:1
 should log messages be prefixed with a timestamp?
enum log_target_type log_target::type
 the type of this log taget
const char *   log_target::@0::@2::fname
int   log_target::@0::@3::facility
struct {
   int   priority
   int   facility
}   log_target::@0::tgt_syslog
struct {
   void *   vty
}   log_target::@0::tgt_vty
union {
   struct {
      FILE *   out
      const char *   fname
   }   tgt_file
   struct {
      int   priority
      int   facility
   }   tgt_syslog
   struct {
      void *   vty
   }   tgt_vty
}; 
void(* log_target::output )(struct log_target *target, unsigned int level, const char *string)
 call-back function to be called when the logging framework wants to log somethnig.
struct llist_head osmo_log_target_list

Enumeration Type Documentation

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


Function Documentation

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.

Referenced by osmo_init_logging().

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.

Referenced by log_target_destroy().

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 log_info::cat, log_info::num_cat, and log_info::num_cat_user.

Referenced by osmo_init_logging().

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.

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_info_cat::name, and log_info::num_cat.

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

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

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.

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.

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.

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.

struct log_target* log_target_create_file ( const char *  fname) [read]

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.

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

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.

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

Find a registered log target.

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

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

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!

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

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!

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


Variable Documentation

const char* log_info_cat::color

color string for cateyory

description text

Referenced by log_vty_command_description().

is this category enabled or not

Referenced by log_target_create().

currently selected log-level

Referenced by log_target_create().

void(* log_target::output)(struct log_target *target, unsigned int level, const char *string)

call-back function to be called when the logging framework wants to log somethnig.

Parameters:
[in]target logging target
[in]levellog level of currnet message
[in]stringthe string that is to be written to the log

Referenced by log_target_create_file(), log_target_create_stderr(), log_target_create_syslog(), and log_target_destroy().