Skip to content

Feature Request: verbose&notice&warning&error&fatalError ---addColor.. #2424

@yty

Description

@yty

I think it should be better to differentiate log files.
How do you think about it?

verbose->blur
notice->green
warning->Orange
error ->darkred
fatalError ->red

string ofGetLogLevelName(ofLogLevel level){
    HANDLE hCout = GetStdHandle(STD_OUTPUT_HANDLE); 

    switch(level){
        case OF_LOG_VERBOSE:
            SetConsoleTextAttribute(hCout,FOREGROUND_BLUE );
            return "verbose";
            break;
        case OF_LOG_NOTICE:
            SetConsoleTextAttribute(hCout,FOREGROUND_GREEN );
            return "notice";
            break;
        case OF_LOG_WARNING:
            SetConsoleTextAttribute(hCout,FOREGROUND_RED|FOREGROUND_GREEN );
            return "warning";
            break;
        case OF_LOG_ERROR:
            SetConsoleTextAttribute(hCout,FOREGROUND_RED );
            return "error";
            break;
        case OF_LOG_FATAL_ERROR:
            SetConsoleTextAttribute(hCout,FOREGROUND_RED|FOREGROUND_INTENSITY );
            return "fatal error";
            break;
        case OF_LOG_SILENT:
            return "silent";
            break;
        default:
            return "";
    }
}

void ofConsoleLoggerChannel::log(ofLogLevel level, const string & module, const string & message){
    // print to cerr for OF_LOG_ERROR and OF_LOG_FATAL_ERROR, everything else to cout 
    ostream& out = level < OF_LOG_ERROR ? cout : cerr;
    out << "[";
    // only print the module name if it's not "OF"
    if(module != "OF") {
        out << module << ":";
    }
    HANDLE hCout = GetStdHandle(STD_OUTPUT_HANDLE); 

    out << ofGetLogLevelName(level);
    SetConsoleTextAttribute(hCout,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE );
    out<< "] "<< message << endl;
}   

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions