ucx/logging.c

changeset 95
ecfdc1c4a552
parent 83
3b552d7a9610
child 103
08018864fb91
equal deleted inserted replaced
94:57ea041df22f 95:ecfdc1c4a552
7 UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask) { 7 UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask) {
8 UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger)); 8 UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger));
9 if (logger != NULL) { 9 if (logger != NULL) {
10 logger->stream = stream; 10 logger->stream = stream;
11 logger->writer = (write_func)fwrite; 11 logger->writer = (write_func)fwrite;
12 logger->dateformat = "%F %T %z "; 12 logger->dateformat = (char*) "%F %T %z ";
13 logger->level = level; 13 logger->level = level;
14 logger->mask = mask; 14 logger->mask = mask;
15 logger->levels = ucx_map_new(8); 15 logger->levels = ucx_map_new(8);
16 16
17 unsigned int l; 17 unsigned int l;
18 l = UCX_LOGGER_ERROR; 18 l = UCX_LOGGER_ERROR;
19 ucx_map_int_put(logger->levels, l, "[ERROR]"); 19 ucx_map_int_put(logger->levels, l, (void*) "[ERROR]");
20 l = UCX_LOGGER_WARN; 20 l = UCX_LOGGER_WARN;
21 ucx_map_int_put(logger->levels, l, "[WARNING]"); 21 ucx_map_int_put(logger->levels, l, (void*) "[WARNING]");
22 l = UCX_LOGGER_INFO; 22 l = UCX_LOGGER_INFO;
23 ucx_map_int_put(logger->levels, l, "[INFO]"); 23 ucx_map_int_put(logger->levels, l, (void*) "[INFO]");
24 l = UCX_LOGGER_TRACE; 24 l = UCX_LOGGER_TRACE;
25 ucx_map_int_put(logger->levels, l, "[TRACE]"); 25 ucx_map_int_put(logger->levels, l, (void*) "[TRACE]");
26 } 26 }
27 27
28 return logger; 28 return logger;
29 } 29 }
30 30
68 va_end (args); 68 va_end (args);
69 69
70 msg[k++] = '\n'; 70 msg[k++] = '\n';
71 71
72 logger->writer(msg, 1, k, logger->stream); 72 logger->writer(msg, 1, k, logger->stream);
73 fflush(logger->stream);
74 } 73 }
75 } 74 }

mercurial