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 */
46 #define OSMO_NUM_DLIB 7
56 const char *description;
61 /* log context information, passed to filter */
63 void *ctx[LOG_MAX_CTX+1];
68 typedef int log_filter(const struct log_context *ctx,
69 struct log_target *target);
72 /* filter callback function */
73 log_filter *filter_fn;
75 /* per-category information */
76 struct log_info_cat *cat;
78 unsigned int num_cat_user;
81 enum log_target_type {
89 struct llist_head entry;
92 void *filter_data[LOG_MAX_FILTERS+1];
94 struct log_category *categories;
97 unsigned int use_color:1;
98 unsigned int print_timestamp:1;
100 enum log_target_type type;
118 void (*output) (struct log_target *target, unsigned int level,
122 /* use the above macros */
123 void logp2(int subsys, unsigned int level, char *file,
124 int line, int cont, const char *format, ...)
125 __attribute__ ((format (printf, 6, 7)));
126 int log_init(const struct log_info *inf, void *talloc_ctx);
128 /* context management */
129 void log_reset_context(void);
130 int log_set_context(uint8_t ctx, void *value);
132 /* filter on the targets */
133 void log_set_all_filter(struct log_target *target, int);
135 void log_set_use_color(struct log_target *target, int);
136 void log_set_print_timestamp(struct log_target *target, int);
137 void log_set_log_level(struct log_target *target, int log_level);
138 void log_parse_category_mask(struct log_target *target, const char* mask);
139 int log_parse_level(const char *lvl);
140 const char *log_level_str(unsigned int lvl);
141 int log_parse_category(const char *category);
142 void log_set_category_filter(struct log_target *target, int category,
143 int enable, int level);
145 /* management of the targets */
146 struct log_target *log_target_create(void);
147 void log_target_destroy(struct log_target *target);
148 struct log_target *log_target_create_stderr(void);
149 struct log_target *log_target_create_file(const char *fname);
150 struct log_target *log_target_create_syslog(const char *ident, int option,
152 int log_target_file_reopen(struct log_target *tgt);
154 void log_add_target(struct log_target *target);
155 void log_del_target(struct log_target *target);
157 /* Generate command string for VTY use */
158 const char *log_vty_command_string(const struct log_info *info);
159 const char *log_vty_command_description(const struct log_info *info);
161 struct log_target *log_target_find(int type, const char *fname);
162 extern struct llist_head osmo_log_target_list;
164 #endif /* _OSMOCORE_LOGGING_H */