logging.h
Go to the documentation of this file.
#pragma once
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <osmocom/core/defs.h>
#include <osmocom/core/linuxlist.h>
#define LOG_MAX_CTX 8
#define LOG_MAX_FILTERS 8
#define DEBUG
#ifdef DEBUG
#define DEBUGP(ss, fmt, args...) LOGP(ss, LOGL_DEBUG, fmt, ##args)
#define DEBUGPC(ss, fmt, args...) LOGPC(ss, LOGL_DEBUG, fmt, ##args)
#else
#define DEBUGP(xss, fmt, args...)
#define DEBUGPC(ss, fmt, args...)
#endif
void osmo_vlogp(int subsys, int level, const char *file, int line,
int cont, const char *format, va_list ap);
void logp(int subsys, const char *file, int line, int cont, const char *format, ...) OSMO_DEPRECATED("Use DEBUGP* macros instead");
#define LOGP(ss, level, fmt, args...) \
LOGPSRC(ss, level, NULL, 0, fmt, ## args)
#define LOGPC(ss, level, fmt, args...) \
do { \
if (log_check_level(ss, level)) \
logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \
} while(0)
#define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \
LOGPSRCC(ss, level, caller_file, caller_line, 0, fmt, ##args)
#define LOGPSRCC(ss, level, caller_file, caller_line, cont, fmt, args...) \
do { \
if (log_check_level(ss, level)) {\
if (caller_file) \
logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \
else \
logp2(ss, level, __BASE_FILE__, __LINE__, cont, fmt, ##args); \
}\
} while(0)
#define LOGL_DEBUG 1
#define LOGL_INFO 3
#define LOGL_NOTICE 5
#define LOGL_ERROR 7
#define LOGL_FATAL 8
/* logging levels defined by the library itself */
#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 DLSS7 -13
#define DLSCCP -14
#define DLSUA -15
#define DLM3UA -16
#define DLMGCP -17
#define DLJIBUF -18
#define OSMO_NUM_DLIB 18
struct log_category {
uint8_t loglevel;
uint8_t enabled;
};
struct log_info_cat {
const char *name;
const char *color;
const char *description;
uint8_t loglevel;
uint8_t enabled;
};
struct log_context {
void *ctx[LOG_MAX_CTX+1];
};
enum log_ctx_index {
LOG_CTX_GB_NSVC,
LOG_CTX_GB_BVC,
LOG_CTX_BSC_SUBSCR,
LOG_CTX_VLR_SUBSCR,
_LOG_CTX_COUNT
};
enum log_filter_index {
LOG_FLT_ALL,
LOG_FLT_GB_NSVC,
LOG_FLT_GB_BVC,
LOG_FLT_BSC_SUBSCR,
LOG_FLT_VLR_SUBSCR,
_LOG_FLT_COUNT
};
#define LOG_FILTER_ALL (1<<LOG_FLT_ALL)
#define GPRS_CTX_NSVC LOG_CTX_GB_NSVC
#define GPRS_CTX_BVC LOG_CTX_GB_BVC
struct log_target;
typedef int log_filter(const struct log_context *ctx,
struct log_target *target);
struct log_info;
struct vty;
struct gsmtap_inst;
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);
struct log_info {
/* filter callback function */
log_filter *filter_fn;
const struct log_info_cat *cat;
unsigned int num_cat;
unsigned int num_cat_user;
log_save_filters *save_fn;
log_print_filters *print_fn;
};
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,
};
enum log_filename_type {
LOG_FILENAME_NONE,
LOG_FILENAME_PATH,
LOG_FILENAME_BASENAME,
};
struct log_target {
struct llist_head entry;
int filter_map;
void *filter_data[LOG_MAX_FILTERS+1];
struct log_category *categories;
uint8_t loglevel;
unsigned int use_color:1;
unsigned int print_timestamp:1;
unsigned int print_filename:1;
unsigned int print_category:1;
unsigned int print_ext_timestamp:1;
enum log_target_type type;
union {
struct {
FILE *out;
const char *fname;
} tgt_file;
struct {
int priority;
int facility;
} tgt_syslog;
struct {
void *vty;
} tgt_vty;
struct {
void *rb;
} tgt_rb;
struct {
struct gsmtap_inst *gsmtap_inst;
const char *ident;
const char *hostname;
} tgt_gsmtap;
};
void (*output) (struct log_target *target, unsigned int level,
const char *string);
void (*raw_output)(struct log_target *target, int subsys,
unsigned int level, const char *file, int line,
int cont, const char *format, va_list ap);
/* Should the log level be printed? */
bool print_level;
/* Should we print the subsys in hex like '<000b>'? */
bool print_category_hex;
/* Should we print the source file and line, and in which way? */
enum log_filename_type print_filename2;
};
/* use the above macros */
void logp2(int subsys, unsigned int level, const char *file,
int line, int cont, const char *format, ...)
__attribute__ ((format (printf, 6, 7)));
int log_init(const struct log_info *inf, void *talloc_ctx);
void log_fini(void);
int log_check_level(int subsys, unsigned int level);
/* context management */
void log_reset_context(void);
int log_set_context(uint8_t ctx, void *value);
/* filter on the targets */
void log_set_all_filter(struct log_target *target, int);
void log_set_use_color(struct log_target *target, int);
void log_set_print_extended_timestamp(struct log_target *target, int);
void log_set_print_timestamp(struct log_target *target, int);
void log_set_print_filename(struct log_target *target, int);
void log_set_print_filename2(struct log_target *target, enum log_filename_type lft);
void log_set_print_category(struct log_target *target, int);
void log_set_print_category_hex(struct log_target *target, int);
void log_set_print_level(struct log_target *target, int);
void log_set_log_level(struct log_target *target, int log_level);
void log_parse_category_mask(struct log_target *target, const char* mask);
const char* log_category_name(int subsys);
int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
const char *log_level_str(unsigned int lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
int log_parse_category(const char *category);
void log_set_category_filter(struct log_target *target, int category,
int enable, int level);
/* management of the targets */
struct log_target *log_target_create(void);
void log_target_destroy(struct log_target *target);
struct log_target *log_target_create_stderr(void);
struct log_target *log_target_create_file(const char *fname);
struct log_target *log_target_create_syslog(const char *ident, int option,
int facility);
struct log_target *log_target_create_gsmtap(const char *host, uint16_t port,
const char *ident,
bool ofd_wq_mode,
bool add_sink);
int log_target_file_reopen(struct log_target *tgt);
int log_targets_reopen(void);
void log_add_target(struct log_target *target);
void log_del_target(struct log_target *target);
/* Generate command string for VTY use */
const char *log_vty_command_string() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
const char *log_vty_command_description() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
struct log_target *log_target_find(int type, const char *fname);
extern struct llist_head osmo_log_target_list;
log_target_type
log_target_type
Type of logging target.
Definition: logging.h:215
LOG_CTX_BSC_SUBSCR
@ LOG_CTX_BSC_SUBSCR
Definition: logging.h:152
log_target::tgt_rb
struct log_target::@7::@12 tgt_rb
log_add_target
void log_add_target(struct log_target *target)
Register a new log target with the logging core.
Definition: logging.c:567
log_category_name
const char * log_category_name(int subsys)
Definition: logging.c:323
log_info_cat::enabled
uint8_t enabled
is this category enabled or not
Definition: logging.h:139
LOG_CTX_VLR_SUBSCR
@ LOG_CTX_VLR_SUBSCR
Definition: logging.h:153
log_set_print_filename2
void log_set_print_filename2(struct log_target *target, enum log_filename_type lft)
Enable or disable printing of the filename while logging.
Definition: logging.c:675
log_target::tgt_syslog
struct log_target::@7::@10 tgt_syslog
log_info_cat::color
const char * color
color string for cateyory
Definition: logging.h:136
log_parse_level
int log_parse_level(const char *lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Parse a human-readable log level into a numeric value.
Definition: logging.c:209
log_info_cat::loglevel
uint8_t loglevel
currently selected log-level
Definition: logging.h:138
OSMO_DEPRECATED
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
log_target_find
struct log_target * log_target_find(int type, const char *fname)
Find a registered log target.
Definition: logging.c:842
log_category
Configuration of single log category / sub-system.
Definition: logging.h:128
LOG_FILENAME_PATH
@ LOG_FILENAME_PATH
Definition: logging.h:227
DEBUGP
#define DEBUGP(ss, fmt, args...)
Log a debug message through the Osmocom logging framework.
Definition: logging.h:27
log_parse_category_mask
void log_parse_category_mask(struct log_target *target, const char *mask)
parse the log category mask
Definition: logging.c:250
LOG_MAX_FILTERS
#define LOG_MAX_FILTERS
Maximum number of logging filters.
Definition: logging.h:17
LOG_FILENAME_BASENAME
@ LOG_FILENAME_BASENAME
Definition: logging.h:228
OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
#define OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Definition: defs.h:47
log_target_create
struct log_target * log_target_create(void)
Create a new log target skeleton.
Definition: logging.c:751
subsys
char subsys[16]
logging sub-system
Definition: gsmtap.h:11
LOG_FLT_GB_BVC
@ LOG_FLT_GB_BVC
Definition: logging.h:163
LOG_FLT_GB_NSVC
@ LOG_FLT_GB_NSVC
Definition: logging.h:162
log_info::filter_fn
log_filter * filter_fn
Definition: logging.h:199
LOG_CTX_GB_NSVC
@ LOG_CTX_GB_NSVC
Definition: logging.h:150
LOG_TGT_TYPE_STDERR
@ LOG_TGT_TYPE_STDERR
stderr logging
Definition: logging.h:219
log_info_cat::name
const char * name
name of category
Definition: logging.h:135
log_set_print_category_hex
void log_set_print_category_hex(struct log_target *target, int)
Enable or disable printing of the category number in hex ('<000b>').
Definition: logging.c:695
log_info_cat
Information regarding one logging category.
Definition: logging.h:134
log_info
Logging configuration, passed to log_init.
Definition: logging.h:197
log_target_create_stderr
struct log_target * log_target_create_stderr(void)
Create the STDERR log target.
Definition: logging.c:792
log_set_print_category
void log_set_print_category(struct log_target *target, int)
Enable or disable printing of the category name.
Definition: logging.c:686
log_filter_index
log_filter_index
Indexes to indicate objects that should be logged.
Definition: logging.h:160
log_set_print_timestamp
void log_set_print_timestamp(struct log_target *target, int)
Enable or disable printing of timestamps while logging.
Definition: logging.c:636
log_target::print_filename2
enum log_filename_type print_filename2
Definition: logging.h:315
log_target::tgt_file
struct log_target::@7::@9 tgt_file
log_target::print_filename
unsigned int print_filename
DEPRECATED: use print_filename2 instead.
Definition: logging.h:250
log_info::print_fn
log_print_filters * print_fn
filter saving function
Definition: logging.h:211
log_print_filters
void log_print_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
Definition: logging.h:188
LOG_FILENAME_NONE
@ LOG_FILENAME_NONE
Definition: logging.h:226
log_vty_command_description
const char * log_vty_command_description() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Generates the logging command description for VTY.
Definition: logging.c:1011
log_target::filter_data
void * filter_data[LOG_MAX_FILTERS+1]
Internal data for filtering.
Definition: logging.h:238
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.
Definition: logging_gsmtap.c:117
log_target_create_file
struct log_target * log_target_create_file(const char *fname)
Create a new file-based log target.
Definition: logging.c:816
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.
Definition: logging_syslog.c:73
LOG_CTX_GB_BVC
@ LOG_CTX_GB_BVC
Definition: logging.h:151
log_set_print_filename
void log_set_print_filename(struct log_target *target, int)
Use log_set_print_filename2() instead.
Definition: logging.c:663
LOG_TGT_TYPE_SYSLOG
@ LOG_TGT_TYPE_SYSLOG
syslog based logging
Definition: logging.h:217
log_target::entry
struct llist_head entry
linked list
Definition: logging.h:233
log_category::loglevel
uint8_t loglevel
configured log-level
Definition: logging.h:129
log_target::use_color
unsigned int use_color
should color be used when printing log messages?
Definition: logging.h:246
log_targets_reopen
int log_targets_reopen(void)
close and re-open all log files (for log file rotation)
Definition: logging.c:908
level
uint8_t level
logging level
Definition: gsmtap.h:8
log_set_print_level
void log_set_print_level(struct log_target *target, int)
Enable or disable printing of the log level name.
Definition: logging.c:706
log_target::print_ext_timestamp
unsigned int print_ext_timestamp
should log messages be prefixed with an extended timestamp?
Definition: logging.h:254
log_target::loglevel
uint8_t loglevel
global log level
Definition: logging.h:244
log_set_context
int log_set_context(uint8_t ctx, void *value)
Set the logging context.
Definition: logging.c:597
log_info::num_cat_user
unsigned int num_cat_user
total number of user categories (not library)
Definition: logging.h:206
log_target
structure representing a logging target
Definition: logging.h:232
log_info::cat
const struct log_info_cat * cat
per-category information
Definition: logging.h:202
gsmtap_inst
one gsmtap instance
Definition: gsmtap_util.h:23
log_target::raw_output
void(* raw_output)(struct log_target *target, int subsys, unsigned int level, const char *file, int line, int cont, const char *format, va_list ap)
alternative call-back function to which the logging framework passes the unfortmatted input arguments...
Definition: logging.h:306
log_target::facility
int facility
Definition: logging.h:267
log_target::print_level
bool print_level
Definition: logging.h:311
log_target::tgt_gsmtap
struct log_target::@7::@13 tgt_gsmtap
log_info::num_cat
unsigned int num_cat
total number of categories
Definition: logging.h:204
log_target::out
FILE * out
Definition: logging.h:261
log_set_use_color
void log_set_use_color(struct log_target *target, int)
Enable or disable the use of colored output.
Definition: logging.c:627
log_del_target
void log_del_target(struct log_target *target)
Unregister a log target from the logging core.
Definition: logging.c:575
logp
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
Definition: logging.c:538
__attribute__
struct rb_root __attribute__
Definition: conv_acc_generic.c:140
log_vty_command_string
const char * log_vty_command_string() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Generates the logging command string for VTY.
Definition: logging.c:931
log_target::print_category
unsigned int print_category
should log messages be prefixed with a category name?
Definition: logging.h:252
log_info::save_fn
log_save_filters * save_fn
filter saving function
Definition: logging.h:209
log_target::rb
void * rb
Definition: logging.h:275
_LOG_CTX_COUNT
@ _LOG_CTX_COUNT
Definition: logging.h:154
log_target::type
enum log_target_type type
the type of this log taget
Definition: logging.h:257
log_target::print_category_hex
bool print_category_hex
Definition: logging.h:313
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
log_target_file_reopen
int log_target_file_reopen(struct log_target *tgt)
close and re-open a log file (for log file rotation)
Definition: logging.c:893
LOG_TGT_TYPE_FILE
@ LOG_TGT_TYPE_FILE
text file logging
Definition: logging.h:218
log_reset_context
void log_reset_context(void)
Reset (clear) the logging context.
Definition: logging.c:581
log_set_print_extended_timestamp
void log_set_print_extended_timestamp(struct log_target *target, int)
Enable or disable printing of extended timestamps while logging.
Definition: logging.c:649
LOG_TGT_TYPE_GSMTAP
@ LOG_TGT_TYPE_GSMTAP
GSMTAP network logging.
Definition: logging.h:221
log_target::fname
const char * fname
Definition: logging.h:262
log_save_filters
void log_save_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
Definition: logging.h:192
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.
Definition: logging.c:715
_LOG_FLT_COUNT
@ _LOG_FLT_COUNT
Definition: logging.h:166
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.
Definition: logging.c:726
log_ctx_index
log_ctx_index
Indexes to indicate the object currently acted upon.
Definition: logging.h:149
logp2
void logp2(int subsys, unsigned int level, const char *file, int line, int cont, const char *format,...) __attribute__((format(printf
logging function used by LOGP() macro
Definition: logging.c:555
log_target_destroy
void log_target_destroy(struct log_target *target)
Unregister, close and delete a log target.
Definition: logging.c:867
LOG_FLT_VLR_SUBSCR
@ LOG_FLT_VLR_SUBSCR
Definition: logging.h:165
type
uint8_t type
see GSMTAP_TYPE_*
Definition: gsmtap.h:4
log_check_level
int log_check_level(int subsys, unsigned int level)
Check whether a log entry will be generated.
Definition: logging.c:1135
log_target::hostname
const char * hostname
Definition: logging.h:281
log_target::output
void(* output)(struct log_target *target, unsigned int level, const char *string)
call-back function to be called when the logging framework wants to log a fully formatted string
Definition: logging.h:291
log_target::categories
struct log_category * categories
logging categories
Definition: logging.h:241
osmo_log_target_list
struct llist_head osmo_log_target_list
LOG_TGT_TYPE_VTY
@ LOG_TGT_TYPE_VTY
VTY logging.
Definition: logging.h:216
log_target::ident
const char * ident
Definition: logging.h:280
log_level_str
const char * log_level_str(unsigned int lvl) OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
convert a numeric log level into human-readable string
Definition: logging.c:218
log_parse_category
int log_parse_category(const char *category)
parse a human-readable log category into numeric form
Definition: logging.c:227
log_init
void int log_init(const struct log_info *inf, void *talloc_ctx)
Initialize the Osmocom logging core.
Definition: logging.c:1075
defs.h
log_category::enabled
uint8_t enabled
is logging enabled?
Definition: logging.h:130
LOG_MAX_CTX
#define LOG_MAX_CTX
Maximum number of logging contexts.
Definition: logging.h:15
log_target::print_timestamp
unsigned int print_timestamp
should log messages be prefixed with a timestamp?
Definition: logging.h:248
log_target::tgt_vty
struct log_target::@7::@11 tgt_vty
log_info_cat::description
const char * description
description text
Definition: logging.h:137
linuxlist.h
log_context
Log context information, passed to filter.
Definition: logging.h:143
log_target::filter_map
int filter_map
Internal data for filtering.
Definition: logging.h:236
log_context::ctx
void * ctx[LOG_MAX_CTX+1]
Definition: logging.h:144
LOG_FLT_BSC_SUBSCR
@ LOG_FLT_BSC_SUBSCR
Definition: logging.h:164
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
Definition: logging.c:507
log_filter
int log_filter(const struct log_context *ctx, struct log_target *target)
Log filter function.
Definition: logging.h:181
LOG_TGT_TYPE_STRRB
@ LOG_TGT_TYPE_STRRB
osmo_strrb-backed logging
Definition: logging.h:220
log_target::priority
int priority
Definition: logging.h:266
log_set_all_filter
void log_set_all_filter(struct log_target *target, int)
Enable the LOG_FLT_ALL log filter.
Definition: logging.c:615
LOG_FLT_ALL
@ LOG_FLT_ALL
Definition: logging.h:161
log_filename_type
log_filename_type
Whether/how to log the source filename (and line number).
Definition: logging.h:225
log_target::gsmtap_inst
struct gsmtap_inst * gsmtap_inst
Definition: logging.h:279
log_fini
void log_fini(void)
Definition: logging.c:1120
log_target::vty
void * vty
Definition: logging.h:271