ucx/logging.h

changeset 81
86a23238d8a1
parent 80
0125e4089f88
child 82
6068d965328b
equal deleted inserted replaced
80:0125e4089f88 81:86a23238d8a1
20 #define UCX_LOGGER_TIMESTAMP 0x02 20 #define UCX_LOGGER_TIMESTAMP 0x02
21 #define UCX_LOGGER_SOURCE 0x04 21 #define UCX_LOGGER_SOURCE 0x04
22 22
23 typedef struct { 23 typedef struct {
24 FILE *stream; 24 FILE *stream;
25 size_t(*writer)(const void*, size_t, size_t, FILE*);
25 unsigned int level; 26 unsigned int level;
26 unsigned int mask; 27 unsigned int mask;
27 UcxMap* levels; 28 UcxMap* levels;
28 } UcxLogger; 29 } UcxLogger;
29 30
30 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask); 31 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask);
31 void ucx_logger_free(UcxLogger* logger); 32 void ucx_logger_free(UcxLogger* logger);
32 33
33 void ucx_logger_log(UcxLogger *logger, unsigned int level, 34 /**
34 const sstr_t message, const char* file, const unsigned int line); 35 * Sets the output stream and writer for this logger.
35 #define ucx_logger_error(l,m) \ 36 * The parameters stream and writer may be NULL, if they shall remain unchanged
36 ucx_logger_log(l, UCX_LOGGER_ERROR, m, __FILE__, __LINE__) 37 * in the logger.
37 #define ucx_logger_info(l,m) \ 38 * l
38 ucx_logger_log(l, UCX_LOGGER_INFO, m, __FILE__, __LINE__) 39 * @param logger The logger
39 #define ucx_logger_warn(l,m) \ 40 * @param stream The stream the logger shall log to
40 ucx_logger_log(l, UCX_LOGGER_WARN, m, __FILE__, __LINE__) 41 * @param writer A pointer to the write function
41 #define ucx_logger_trace(l,m) \ 42 */
42 ucx_logger_log(l, UCX_LOGGER_TRACE, m, __FILE__, __LINE__) 43 void ucx_logger_setoutput(UcxLogger *logger, FILE *stream,
44 size_t(*writer)(const void*,size_t,size_t,FILE*));
45
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)
43 58
44 #ifdef __cplusplus 59 #ifdef __cplusplus
45 } 60 }
46 #endif 61 #endif
47 62

mercurial