libosmocore  0.9.6.311-c977
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
logging.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdarg.h>
10 #include <stdbool.h>
11 #include <osmocom/core/defs.h>
12 #include <osmocom/core/linuxlist.h>
13 
15 #define LOG_MAX_CTX 8
16 
17 #define LOG_MAX_FILTERS 8
18 
19 #define DEBUG
20 
21 #ifdef DEBUG
22 
27 #define DEBUGP(ss, fmt, args...) LOGP(ss, LOGL_DEBUG, fmt, ##args)
28 #define DEBUGPC(ss, fmt, args...) LOGPC(ss, LOGL_DEBUG, fmt, ##args)
29 #else
30 #define DEBUGP(xss, fmt, args...)
31 #define DEBUGPC(ss, fmt, args...)
32 #endif
33 
34 
35 void osmo_vlogp(int subsys, int level, const char *file, int line,
36  int cont, const char *format, va_list ap);
37 
38 void logp(int subsys, const char *file, int line, int cont, const char *format, ...) OSMO_DEPRECATED("Use DEBUGP* macros instead");
39 
46 #define LOGP(ss, level, fmt, args...) \
47  LOGPSRC(ss, level, NULL, 0, fmt, ## args)
48 
55 #define LOGPC(ss, level, fmt, args...) \
56  do { \
57  if (log_check_level(ss, level)) \
58  logp2(ss, level, __BASE_FILE__, __LINE__, 1, fmt, ##args); \
59  } while(0)
60 
73 #define LOGPSRC(ss, level, caller_file, caller_line, fmt, args...) \
74  do { \
75  if (log_check_level(ss, level)) {\
76  if (caller_file) \
77  logp2(ss, level, caller_file, caller_line, 0, fmt, ##args); \
78  else \
79  logp2(ss, level, __BASE_FILE__, __LINE__, 0, fmt, ##args); \
80  }\
81  } while(0)
82 
84 #define LOGL_DEBUG 1
85 #define LOGL_INFO 3
86 #define LOGL_NOTICE 5
87 #define LOGL_ERROR 7
88 #define LOGL_FATAL 8
90 /* logging levels defined by the library itself */
91 #define DLGLOBAL -1
92 #define DLLAPD -2
93 #define DLINP -3
94 #define DLMUX -4
95 #define DLMI -5
96 #define DLMIB -6
97 #define DLSMS -7
98 #define DLCTRL -8
99 #define DLGTP -9
100 #define DLSTATS -10
101 #define DLGSUP -11
102 #define DLOAP -12
103 #define DLSS7 -13
104 #define DLSCCP -14
105 #define DLSUA -15
106 #define DLM3UA -16
107 #define OSMO_NUM_DLIB 16
110 struct log_category {
111  uint8_t loglevel;
112  uint8_t enabled;
113 };
114 
116 struct log_info_cat {
117  const char *name;
118  const char *color;
119  const char *description;
120  uint8_t loglevel;
121  uint8_t enabled;
122 };
123 
125 struct log_context {
126  void *ctx[LOG_MAX_CTX+1];
127 };
128 
137 };
138 
149 };
150 
152 #define LOG_FILTER_ALL (1<<LOG_FLT_ALL)
153 
154 #define GPRS_CTX_NSVC LOG_CTX_GB_NSVC
155 
156 #define GPRS_CTX_BVC LOG_CTX_GB_BVC
157 
160 struct log_target;
161 
163 typedef int log_filter(const struct log_context *ctx,
164  struct log_target *target);
165 
166 struct log_info;
167 struct vty;
168 struct gsmtap_inst;
169 
170 typedef void log_print_filters(struct vty *vty,
171  const struct log_info *info,
172  const struct log_target *tgt);
173 
174 typedef void log_save_filters(struct vty *vty,
175  const struct log_info *info,
176  const struct log_target *tgt);
177 
179 struct log_info {
180  /* filter callback function */
182 
184  const struct log_info_cat *cat;
186  unsigned int num_cat;
188  unsigned int num_cat_user;
189 
194 };
195 
204 };
205 
207 struct log_target {
208  struct llist_head entry;
214 
217 
219  uint8_t loglevel;
221  unsigned int use_color:1;
223  unsigned int print_timestamp:1;
225  unsigned int print_filename:1;
227  unsigned int print_category:1;
229  unsigned int print_ext_timestamp:1;
230 
233 
234  union {
235  struct {
236  FILE *out;
237  const char *fname;
238  } tgt_file;
239 
240  struct {
241  int priority;
242  int facility;
243  } tgt_syslog;
244 
245  struct {
246  void *vty;
247  } tgt_vty;
248 
249  struct {
250  void *rb;
251  } tgt_rb;
252 
253  struct {
255  const char *ident;
256  const char *hostname;
257  } tgt_gsmtap;
258  };
259 
266  void (*output) (struct log_target *target, unsigned int level,
267  const char *string);
268 
281  void (*raw_output)(struct log_target *target, int subsys,
282  unsigned int level, const char *file, int line,
283  int cont, const char *format, va_list ap);
284 };
285 
286 /* use the above macros */
287 void logp2(int subsys, unsigned int level, const char *file,
288  int line, int cont, const char *format, ...)
289  __attribute__ ((format (printf, 6, 7)));
290 int log_init(const struct log_info *inf, void *talloc_ctx);
291 void log_fini(void);
292 int log_check_level(int subsys, unsigned int level);
293 
294 /* context management */
295 void log_reset_context(void);
296 int log_set_context(uint8_t ctx, void *value);
297 
298 /* filter on the targets */
299 void log_set_all_filter(struct log_target *target, int);
300 
301 void log_set_use_color(struct log_target *target, int);
302 void log_set_print_extended_timestamp(struct log_target *target, int);
303 void log_set_print_timestamp(struct log_target *target, int);
304 void log_set_print_filename(struct log_target *target, int);
305 void log_set_print_category(struct log_target *target, int);
306 void log_set_log_level(struct log_target *target, int log_level);
307 void log_parse_category_mask(struct log_target *target, const char* mask);
308 const char* log_category_name(int subsys);
309 int log_parse_level(const char *lvl);
310 const char *log_level_str(unsigned int lvl);
311 int log_parse_category(const char *category);
312 void log_set_category_filter(struct log_target *target, int category,
313  int enable, int level);
314 
315 /* management of the targets */
316 struct log_target *log_target_create(void);
317 void log_target_destroy(struct log_target *target);
319 struct log_target *log_target_create_file(const char *fname);
320 struct log_target *log_target_create_syslog(const char *ident, int option,
321  int facility);
322 struct log_target *log_target_create_gsmtap(const char *host, uint16_t port,
323  const char *ident,
324  bool ofd_wq_mode,
325  bool add_sink);
326 int log_target_file_reopen(struct log_target *tgt);
327 int log_targets_reopen(void);
328 
329 void log_add_target(struct log_target *target);
330 void log_del_target(struct log_target *target);
331 
332 /* Generate command string for VTY use */
334 const char *log_vty_command_description() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE;
335 
336 struct log_target *log_target_find(int type, const char *fname);
337 extern struct llist_head osmo_log_target_list;
338 
Information regarding one logging category.
Definition: logging.h:116
int filter_map
Internal data for filtering.
Definition: logging.h:211
void log_set_all_filter(struct log_target *target, int)
Enable the LOG_FLT_ALL log filter.
Definition: logging.c:545
int log_parse_level(const char *lvl)
Parse a human-readable log level into a numeric value.
Definition: logging.c:197
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
int log_parse_category(const char *category)
parse a human-readable log category into numeric form
Definition: logging.c:215
const char * name
name of category
Definition: logging.h:117
VTY logging.
Definition: logging.h:198
log_save_filters * save_fn
filter saving function
Definition: logging.h:191
Definition: logging.h:148
void log_set_print_timestamp(struct log_target *target, int)
Enable or disable printing of timestamps while logging.
Definition: logging.c:566
enum log_target_type type
the type of this log taget
Definition: logging.h:232
void * rb
Definition: logging.h:250
char subsys[16]
logging sub-system
Definition: gsmtap.h:120
const char * fname
Definition: logging.h:237
Configuration of single log category / sub-system.
Definition: logging.h:110
log_ctx_index
Indexes to indicate the object currently acted upon.
Definition: logging.h:131
struct rb_root __attribute__
Definition: conv_acc_generic.c:138
Definition: logging.h:133
#define OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Definition: defs.h:47
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:107
Definition: logging.h:145
uint8_t enabled
is this category enabled or not
Definition: logging.h:121
void * ctx[LOG_MAX_CTX+1]
Definition: logging.h:126
log_filter_index
Indexes to indicate objects that should be logged.
Definition: logging.h:142
Definition: logging.h:143
syslog based logging
Definition: logging.h:199
const char * log_level_str(unsigned int lvl)
convert a numeric log level into human-readable string
Definition: logging.c:206
const char * ident
Definition: logging.h:255
Definition: logging.h:146
General definitions that are meant to be included from header files.
struct log_target * log_target_create_syslog(const char *ident, int option, int facility)
log_target_type
Type of logging target.
Definition: logging.h:197
void log_target_destroy(struct log_target *target)
Unregister, close and delete a log target.
Definition: logging.c:752
void log_set_use_color(struct log_target *target, int)
Enable or disable the use of colored output.
Definition: logging.c:557
#define DEBUGP(ss, fmt, args...)
Log a debug message through the Osmocom logging framework.
Definition: logging.h:27
void * vty
Definition: logging.h:246
struct log_target::@7::@9 tgt_file
#define LOG_MAX_FILTERS
Maximum number of logging filters.
Definition: logging.h:17
struct llist_head osmo_log_target_list
one gsmtap instance
Definition: gsmtap_util.h:22
uint8_t enabled
is logging enabled?
Definition: logging.h:112
int facility
Definition: logging.h:242
uint8_t level
logging level
Definition: gsmtap.h:117
unsigned int print_category
should log messages be prefixed with a category name?
Definition: logging.h:227
void log_add_target(struct log_target *target)
Register a new log target with the logging core.
Definition: logging.c:497
int log_filter(const struct log_context *ctx, struct log_target *target)
Log filter function.
Definition: logging.h:163
osmo_strrb-backed logging
Definition: logging.h:202
Definition: logging.h:147
struct log_target::@7::@11 tgt_vty
int priority
Definition: logging.h:241
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:281
text file logging
Definition: logging.h:200
void log_del_target(struct log_target *target)
Unregister a log target from the logging core.
Definition: logging.c:505
struct log_target * log_target_create_file(const char *fname)
Create a new file-based log target.
Definition: logging.c:708
const char * log_vty_command_description() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Generates the logging command description for VTY.
Definition: logging.c:896
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:468
FILE * out
Definition: logging.h:236
struct log_target::@7::@10 tgt_syslog
stderr logging
Definition: logging.h:201
void log_save_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
Definition: logging.h:174
struct gsmtap_inst * gsmtap_inst
Definition: logging.h:254
Simple doubly linked list implementation.
void log_print_filters(struct vty *vty, const struct log_info *info, const struct log_target *tgt)
Definition: logging.h:170
unsigned int print_filename
should log messages be prefixed with a filename?
Definition: logging.h:225
(double) linked list header structure
Definition: linuxlist.h:46
const char * color
color string for cateyory
Definition: logging.h:118
Definition: logging.h:144
log_filter * filter_fn
Definition: logging.h:181
Definition: logging.h:134
void log_set_print_filename(struct log_target *target, int)
Enable or disable printing of the filename while logging.
Definition: logging.c:588
int log_set_context(uint8_t ctx, void *value)
Set the logging context.
Definition: logging.c:527
Definition: logging.h:135
void logp2(int subsys, unsigned int level, const char *file, int line, int cont, const char *format,...) __attribute__((format(printf
void log_set_print_category(struct log_target *target, int)
Enable or disable printing of the category name.
Definition: logging.c:599
struct log_category * categories
logging categories
Definition: logging.h:216
uint8_t loglevel
global log level
Definition: logging.h:219
struct log_target::@7::@13 tgt_gsmtap
struct log_target * log_target_create_stderr(void)
Create the STDERR log target.
Definition: logging.c:684
void log_parse_category_mask(struct log_target *target, const char *mask)
parse the log category mask
Definition: logging.c:238
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:619
GSMTAP network logging.
Definition: logging.h:203
void log_fini(void)
Definition: logging.c:1005
int log_check_level(int subsys, unsigned int level)
Check whether a log entry will be generated.
Definition: logging.c:1020
uint8_t loglevel
configured log-level
Definition: logging.h:111
Definition: logging.h:136
const char * log_category_name(int subsys)
Definition: logging.c:294
void int log_init(const struct log_info *inf, void *talloc_ctx)
Initialize the Osmocom logging core.
Definition: logging.c:960
Logging configuration, passed to log_init.
Definition: logging.h:179
uint8_t type
see GSMTAP_TYPE_*
Definition: gsmtap.h:113
unsigned int print_timestamp
should log messages be prefixed with a timestamp?
Definition: logging.h:223
Definition: logging.h:132
log_print_filters * print_fn
filter saving function
Definition: logging.h:193
unsigned int num_cat_user
total number of user categories (not library)
Definition: logging.h:188
Log context information, passed to filter.
Definition: logging.h:125
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:266
struct log_target * log_target_create(void)
Create a new log target skeleton.
Definition: logging.c:644
const struct log_info_cat * cat
per-category information
Definition: logging.h:184
unsigned int use_color
should color be used when printing log messages?
Definition: logging.h:221
const char * log_vty_command_string() OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE
Generates the logging command string for VTY.
Definition: logging.c:816
struct log_target * log_target_find(int type, const char *fname)
Find a registered log target.
Definition: logging.c:734
unsigned int print_ext_timestamp
should log messages be prefixed with an extended timestamp?
Definition: logging.h:229
int log_target_file_reopen(struct log_target *tgt)
close and re-open a log file (for log file rotation)
Definition: logging.c:778
const char * hostname
Definition: logging.h:256
structure representing a logging target
Definition: logging.h:207
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:437
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:608
struct log_target::@7::@12 tgt_rb
void log_reset_context(void)
Reset (clear) the logging context.
Definition: logging.c:511
#define LOG_MAX_CTX
Maximum number of logging contexts.
Definition: logging.h:15
uint8_t loglevel
currently selected log-level
Definition: logging.h:120
unsigned int num_cat
total number of categories
Definition: logging.h:186
void * filter_data[LOG_MAX_FILTERS+1]
Internal data for filtering.
Definition: logging.h:213
int log_targets_reopen(void)
close and re-open all log files (for log file rotation)
Definition: logging.c:793
void log_set_print_extended_timestamp(struct log_target *target, int)
Enable or disable printing of extended timestamps while logging.
Definition: logging.c:579
const char * description
description text
Definition: logging.h:119
struct llist_head entry
linked list
Definition: logging.h:208