ucx/logging.c

changeset 70
88092b88ec00
parent 39
3e55bed345f9
child 110
53895e9a4bbb
equal deleted inserted replaced
69:0dbdd7e8c1fc 70:88092b88ec00
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2013 Olaf Wintermann. All rights reserved. 4 * Copyright 2014 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
73 size_t n; 73 size_t n;
74 74
75 if ((logger->mask & UCX_LOGGER_LEVEL) > 0) { 75 if ((logger->mask & UCX_LOGGER_LEVEL) > 0) {
76 text = (char*) ucx_map_int_get(logger->levels, level); 76 text = (char*) ucx_map_int_get(logger->levels, level);
77 n = strlen(text); 77 n = strlen(text);
78 n = n > 256 ? 256 : n;
78 memcpy(msg+k, text, n); 79 memcpy(msg+k, text, n);
79 k += n; 80 k += n;
80 msg[k++] = ' '; 81 msg[k++] = ' ';
81 } 82 }
82 if ((logger->mask & UCX_LOGGER_TIMESTAMP) > 0) { 83 if ((logger->mask & UCX_LOGGER_TIMESTAMP) > 0) {
85 } 86 }
86 if ((logger->mask & UCX_LOGGER_SOURCE) > 0) { 87 if ((logger->mask & UCX_LOGGER_SOURCE) > 0) {
87 n = strlen(file); 88 n = strlen(file);
88 memcpy(msg+k, file, n); 89 memcpy(msg+k, file, n);
89 k += n; 90 k += n;
90 #ifdef _WIN32 91 k += sprintf(msg+k, ":%u ", line);
91 k += _snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line);
92 #else
93 k += snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line);
94 #endif /* _WIN32 */
95 } 92 }
96 93
97 msg[k++] = '-'; msg[k++] = ' '; 94 msg[k++] = '-'; msg[k++] = ' ';
98 95
99 va_list args; 96 va_list args;

mercurial