Changeset 397


Ignore:
Timestamp:
06/23/15 00:53:10 (9 years ago)
Author:
Maciej Komosinski
Message:

Colors in console (stdout)

Location:
cpp/common/loggers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/loggers/loggertostdout.cpp

    r378 r397  
    44
    55#include "loggertostdout.h"
     6#include <common/console.h>
    67#ifdef SHP
    78#include <FBaseSys.h> //AppLog
     
    910#include <stdio.h>
    1011#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, 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}
    1128
    1229void LoggerToStdout::handle(const char *obj, const char *method, int level, const char *msg)
     
    1936                file->printf(LOG_FORMAT "\n", LOG_LEVEL[level + 1], obj, method, msg);
    2037        else
    21                 printf(LOG_FORMAT "\n", LOG_LEVEL[level + 1], obj, method, msg);
     38                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
    2239#endif
    2340}
  • cpp/common/loggers/loggertostdout.h

    r382 r397  
    1313        VirtFILE *file;
    1414public:
    15         LoggerToStdout(int opts = 0, VirtFILE *_file = NULL) :LoggerBase(opts), file(_file) {}
     15        LoggerToStdout(int opts = 0, VirtFILE *_file = NULL);
    1616        void handle(const char *obj, const char *method, int level, const char *msg);
     17
     18        static const char* default_log_format[];
     19        static const char** default_log_level[];
     20        const char** log_level;
     21        const char* log_format;
    1722};
    1823
Note: See TracChangeset for help on using the changeset viewer.