source: cpp/common/log.cpp @ 1000

Last change on this file since 1000 was 875, checked in by Maciej Komosinski, 6 years ago

Better use of LOG_level constants

  • 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/
[874]2// Copyright (C) 1999-2019  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>
[109]10
[874]11const char* LOG_LEVEL_ARRAY[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " };
[109]12
[375]13void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va)
[109]14{
[375]15        string buf = ssprintf_va(msgf, va);
16        logMessage(obj, method, level, buf.c_str());
[109]17}
18
[375]19void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...)
[109]20{
21        va_list argptr;
[375]22        va_start(argptr, msgf);
23        logPrintf_va(obj, method, level, msgf, argptr);
[109]24        va_end(argptr);
25}
26
[375]27void log_printf(const char *msgf, ...)
[109]28{
29        va_list argptr;
[375]30        va_start(argptr, msgf);
31        logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr);
[109]32        va_end(argptr);
33}
[874]34
35const char* logLevelName(int level)
36{
[875]37        assert((level>=LOG_MIN) && (level<=LOG_MAX));
38        level = min(LOG_MAX, max(LOG_MIN, level));
[874]39        return LOG_LEVEL_ARRAY[level + 1];
40}
Note: See TracBrowser for help on using the repository browser.