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

Last change on this file since 999 was 875, checked in by Maciej Komosinski, 6 years ago

Better use of LOG_level constants

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[874]2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[109]4
[375]5#include "loggertostdout.h"
[397]6#include <common/console.h>
[875]7#include <assert.h>
[109]8#ifdef SHP
9#include <FBaseSys.h> //AppLog
10#else
11#include <stdio.h>
12#endif
13
[397]14static const char* default_log_level_ansicolor[] =
[522]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" };
[397]16
17const char** LoggerToStdout::default_log_level[] =
[874]18{ LOG_LEVEL_ARRAY, default_log_level_ansicolor };
[397]19
[522]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" };
[397]22
23LoggerToStdout::LoggerToStdout(int opts, VirtFILE *_file)
24        :LoggerBase(opts), file(_file)
25{
[522]26        log_format = default_log_format[console_color_mode];
27        log_level = default_log_level[console_color_mode];
[397]28}
29
[511]30void LoggerToStdout::handleSingleLine(const char *obj, const char *method, int level, const char *msg)
[109]31{
32#ifdef SHP
[874]33        AppLog(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
[109]34#else
[244]35        if (file)
[874]36                file->printf(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
[244]37        else
[874]38        {
[875]39                assert((level>=LOG_MIN) && (level<=LOG_MAX));
40                level = min(LOG_MAX, max(LOG_MIN, level));
[397]41                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
[874]42        }
[109]43#endif
44}
Note: See TracBrowser for help on using the repository browser.