1 #ifndef _OSMOCORE_LOGGING_H
2 #define _OSMOCORE_LOGGING_H
6 #include <osmocom/core/linuxlist.h>
9 #define LOG_MAX_FILTERS 8
14 #define DEBUGP(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args)
15 #define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args)
17 #define DEBUGP(xss, fmt, args...)
18 #define DEBUGPC(ss, fmt, args...)
22 void logp(int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
24 /* new logging interface */
25 #define LOGP(ss, level, fmt, args...) \
26 logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args)
27 #define LOGPC(ss, level, fmt, args...) \
28 logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args)
30 /* different levels */
31 #define LOGL_DEBUG 1 /* debugging information */
33 #define LOGL_NOTICE 5 /* abnormal/unexpected condition */
34 #define LOGL_ERROR 7 /* error condition, requires user action */
35 #define LOGL_FATAL 8 /* fatal, program aborted */
37 #define LOG_FILTER_ALL 0x0001
39 /* logging levels defined by the library itself */
42 #define OSMO_NUM_DLIB 2
52 const char *description;
57 /* log context information, passed to filter */
59 void *ctx[LOG_MAX_CTX+1];
64 typedef int log_filter(const struct log_context *ctx,
65 struct log_target *target);
68 /* filter callback function */
69 log_filter *filter_fn;
71 /* per-category information */
72 struct log_info_cat *cat;
74 unsigned int num_cat_user;
77 enum log_target_type {
85 struct llist_head entry;
88 void *filter_data[LOG_MAX_FILTERS+1];
90 struct log_category *categories;
94 int print_timestamp:1;
96 enum log_target_type type;
114 void (*output) (struct log_target *target, unsigned int level,
118 /* use the above macros */
119 void logp2(int subsys, unsigned int level, char *file,
120 int line, int cont, const char *format, ...)
121 __attribute__ ((format (printf, 6, 7)));
122 int log_init(const struct log_info *inf, void *talloc_ctx);
124 /* context management */
125 void log_reset_context(void);
126 int log_set_context(uint8_t ctx, void *value);
128 /* filter on the targets */
129 void log_set_all_filter(struct log_target *target, int);
131 void log_set_use_color(struct log_target *target, int);
132 void log_set_print_timestamp(struct log_target *target, int);
133 void log_set_log_level(struct log_target *target, int log_level);
134 void log_parse_category_mask(struct log_target *target, const char* mask);
135 int log_parse_level(const char *lvl);
136 const char *log_level_str(unsigned int lvl);
137 int log_parse_category(const char *category);
138 void log_set_category_filter(struct log_target *target, int category,
139 int enable, int level);
141 /* management of the targets */
142 struct log_target *log_target_create(void);
143 void log_target_destroy(struct log_target *target);
144 struct log_target *log_target_create_stderr(void);
145 struct log_target *log_target_create_file(const char *fname);
146 struct log_target *log_target_create_syslog(const char *ident, int option,
148 int log_target_file_reopen(struct log_target *tgt);
150 void log_add_target(struct log_target *target);
151 void log_del_target(struct log_target *target);
153 /* Generate command string for VTY use */
154 const char *log_vty_command_string(const struct log_info *info);
155 const char *log_vty_command_description(const struct log_info *info);
157 struct log_target *log_target_find(int type, const char *fname);
158 extern struct llist_head osmo_log_target_list;
160 #endif /* _OSMOCORE_LOGGING_H */