source: cpp/common/log.cpp @ 1156

Last change on this file since 1156 was 1130, checked in by Maciej Komosinski, 4 years ago

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

  • Property svn:eol-style set to native
File size: 1.1 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[1130]2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[122]4
[375]5#include "log.h"
[109]6#include <common/nonstd_stdio.h>
[841]7#include "util-string.h"
[109]8#include "Convert.h"
[875]9#include <assert.h>
[1130]10#include <algorithm>
[109]11
[874]12const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " };
[109]13
[375]14void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va)
[109]15{
[375]16        string buf = ssprintf_va(msgf, va);
17        logMessage(obj, method, level, buf.c_str());
[109]18}
19
[375]20void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...)
[109]21{
22        va_list argptr;
[375]23        va_start(argptr, msgf);
24        logPrintf_va(obj, method, level, msgf, argptr);
[109]25        va_end(argptr);
26}
27
[375]28void log_printf(const char *msgf, ...)
[109]29{
30        va_list argptr;
[375]31        va_start(argptr, msgf);
32        logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr);
[109]33        va_end(argptr);
34}
[874]35
36const char* logLevelName(int level)
37{
[875]38        assert((level>=LOG_MIN) && (level<=LOG_MAX));
[1130]39        level = std::min(LOG_MAX, std::max(LOG_MIN, level));
[874]40        return LOG_LEVEL_ARRAY[level + 1];
41}
Note: See TracBrowser for help on using the repository browser.