source: cpp/common/log.cpp @ 874

Last change on this file since 874 was 874, checked in by Maciej Komosinski, 3 months ago

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

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