Changeset 875 for cpp/common


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

Better use of LOG_level constants

Location:
cpp/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/log.cpp

    r874 r875  
    77#include "util-string.h"
    88#include "Convert.h"
     9#include <assert.h>
    910
    1011const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " };
     
    3435const char* logLevelName(int level)
    3536{
    36         level = min(LOG_CRITICAL, max(LOG_DEBUG, level));
     37        assert((level>=LOG_MIN) && (level<=LOG_MAX));
     38        level = min(LOG_MAX, max(LOG_MIN, level));
    3739        return LOG_LEVEL_ARRAY[level + 1];
    3840}
  • cpp/common/log.h

    r874 r875  
    2020
    2121//level (importance) of a message
     22#define LOG_MIN LOG_DEBUG
    2223#define LOG_DEBUG -1 //debugging information, not needed for final users
    2324#define LOG_INFO 0 //information
     
    2526#define LOG_ERROR 2 //uncorrected error, can cause malfunction
    2627#define LOG_CRITICAL 3 //serious error, causes side effects. User should save what can be saved and restart the application
     28#define LOG_MAX LOG_CRITICAL
    2729
    2830#endif
  • cpp/common/loggers/loggertostdout.cpp

    r874 r875  
    55#include "loggertostdout.h"
    66#include <common/console.h>
     7#include <assert.h>
    78#ifdef SHP
    89#include <FBaseSys.h> //AppLog
     
    3637        else
    3738        {
    38                 if (level < -1) level = -1; else if (level > 3) level = 3;
     39                assert((level>=LOG_MIN) && (level<=LOG_MAX));
     40                level = min(LOG_MAX, max(LOG_MIN, level));
    3941                printf(log_format, log_level[level + 1], obj, method, msg, "\n");
    4042        }
Note: See TracChangeset for help on using the changeset viewer.