1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "loggertostdout.h" |
---|
6 | #include <common/console.h> |
---|
7 | #include <assert.h> |
---|
8 | #ifdef SHP |
---|
9 | #include <FBaseSys.h> //AppLog |
---|
10 | #else |
---|
11 | #include <stdio.h> |
---|
12 | #endif |
---|
13 | |
---|
14 | static const char* default_log_level_ansicolor[] = |
---|
15 | { "[\033[2mDEBUG\033[0m] \033[2m", "", "[\033[33mWARN\033[0m] \033[1m", "[\033[1;31mERROR\033[0m] \033[1m", "[\033[1;31mCRITICAL\033[0m] \033[1m" }; |
---|
16 | |
---|
17 | const char** LoggerToStdout::default_log_level[] = |
---|
18 | { LOG_LEVEL_ARRAY, default_log_level_ansicolor }; |
---|
19 | |
---|
20 | const char* LoggerToStdout::default_log_format[] = //note trailing %s (so it's easy to append "\n" later) |
---|
21 | { LOG_FORMAT "%s", "%s%s.%s: %s\033[0m%s" }; |
---|
22 | |
---|
23 | LoggerToStdout::LoggerToStdout(int opts, VirtFILE *_file) |
---|
24 | :LoggerBase(opts), file(_file) |
---|
25 | { |
---|
26 | log_format = default_log_format[console_color_mode]; |
---|
27 | log_level = default_log_level[console_color_mode]; |
---|
28 | } |
---|
29 | |
---|
30 | void LoggerToStdout::handleSingleLine(const char *obj, const char *method, int level, const char *msg) |
---|
31 | { |
---|
32 | #ifdef SHP |
---|
33 | AppLog(LOG_FORMAT "\n", logLevelName(level), obj, method, msg); |
---|
34 | #else |
---|
35 | if (file) |
---|
36 | file->printf(LOG_FORMAT "\n", logLevelName(level), obj, method, msg); |
---|
37 | else |
---|
38 | { |
---|
39 | assert((level>=LOG_MIN) && (level<=LOG_MAX)); |
---|
40 | level = min(LOG_MAX, max(LOG_MIN, level)); |
---|
41 | printf(log_format, log_level[level + 1], obj, method, msg, "\n"); |
---|
42 | } |
---|
43 | #endif |
---|
44 | } |
---|