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 */
41 #define OSMO_NUM_DLIB 1
51 const char *description;
56 /* log context information, passed to filter */
58 void *ctx[LOG_MAX_CTX+1];
63 typedef int log_filter(const struct log_context *ctx,
64 struct log_target *target);
67 /* filter callback function */
68 log_filter *filter_fn;
70 /* per-category information */
71 struct log_info_cat *cat;
73 unsigned int num_cat_user;
76 enum log_target_type {
84 struct llist_head entry;
87 void *filter_data[LOG_MAX_FILTERS+1];
89 struct log_category *categories;
93 int print_timestamp:1;
95 enum log_target_type type;
113 void (*output) (struct log_target *target, unsigned int level,
117 /* use the above macros */
118 void logp2(int subsys, unsigned int level, char *file,
119 int line, int cont, const char *format, ...)
120 __attribute__ ((format (printf, 6, 7)));
121 int log_init(const struct log_info *inf, void *talloc_ctx);
123 /* context management */
124 void log_reset_context(void);
125 int log_set_context(uint8_t ctx, void *value);
127 /* filter on the targets */
128 void log_set_all_filter(struct log_target *target, int);
130 void log_set_use_color(struct log_target *target, int);
131 void log_set_print_timestamp(struct log_target *target, int);
132 void log_set_log_level(struct log_target *target, int log_level);
133 void log_parse_category_mask(struct log_target *target, const char* mask);
134 int log_parse_level(const char *lvl);
135 const char *log_level_str(unsigned int lvl);
136 int log_parse_category(const char *category);
137 void log_set_category_filter(struct log_target *target, int category,
138 int enable, int level);
140 /* management of the targets */
141 struct log_target *log_target_create(void);
142 void log_target_destroy(struct log_target *target);
143 struct log_target *log_target_create_stderr(void);
144 struct log_target *log_target_create_file(const char *fname);
145 struct log_target *log_target_create_syslog(const char *ident, int option,
147 int log_target_file_reopen(struct log_target *tgt);
149 void log_add_target(struct log_target *target);
150 void log_del_target(struct log_target *target);
152 /* Generate command string for VTY use */
153 const char *log_vty_command_string(const struct log_info *info);
154 const char *log_vty_command_description(const struct log_info *info);
156 struct log_target *log_target_find(int type, const char *fname);
157 extern struct llist_head osmo_log_target_list;
159 #endif /* _OSMOCORE_LOGGING_H */