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

Last change on this file since 874 was 874, checked in by Maciej Komosinski, 3 months ago

Introduced a function logLevelName() to avoid potential errors, e.g. forgetting "+1" in LOG_LEVEL[level+1]

  • Property svn:eol-style set to native
File size: 1.3 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#ifdef SHP
8#include <FBaseSys.h> //AppLog
9#else
10#include <stdio.h>
11#endif
12
13static const char* default_log_level_ansicolor[] =
14{ "[\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" };
15
16const char** LoggerToStdout::default_log_level[] =
17{ LOG_LEVEL_ARRAY, default_log_level_ansicolor };
18
19const char* LoggerToStdout::default_log_format[] = //note trailing %s (so it's easy to append "\n" later)
20{ LOG_FORMAT "%s", "%s%s.%s: %s\033[0m%s" };
21
22LoggerToStdout::LoggerToStdout(int opts, VirtFILE *_file)
23        :LoggerBase(opts), file(_file)
24{
25        log_format = default_log_format[console_color_mode];
26        log_level = default_log_level[console_color_mode];
27}
28
29void LoggerToStdout::handleSingleLine(const char *obj, const char *method, int level, const char *msg)
30{
31#ifdef SHP
32        AppLog(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
33#else
34        if (file)
35                file->printf(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
36        else
37        {
38                if (level < -1) level = -1; else if (level > 3) level = 3;
39                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
40        }
41#endif
42}
Note: See TracBrowser for help on using the repository browser.