Changeset 874 for cpp/common/loggers


Ignore:
Timestamp:
05/05/19 06:21:06 (6 years ago)
Author:
Maciej Komosinski
Message:

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

Location:
cpp/common/loggers
Files:
2 edited

Legend:

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

    r873 r874  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    148148                        {
    149149                                if (msgs.length() > 0) msgs += '\n';
    150                                 msgs += ssprintf(LOG_FORMAT, LOG_LEVEL[level + 1], obj, method, msg);
     150                                msgs += ssprintf(LOG_FORMAT, logLevelName(level), obj, method, msg);
    151151                        }
    152152                }
     
    170170        return string("");
    171171}
    172 
  • cpp/common/loggers/loggertostdout.cpp

    r522 r874  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1515
    1616const char** LoggerToStdout::default_log_level[] =
    17 { LOG_LEVEL, default_log_level_ansicolor };
     17{ LOG_LEVEL_ARRAY, default_log_level_ansicolor };
    1818
    1919const char* LoggerToStdout::default_log_format[] = //note trailing %s (so it's easy to append "\n" later)
     
    2929void LoggerToStdout::handleSingleLine(const char *obj, const char *method, int level, const char *msg)
    3030{
    31         if (level < -1) level = -1; else if (level>3) level = 3;
    3231#ifdef SHP
    33         AppLog(LOG_FORMAT "\n",LOG_LEVEL[level+1],obj,method,msg);
     32        AppLog(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
    3433#else
    3534        if (file)
    36                 file->printf(LOG_FORMAT "\n", LOG_LEVEL[level + 1], obj, method, msg);
     35                file->printf(LOG_FORMAT "\n", logLevelName(level), obj, method, msg);
    3736        else
     37        {
     38                if (level < -1) level = -1; else if (level > 3) level = 3;
    3839                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
     40        }
    3941#endif
    4042}
Note: See TracChangeset for help on using the changeset viewer.