1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "log.h" |
---|
6 | #include <common/nonstd_stdio.h> |
---|
7 | #include "util-string.h" |
---|
8 | #include "Convert.h" |
---|
9 | #include <assert.h> |
---|
10 | #include <algorithm> |
---|
11 | |
---|
12 | const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " }; |
---|
13 | |
---|
14 | void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va) |
---|
15 | { |
---|
16 | string buf = ssprintf_va(msgf, va); |
---|
17 | logMessage(obj, method, level, buf.c_str()); |
---|
18 | } |
---|
19 | |
---|
20 | void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...) |
---|
21 | { |
---|
22 | va_list argptr; |
---|
23 | va_start(argptr, msgf); |
---|
24 | logPrintf_va(obj, method, level, msgf, argptr); |
---|
25 | va_end(argptr); |
---|
26 | } |
---|
27 | |
---|
28 | void log_printf(const char *msgf, ...) |
---|
29 | { |
---|
30 | va_list argptr; |
---|
31 | va_start(argptr, msgf); |
---|
32 | logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr); |
---|
33 | va_end(argptr); |
---|
34 | } |
---|
35 | |
---|
36 | const char* logLevelName(int level) |
---|
37 | { |
---|
38 | assert((level>=LOG_MIN) && (level<=LOG_MAX)); |
---|
39 | level = std::min(LOG_MAX, std::max(LOG_MIN, level)); |
---|
40 | return LOG_LEVEL_ARRAY[level + 1]; |
---|
41 | } |
---|