1 #ifndef LOGGING_H |
1 #ifndef LOGGING_H |
2 #define LOGGING_H |
2 #define LOGGING_H |
3 |
3 |
4 #include "ucx.h" |
4 #include "ucx.h" |
|
5 #include "map.h" |
5 #include "string.h" |
6 #include "string.h" |
6 #include <stdio.h> |
7 #include <stdio.h> |
7 |
8 |
8 #ifdef __cplusplus |
9 #ifdef __cplusplus |
9 extern "C" { |
10 extern "C" { |
10 #endif |
11 #endif |
11 |
12 |
12 /* leave enough space for custom log levels */ |
13 /* leave enough space for custom log levels */ |
13 #define UCX_LOGGER_ERROR 0x00 |
14 #define UCX_LOGGER_ERROR 0x00 |
14 #define UCX_LOGGER_WARN 0x10 |
15 #define UCX_LOGGER_WARN 0x10 |
15 #define UCX_LOGGER_INFO 0x20 |
16 #define UCX_LOGGER_INFO 0x20 |
16 #define UCX_LOGGER_TRACE 0x30 |
17 #define UCX_LOGGER_TRACE 0x30 |
|
18 |
|
19 #define UCX_LOGGER_LEVEL 0x01 |
|
20 #define UCX_LOGGER_TIMESTAMP 0x02 |
|
21 #define UCX_LOGGER_SOURCE 0x04 |
17 |
22 |
18 typedef struct { |
23 typedef struct { |
19 FILE *stream; |
24 FILE *stream; |
20 unsigned int level; |
25 unsigned int level; |
|
26 unsigned int mask; |
|
27 UcxMap* levels; |
21 } UcxLogger; |
28 } UcxLogger; |
22 |
29 |
23 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); |
30 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level, unsigned int mask); |
24 /* neither provide a free function nor a parameter for an allocator */ |
31 void ucx_logger_free(UcxLogger* logger); |
25 |
32 |
26 void ucx_logger_log(UcxLogger *logger, unsigned int level, |
33 void ucx_logger_log(UcxLogger *logger, unsigned int level, |
27 const sstr_t message); |
34 const sstr_t message, const char* file, const unsigned int line); |
28 #define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) |
35 #define ucx_logger_error(l,m) \ |
29 #define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) |
36 ucx_logger_log(l, UCX_LOGGER_ERROR, m, __FILE__, __LINE__) |
30 #define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m) |
37 #define ucx_logger_info(l,m) \ |
31 #define ucx_logger_trace(l,m) ucx_logger_log(l, UCX_LOGGER_TRACE, m) |
38 ucx_logger_log(l, UCX_LOGGER_INFO, m, __FILE__, __LINE__) |
|
39 #define ucx_logger_warn(l,m) \ |
|
40 ucx_logger_log(l, UCX_LOGGER_WARN, m, __FILE__, __LINE__) |
|
41 #define ucx_logger_trace(l,m) \ |
|
42 ucx_logger_log(l, UCX_LOGGER_TRACE, m, __FILE__, __LINE__) |
32 |
43 |
33 #ifdef __cplusplus |
44 #ifdef __cplusplus |
34 } |
45 } |
35 #endif |
46 #endif |
36 |
47 |