ucx/logging.h

Fri, 08 Feb 2013 10:37:24 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 08 Feb 2013 10:37:24 +0100
changeset 81
86a23238d8a1
parent 80
0125e4089f88
child 82
6068d965328b
permissions
-rw-r--r--

changed logger to behave more like printf + added possibility to specify write function

     1 #ifndef LOGGING_H
     2 #define LOGGING_H
     4 #include "ucx.h"
     5 #include "map.h"
     6 #include "string.h"
     7 #include <stdio.h>
     9 #ifdef __cplusplus
    10 extern "C" {
    11 #endif
    13 /* leave enough space for custom log levels */
    14 #define UCX_LOGGER_ERROR        0x00
    15 #define UCX_LOGGER_WARN         0x10
    16 #define UCX_LOGGER_INFO         0x20
    17 #define UCX_LOGGER_TRACE        0x30
    19 #define UCX_LOGGER_LEVEL        0x01
    20 #define UCX_LOGGER_TIMESTAMP    0x02
    21 #define UCX_LOGGER_SOURCE       0x04
    23 typedef struct {
    24     FILE *stream;
    25     size_t(*writer)(const void*, size_t, size_t, FILE*);
    26     unsigned int level;
    27     unsigned int mask;
    28     UcxMap* levels;
    29 } UcxLogger;
    31 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask);
    32 void ucx_logger_free(UcxLogger* logger);
    34 /**
    35  * Sets the output stream and writer for this logger.
    36  * The parameters stream and writer may be NULL, if they shall remain unchanged
    37  * in the logger.
    38  * l
    39  * @param logger The logger
    40  * @param stream The stream the logger shall log to
    41  * @param writer A pointer to the write function
    42  */
    43 void ucx_logger_setoutput(UcxLogger *logger, FILE *stream,
    44         size_t(*writer)(const void*,size_t,size_t,FILE*));
    46 void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
    47         const unsigned int line, const char* format, ...);
    48 #define ucx_logger_log(logger, level, format...) \
    49     ucx_logger_logf(logger, level, __FILE__, __LINE__, format)
    50 #define ucx_logger_error(logger,format...) \
    51     ucx_logger_log(logger, UCX_LOGGER_ERROR, format)
    52 #define ucx_logger_info(logger,format...) \
    53     ucx_logger_log(logger, UCX_LOGGER_INFO, format)
    54 #define ucx_logger_warn(logger,format...) \
    55     ucx_logger_log(logger, UCX_LOGGER_WARN, format)
    56 #define ucx_logger_trace(logger,format...) \
    57     ucx_logger_log(logger, UCX_LOGGER_TRACE, format)
    59 #ifdef __cplusplus
    60 }
    61 #endif
    63 #endif /* LOGGING_H */

mercurial