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

Last change on this file since 438 was 397, checked in by Maciej Komosinski, 9 years ago

Colors in console (stdout)

  • Property svn:eol-style set to native
File size: 1.3 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
[109]4
[375]5#include "loggertostdout.h"
[397]6#include <common/console.h>
[109]7#ifdef SHP
8#include <FBaseSys.h> //AppLog
9#else
10#include <stdio.h>
11#endif
12
[397]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, 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{
25log_format=default_log_format[console_color_mode];
26log_level=default_log_level[console_color_mode];
27}
28
[378]29void LoggerToStdout::handle(const char *obj, const char *method, int level, const char *msg)
[109]30{
[378]31        if (level < -1) level = -1; else if (level>3) level = 3;
[109]32#ifdef SHP
[378]33        AppLog(LOG_FORMAT "\n",LOG_LEVEL[level+1],obj,method,msg);
[109]34#else
[244]35        if (file)
[378]36                file->printf(LOG_FORMAT "\n", LOG_LEVEL[level + 1], obj, method, msg);
[244]37        else
[397]38                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
[109]39#endif
40}
Note: See TracBrowser for help on using the repository browser.