ucx/logging.h

Fri, 08 Feb 2013 11:25:04 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 08 Feb 2013 11:25:04 +0100
changeset 82
6068d965328b
parent 81
86a23238d8a1
child 83
3b552d7a9610
permissions
-rw-r--r--

logger can now log timestamps

olaf@57 1 #ifndef LOGGING_H
olaf@57 2 #define LOGGING_H
olaf@57 3
universe@69 4 #include "ucx.h"
universe@80 5 #include "map.h"
olaf@57 6 #include "string.h"
olaf@57 7 #include <stdio.h>
olaf@57 8
olaf@57 9 #ifdef __cplusplus
olaf@57 10 extern "C" {
olaf@57 11 #endif
olaf@57 12
olaf@57 13 /* leave enough space for custom log levels */
universe@80 14 #define UCX_LOGGER_ERROR 0x00
universe@80 15 #define UCX_LOGGER_WARN 0x10
universe@80 16 #define UCX_LOGGER_INFO 0x20
universe@80 17 #define UCX_LOGGER_TRACE 0x30
universe@80 18
universe@80 19 #define UCX_LOGGER_LEVEL 0x01
universe@80 20 #define UCX_LOGGER_TIMESTAMP 0x02
universe@80 21 #define UCX_LOGGER_SOURCE 0x04
olaf@57 22
olaf@57 23 typedef struct {
olaf@57 24 FILE *stream;
universe@82 25 write_func writer;
universe@82 26 char *dateformat;
olaf@57 27 unsigned int level;
universe@80 28 unsigned int mask;
universe@80 29 UcxMap* levels;
olaf@57 30 } UcxLogger;
olaf@57 31
universe@80 32 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask);
universe@80 33 void ucx_logger_free(UcxLogger* logger);
olaf@57 34
universe@81 35 void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
universe@81 36 const unsigned int line, const char* format, ...);
universe@81 37 #define ucx_logger_log(logger, level, format...) \
universe@81 38 ucx_logger_logf(logger, level, __FILE__, __LINE__, format)
universe@81 39 #define ucx_logger_error(logger,format...) \
universe@81 40 ucx_logger_log(logger, UCX_LOGGER_ERROR, format)
universe@81 41 #define ucx_logger_info(logger,format...) \
universe@81 42 ucx_logger_log(logger, UCX_LOGGER_INFO, format)
universe@81 43 #define ucx_logger_warn(logger,format...) \
universe@81 44 ucx_logger_log(logger, UCX_LOGGER_WARN, format)
universe@81 45 #define ucx_logger_trace(logger,format...) \
universe@81 46 ucx_logger_log(logger, UCX_LOGGER_TRACE, format)
olaf@57 47
olaf@57 48 #ifdef __cplusplus
olaf@57 49 }
olaf@57 50 #endif
olaf@57 51
olaf@57 52 #endif /* LOGGING_H */

mercurial