1 #ifndef _OSMOCORE_LOGGING_H
2 #define _OSMOCORE_LOGGING_H
6 #include <osmocore/linuxlist.h>
8 #define LOG_MAX_CATEGORY 32
10 #define LOG_MAX_FILTERS 8
15 #define DEBUGP(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args)
16 #define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args)
18 #define DEBUGP(xss, fmt, args...)
19 #define DEBUGPC(ss, fmt, args...)
23 void logp(unsigned int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
25 /* new logging interface */
26 #define LOGP(ss, level, fmt, args...) \
27 logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args)
28 #define LOGPC(ss, level, fmt, args...) \
29 logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args)
31 /* different levels */
32 #define LOGL_DEBUG 1 /* debugging information */
34 #define LOGL_NOTICE 5 /* abnormal/unexpected condition */
35 #define LOGL_ERROR 7 /* error condition, requires user action */
36 #define LOGL_FATAL 8 /* fatal, program aborted */
38 #define LOG_FILTER_ALL 0x0001
48 const char *description;
53 /* log context information, passed to filter */
55 void *ctx[LOG_MAX_CTX+1];
60 typedef int log_filter(const struct log_context *ctx,
61 struct log_target *target);
64 /* filter callback function */
65 log_filter *filter_fn;
67 /* per-category information */
68 const struct log_info_cat *cat;
73 struct llist_head entry;
76 void *filter_data[LOG_MAX_FILTERS+1];
78 struct log_category categories[LOG_MAX_CATEGORY+1];
81 int print_timestamp:1;
98 void (*output) (struct log_target *target, const char *string);
101 /* use the above macros */
102 void logp2(unsigned int subsys, unsigned int level, char *file,
103 int line, int cont, const char *format, ...)
104 __attribute__ ((format (printf, 6, 7)));
105 void log_init(const struct log_info *cat);
107 /* context management */
108 void log_reset_context(void);
109 int log_set_context(uint8_t ctx, void *value);
111 /* filter on the targets */
112 void log_set_all_filter(struct log_target *target, int);
114 void log_set_use_color(struct log_target *target, int);
115 void log_set_print_timestamp(struct log_target *target, int);
116 void log_set_log_level(struct log_target *target, int log_level);
117 void log_parse_category_mask(struct log_target *target, const char* mask);
118 int log_parse_level(const char *lvl);
119 const char *log_level_str(unsigned int lvl);
120 int log_parse_category(const char *category);
121 void log_set_category_filter(struct log_target *target, int category,
122 int enable, int level);
124 /* management of the targets */
125 struct log_target *log_target_create(void);
126 void log_target_destroy(struct log_target *target);
127 struct log_target *log_target_create_stderr(void);
128 struct log_target *log_target_create_file(const char *fname);
129 int log_target_file_reopen(struct log_target *tgt);
131 void log_add_target(struct log_target *target);
132 void log_del_target(struct log_target *target);
134 /* Gernerate command argument strings for VTY use */
135 const char *log_vty_category_string(struct log_info *info);
136 const char *log_vty_level_string(struct log_info *info);
138 #endif /* _OSMOCORE_LOGGING_H */