source: cpp/common/loggers/loggertostdout.cpp @ 875

Last change on this file since 875 was 875, checked in by Maciej Komosinski, 2 weeks ago

Better use of LOG_level constants

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
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
14static 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
17const char** LoggerToStdout::default_log_level[] =
18{ LOG_LEVEL_ARRAY, default_log_level_ansicolor };
19
20const 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
23LoggerToStdout::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
30void 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}
Note: See TracBrowser for help on using the repository browser.