diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-03-26 21:35:28 +0800 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-03-26 21:35:28 +0800 |
commit | 71ba85e4aff1374bee0316cab9a627d03ba1eee5 (patch) | |
tree | 367111a205d06bf0c86d81208a5db006a5f2e5a7 /libosmocore/include/osmocore | |
parent | dc5062b1850089021199abd686a802b59bed7c46 (diff) | |
parent | 3ae2758fba1dc9b364238c6e1e7d591b12c3d878 (diff) |
Merge commit '3ae2758fba1dc9b364238c6e1e7d591b12c3d878'
Diffstat (limited to 'libosmocore/include/osmocore')
-rw-r--r-- | libosmocore/include/osmocore/Makefile.am | 2 | ||||
-rw-r--r-- | libosmocore/include/osmocore/logging.h | 130 | ||||
-rw-r--r-- | libosmocore/include/osmocore/write_queue.h | 1 |
3 files changed, 132 insertions, 1 deletions
diff --git a/libosmocore/include/osmocore/Makefile.am b/libosmocore/include/osmocore/Makefile.am index fb4f089b7..1c3a33f33 100644 --- a/libosmocore/include/osmocore/Makefile.am +++ b/libosmocore/include/osmocore/Makefile.am @@ -1,7 +1,7 @@ osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h \ tlv.h bitvec.h comp128.h statistics.h gsm_utils.h utils.h \ gsmtap.h write_queue.h rsl.h gsm48.h rxlev_stat.h mncc.h \ - gsm48_ie.h + gsm48_ie.h logging.h if ENABLE_TALLOC osmocore_HEADERS += talloc.h diff --git a/libosmocore/include/osmocore/logging.h b/libosmocore/include/osmocore/logging.h new file mode 100644 index 000000000..93f18a07b --- /dev/null +++ b/libosmocore/include/osmocore/logging.h @@ -0,0 +1,130 @@ +#ifndef _OSMOCORE_LOGGING_H +#define _OSMOCORE_LOGGING_H + +#include <stdio.h> +#include <stdint.h> +#include <osmocore/linuxlist.h> + +#define LOG_MAX_CATEGORY 32 +#define LOG_MAX_CTX 8 +#define LOG_MAX_FILTERS 8 + +#define DEBUG + +#ifdef DEBUG +#define DEBUGP(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args) +#define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args) +#else +#define DEBUGP(xss, fmt, args...) +#define DEBUGPC(ss, fmt, args...) +#endif + +#define static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1]; + +char *hexdump(const unsigned char *buf, int len); +void logp(unsigned int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6))); + +/* new logging interface */ +#define LOGP(ss, level, fmt, args...) \ + logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args) +#define LOGPC(ss, level, fmt, args...) \ + logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args) + +/* different levels */ +#define LOGL_DEBUG 1 /* debugging information */ +#define LOGL_INFO 3 +#define LOGL_NOTICE 5 /* abnormal/unexpected condition */ +#define LOGL_ERROR 7 /* error condition, requires user action */ +#define LOGL_FATAL 8 /* fatal, program aborted */ + +#define LOG_FILTER_ALL 0x0001 + +struct log_category { + uint8_t loglevel; + uint8_t enabled; +}; + +struct log_info_cat { + const char *name; + const char *color; + const char *description; + uint8_t loglevel; + uint8_t enabled; +}; + +/* log context information, passed to filter */ +struct log_context { + void *ctx[LOG_MAX_CTX+1]; +}; + +struct log_target; + +typedef int log_filter(const struct log_context *ctx, + struct log_target *target); + +struct log_info { + /* filter callback function */ + log_filter *filter_fn; + + /* per-category information */ + const struct log_info_cat *cat; + unsigned int num_cat; +}; + +struct log_target { + struct llist_head entry; + + int filter_map; + void *filter_data[LOG_MAX_FILTERS+1]; + + struct log_category categories[LOG_MAX_CATEGORY+1]; + uint8_t loglevel; + int use_color:1; + int print_timestamp:1; + + union { + struct { + FILE *out; + } tgt_stdout; + + struct { + int priority; + } tgt_syslog; + + struct { + void *vty; + } tgt_vty; + }; + + void (*output) (struct log_target *target, const char *string); +}; + +/* use the above macros */ +void logp2(unsigned int subsys, unsigned int level, char *file, + int line, int cont, const char *format, ...) + __attribute__ ((format (printf, 6, 7))); +void log_init(const struct log_info *cat); + +/* context management */ +void log_reset_context(void); +int log_set_context(uint8_t ctx, void *value); + +/* filter on the targets */ +void log_set_all_filter(struct log_target *target, int); + +void log_set_use_color(struct log_target *target, int); +void log_set_print_timestamp(struct log_target *target, int); +void log_set_log_level(struct log_target *target, int log_level); +void log_parse_category_mask(struct log_target *target, const char* mask); +int log_parse_level(const char *lvl); +int log_parse_category(const char *category); +void log_set_category_filter(struct log_target *target, int category, + int enable, int level); + +/* management of the targets */ +struct log_target *log_target_create(void); +struct log_target *log_target_create_stderr(void); +void log_add_target(struct log_target *target); +void log_del_target(struct log_target *target); + +#endif /* _OSMOCORE_LOGGING_H */ diff --git a/libosmocore/include/osmocore/write_queue.h b/libosmocore/include/osmocore/write_queue.h index c84000c1e..64d4159a0 100644 --- a/libosmocore/include/osmocore/write_queue.h +++ b/libosmocore/include/osmocore/write_queue.h @@ -38,6 +38,7 @@ struct write_queue { }; void write_queue_init(struct write_queue *queue, int max_length); +void write_queue_clear(struct write_queue *queue); int write_queue_enqueue(struct write_queue *queue, struct msgb *data); int write_queue_bfd_cb(struct bsc_fd *fd, unsigned int what); |