libosmocore  0.9.6.315-40e62
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
logging.c File Reference

Debugging/Logging support code. More...

#include "../config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/timer.h>
#include <osmocom/vty/logging.h>

Macros

#define LOGLEVEL_DEFS   6 /* Number of loglevels.*/
 
#define INT2IDX(x)   (-1*(x)-1)
 

Functions

 osmo_static_assert (_LOG_CTX_COUNT<=ARRAY_SIZE(((struct log_context *) NULL) ->ctx), enum_logging_ctx_items_fit_in_struct_log_context)
 
 osmo_static_assert (_LOG_FLT_COUNT<=ARRAY_SIZE(((struct log_target *) NULL) ->filter_data), enum_logging_filters_fit_in_log_target_filter_data)
 
 osmo_static_assert (_LOG_FLT_COUNT<=8 *sizeof(((struct log_target *) NULL) ->filter_map), enum_logging_filters_fit_in_log_target_filter_map)
 
 LLIST_HEAD (osmo_log_target_list)
 
static void assert_loginfo (void)
 
static int subsys_lib2index (int subsys)
 
int log_parse_level (const char *lvl)
 Parse a human-readable log level into a numeric value. More...
 
const char * log_level_str (unsigned int lvl)
 convert a numeric log level into human-readable string More...
 
int log_parse_category (const char *category)
 parse a human-readable log category into numeric form More...
 
void log_parse_category_mask (struct log_target *target, const char *_mask)
 parse the log category mask More...
 
static const char * color (int subsys)
 
const char * log_category_name (int subsys)
 
static void _output (struct log_target *target, unsigned int subsys, unsigned int level, const char *file, int line, int cont, const char *format, va_list ap)
 
static int map_subsys (int subsys)
 
static bool should_log_to_target (struct log_target *tar, int subsys, int level)
 
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 More...
 
void logp (int subsys, const char *file, int line, int cont, const char *format,...)
 logging function used by DEBUGP() macro More...
 
void logp2 (int subsys, unsigned int level, const char *file, int line, int cont, const char *format,...)
 logging function used by LOGP() macro More...
 
void log_add_target (struct log_target *target)
 Register a new log target with the logging core. More...
 
void log_del_target (struct log_target *target)
 Unregister a log target from the logging core. More...
 
void log_reset_context (void)
 Reset (clear) the logging context. More...
 
int log_set_context (uint8_t ctx_nr, void *value)
 Set the logging context. More...
 
void log_set_all_filter (struct log_target *target, int all)
 Enable the LOG_FLT_ALL log filter. More...
 
void log_set_use_color (struct log_target *target, int use_color)
 Enable or disable the use of colored output. More...
 
void log_set_print_timestamp (struct log_target *target, int print_timestamp)
 Enable or disable printing of timestamps while logging. More...
 
void log_set_print_extended_timestamp (struct log_target *target, int print_timestamp)
 Enable or disable printing of extended timestamps while logging. More...
 
void log_set_print_filename (struct log_target *target, int print_filename)
 Enable or disable printing of the filename while logging. More...
 
void log_set_print_category (struct log_target *target, int print_category)
 Enable or disable printing of the category name. More...
 
void log_set_log_level (struct log_target *target, int log_level)
 Set the global log level for a given log target. More...
 
void log_set_category_filter (struct log_target *target, int category, int enable, int level)
 Set a category filter on a given log target. More...
 
static void _file_output (struct log_target *target, unsigned int level, const char *log)
 
struct log_targetlog_target_create (void)
 Create a new log target skeleton. More...
 
struct log_targetlog_target_create_stderr (void)
 Create the STDERR log target. More...
 
struct log_targetlog_target_create_file (const char *fname)
 Create a new file-based log target. More...
 
struct log_targetlog_target_find (int type, const char *fname)
 Find a registered log target. More...
 
void log_target_destroy (struct log_target *target)
 Unregister, close and delete a log target. More...
 
int log_target_file_reopen (struct log_target *target)
 close and re-open a log file (for log file rotation) More...
 
int log_targets_reopen (void)
 close and re-open all log files (for log file rotation) More...
 
const char * log_vty_command_string ()
 Generates the logging command string for VTY. More...
 
const char * log_vty_command_description ()
 Generates the logging command description for VTY. More...
 
int log_init (const struct log_info *inf, void *ctx)
 Initialize the Osmocom logging core. More...
 
void log_fini (void)
 
int log_check_level (int subsys, unsigned int level)
 Check whether a log entry will be generated. More...
 

Variables

struct log_infoosmo_log_info
 
static struct log_context log_context
 
static void * tall_log_ctx = NULL
 
static const struct value_string loglevel_strs [LOGLEVEL_DEFS+1]
 
static const struct log_info_cat internal_cat [OSMO_NUM_DLIB]
 
static const char * loglevel_descriptions [LOGLEVEL_DEFS+1]
 descriptive string for each log level More...
 

Detailed Description

Debugging/Logging support code.

Macro Definition Documentation

#define INT2IDX (   x)    (-1*(x)-1)
#define LOGLEVEL_DEFS   6 /* Number of loglevels.*/

Function Documentation

static void _file_output ( struct log_target target,
unsigned int  level,
const char *  log 
)
static
static void _output ( struct log_target target,
unsigned int  subsys,
unsigned int  level,
const char *  file,
int  line,
int  cont,
const char *  format,
va_list  ap 
)
static
static const char* color ( int  subsys)
static

References log_info::cat, log_info_cat::color, and subsys.

Referenced by _output(), and rb_erase().

LLIST_HEAD ( osmo_log_target_list  )
void logp2 ( int  subsys,
unsigned int  level,
const char *  file,
int  line,
int  cont,
const char *  format,
  ... 
)

logging function used by LOGP() macro

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

References osmo_vlogp().

static int map_subsys ( int  subsys)
inlinestatic
osmo_static_assert ( _LOG_CTX_COUNT<=  ARRAY_SIZE((struct log_context *) NULL) ->ctx,
enum_logging_ctx_items_fit_in_struct_log_context   
)
osmo_static_assert ( _LOG_FLT_COUNT<=  ARRAY_SIZE((struct log_target *) NULL) ->filter_data,
enum_logging_filters_fit_in_log_target_filter_data   
)
osmo_static_assert ( _LOG_FLT_COUNT<=8 *  sizeof((struct log_target *) NULL) ->filter_map,
enum_logging_filters_fit_in_log_target_filter_map   
)
static bool should_log_to_target ( struct log_target tar,
int  subsys,
int  level 
)
inlinestatic
static int subsys_lib2index ( int  subsys)
static

References log_info::num_cat_user.

Referenced by map_subsys().

Variable Documentation

const struct log_info_cat internal_cat[OSMO_NUM_DLIB]
static
struct log_context log_context
static
const char* loglevel_descriptions[LOGLEVEL_DEFS+1]
static
Initial value:
= {
"Don't use. It doesn't log anything",
"Log debug messages and higher levels",
"Log informational messages and higher levels",
"Log noticeable messages and higher levels",
"Log error messages and higher levels",
"Log only fatal messages",
NULL,
}

descriptive string for each log level

const struct value_string loglevel_strs[LOGLEVEL_DEFS+1]
static
Initial value:
= {
{ 0, "EVERYTHING" },
{ LOGL_DEBUG, "DEBUG" },
{ LOGL_INFO, "INFO" },
{ LOGL_NOTICE, "NOTICE" },
{ LOGL_ERROR, "ERROR" },
{ LOGL_FATAL, "FATAL" },
{ 0, NULL },
}
#define LOGL_INFO
general information
Definition: logging.h:85
#define LOGL_DEBUG
different log levels
Definition: logging.h:84
#define LOGL_ERROR
error condition, requires user action
Definition: logging.h:87
#define LOGL_NOTICE
abnormal/unexpected condition
Definition: logging.h:86
#define LOGL_FATAL
fatal, program aborted
Definition: logging.h:88
struct log_info* osmo_log_info
void* tall_log_ctx = NULL
static