Add the fmt library (#4065)
* Replaces AppendVPrintf with fmt::sprintf * fmt::ArgList now used as a type safe alternative to varargs. * Removed SIZE_T_FMT compatibility macros. fmt::sprintf is fully portable and supports %zu. * Adds FLOG functions to log with fmt's native formatting style.master
parent
68fc28857f
commit
757231cc6e
|
@ -59,3 +59,7 @@
|
|||
path = lib/zlib
|
||||
url = https://github.com/cuberite/zlib.git
|
||||
ignore = dirty
|
||||
[submodule "lib/fmt"]
|
||||
path = lib/fmt
|
||||
url = https://github.com/fmtlib/fmt.git
|
||||
ignore = dirty
|
||||
|
|
|
@ -224,6 +224,9 @@ endif()
|
|||
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/expat/CMakeLists.txt)
|
||||
message(FATAL_ERROR "expat is missing in folder lib/expat. Have you initialized and updated the submodules / downloaded the extra libraries?")
|
||||
endif()
|
||||
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/fmt/CMakeLists.txt)
|
||||
message(FATAL_ERROR "fmt is missing in folder lib/fmt. Have you initialized and updated the submodules / downloaded the extra libraries?")
|
||||
endif()
|
||||
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/lua/CMakeLists.txt)
|
||||
message(FATAL_ERROR "lua is missing in folder lib/lua. Have you initialized and updated the submodules / downloaded the extra libraries?")
|
||||
endif()
|
||||
|
@ -256,6 +259,8 @@ add_subdirectory(lib/SQLiteCpp/)
|
|||
add_subdirectory(lib/expat/)
|
||||
add_subdirectory(lib/luaexpat/)
|
||||
add_subdirectory(lib/libevent/ EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(lib/fmt)
|
||||
|
||||
|
||||
# Add proper include directories so that SQLiteCpp can find SQLite3:
|
||||
get_property(SQLITECPP_INCLUDES DIRECTORY "lib/SQLiteCpp/" PROPERTY INCLUDE_DIRECTORIES)
|
||||
|
@ -299,6 +304,7 @@ if (MSVC)
|
|||
event_core
|
||||
event_extra
|
||||
expat
|
||||
fmt
|
||||
jsoncpp_lib_static
|
||||
lua
|
||||
luaexpat
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -252,7 +252,7 @@ macro(set_exe_flags)
|
|||
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
|
||||
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE}")
|
||||
string(REPLACE "-w" "" CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_COVERAGE}")
|
||||
add_flags_cxx("-Wall -Wextra -Wno-unused-parameter")
|
||||
add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-missing-noreturn")
|
||||
|
||||
# we support non-IEEE 754 fpus so can make no guarentees about error
|
||||
add_flags_cxx("-ffast-math")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project (GrownBiomeGenVisualiser)
|
||||
|
||||
# Without this, the MSVC variable isn't defined for MSVC builds ( https://www.cmake.org/pipermail/cmake/2011-November/047130.html )
|
||||
|
@ -89,4 +90,6 @@ add_executable(GrownBiomeGenVisualiser
|
|||
${SHARED_OSS_HDR}
|
||||
)
|
||||
|
||||
target_link_libraries(GrownBiomeGenVisualiser fmt::fmt)
|
||||
|
||||
set_target_properties(GrownBiomeGenVisualiser PROPERTIES FOLDER Tools)
|
||||
|
|
|
@ -22,13 +22,6 @@
|
|||
#define ALIGN_8
|
||||
#define ALIGN_16
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
// MSVC has its own custom version of zu format
|
||||
#define SIZE_T_FMT "%Iu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
|
||||
#define SIZE_T_FMT_HEX "%Ix"
|
||||
|
||||
#define NORETURN __declspec(noreturn)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
@ -49,27 +42,6 @@
|
|||
// Some portability macros :)
|
||||
#define stricmp strcasecmp
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
#if defined(_WIN32)
|
||||
// We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing.
|
||||
// We need direct size formats:
|
||||
#if defined(_WIN64)
|
||||
#define SIZE_T_FMT "%I64u"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "I64u"
|
||||
#define SIZE_T_FMT_HEX "%I64x"
|
||||
#else
|
||||
#define SIZE_T_FMT "%u"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "u"
|
||||
#define SIZE_T_FMT_HEX "%x"
|
||||
#endif
|
||||
#else
|
||||
// We're compiling on Linux, so we can use libc's size_t printf format:
|
||||
#define SIZE_T_FMT "%zu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
|
||||
#define SIZE_T_FMT_HEX "%zx"
|
||||
#endif
|
||||
|
||||
#define NORETURN __attribute((__noreturn__))
|
||||
#else
|
||||
|
||||
|
@ -92,8 +64,6 @@
|
|||
#define ALIGN_16
|
||||
*/
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -213,6 +183,7 @@ typedef unsigned char Byte;
|
|||
|
||||
|
||||
// Common headers (without macros):
|
||||
#include "fmt/format.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define PROT_INT_BUFFER_SIZE (130 * 130)
|
||||
#include "Generating/ProtIntGen.h"
|
||||
|
||||
#include "fmt/printf.h"
|
||||
|
||||
|
||||
|
||||
|
@ -20,7 +21,6 @@ typedef int Color[3]; // Color is an array of 3 ints
|
|||
|
||||
|
||||
// Forward declarations, needed for GCC and Clang:
|
||||
void log(const char * a_Fmt, ...) FORMATSTRING(1, 2);
|
||||
void outputBitmapFile(
|
||||
const AString & a_FileName,
|
||||
unsigned a_ImageSizeX, unsigned a_ImageSizeY,
|
||||
|
@ -155,14 +155,12 @@ biomeColorMap[] =
|
|||
|
||||
|
||||
|
||||
void log(const char * a_Fmt, ...)
|
||||
template <typename ... Args>
|
||||
void log(const char * a_Fmt, const Args & ... a_Args)
|
||||
{
|
||||
AString buf;
|
||||
va_list args;
|
||||
va_start(args, a_Fmt);
|
||||
AppendVPrintf(buf, a_Fmt, args);
|
||||
va_end(args);
|
||||
std::cout << buf << std::endl << std::flush;
|
||||
fmt::printf(a_Fmt, a_Args...);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project (MCADefrag)
|
||||
|
||||
# Without this, the MSVC variable isn't defined for MSVC builds ( https://www.cmake.org/pipermail/cmake/2011-November/047130.html )
|
||||
|
@ -92,4 +93,4 @@ add_executable(MCADefrag
|
|||
${SHARED_OSS_HDR}
|
||||
)
|
||||
|
||||
target_link_libraries(MCADefrag zlib)
|
||||
target_link_libraries(MCADefrag zlib fmt::fmt)
|
||||
|
|
|
@ -22,13 +22,6 @@
|
|||
#define ALIGN_8
|
||||
#define ALIGN_16
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
// MSVC has its own custom version of zu format
|
||||
#define SIZE_T_FMT "%Iu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
|
||||
#define SIZE_T_FMT_HEX "%Ix"
|
||||
|
||||
#define NORETURN __declspec(noreturn)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
@ -44,12 +37,6 @@
|
|||
// Some portability macros :)
|
||||
#define stricmp strcasecmp
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
#define SIZE_T_FMT "%zu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
|
||||
#define SIZE_T_FMT_HEX "%zx"
|
||||
|
||||
#define NORETURN __attribute((__noreturn__))
|
||||
#else
|
||||
|
||||
|
@ -69,8 +56,6 @@
|
|||
#define ALIGN_16
|
||||
*/
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -190,6 +175,7 @@ typedef unsigned char Byte;
|
|||
|
||||
|
||||
// Common headers (without macros):
|
||||
#include "fmt/format.h"
|
||||
#include "StringUtils.h"
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
#include "OSSupport/Event.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "Globals.h"
|
||||
#include "MCADefrag.h"
|
||||
#include "Logger.h"
|
||||
#include "LoggerSimple.h"
|
||||
#include "LoggerListeners.h"
|
||||
#include "zlib/zlib.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project (NoiseSpeedTest)
|
||||
|
||||
include(../../SetFlags.cmake)
|
||||
|
@ -60,6 +61,8 @@ add_executable(NoiseSpeedTest
|
|||
${SHARED_HDR}
|
||||
)
|
||||
|
||||
target_link_libraries(NoiseSpeedTest fmt::fmt)
|
||||
|
||||
set_target_properties(
|
||||
NoiseSpeedTest
|
||||
PROPERTIES FOLDER Tools
|
||||
|
|
|
@ -22,13 +22,6 @@
|
|||
#define ALIGN_8
|
||||
#define ALIGN_16
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
// MSVC has its own custom version of zu format
|
||||
#define SIZE_T_FMT "%Iu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
|
||||
#define SIZE_T_FMT_HEX "%Ix"
|
||||
|
||||
#define NORETURN __declspec(noreturn)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
@ -44,12 +37,6 @@
|
|||
// Some portability macros :)
|
||||
#define stricmp strcasecmp
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
#define SIZE_T_FMT "%zu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
|
||||
#define SIZE_T_FMT_HEX "%zx"
|
||||
|
||||
#define NORETURN __attribute((__noreturn__))
|
||||
#else
|
||||
|
||||
|
@ -69,8 +56,6 @@
|
|||
#define ALIGN_16
|
||||
*/
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -191,6 +176,7 @@ typedef unsigned char Byte;
|
|||
|
||||
|
||||
// Common headers (without macros):
|
||||
#include "fmt/format.h"
|
||||
#include "StringUtils.h"
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
#include "OSSupport/Event.h"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project (ProtoProxy)
|
||||
|
||||
include(../../SetFlags.cmake)
|
||||
|
@ -100,5 +101,5 @@ add_executable(ProtoProxy
|
|||
${SHARED_OSS_HDR}
|
||||
)
|
||||
|
||||
target_link_libraries(ProtoProxy zlib mbedtls)
|
||||
target_link_libraries(ProtoProxy zlib mbedtls fmt::fmt)
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "mbedTLS++/CryptoKey.h"
|
||||
#include "../../src/Logger.h"
|
||||
|
||||
#include "fmt/printf.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h> // For _mkdir()
|
||||
#endif
|
||||
|
@ -282,15 +284,12 @@ void cConnection::Run(void)
|
|||
|
||||
|
||||
|
||||
void cConnection::Log(const char * a_Format, ...)
|
||||
void cConnection::Log(const char * a_Format, fmt::ArgList a_Args)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, a_Format);
|
||||
AString msg;
|
||||
AppendVPrintf(msg, a_Format, args);
|
||||
va_end(args);
|
||||
AString FullMsg;
|
||||
Printf(FullMsg, "[%5.3f] %s\n", GetRelativeTime(), msg.c_str());
|
||||
fmt::MemoryWriter FullMsg;
|
||||
fmt::printf(FullMsg, "[%5.3f] ", GetRelativeTime());
|
||||
fmt::printf(FullMsg, a_Format, a_Args);
|
||||
fmt::printf(FullMsg, "\n");
|
||||
|
||||
// Log to file:
|
||||
cCSLock Lock(m_CSLog);
|
||||
|
@ -307,16 +306,13 @@ void cConnection::Log(const char * a_Format, ...)
|
|||
|
||||
|
||||
|
||||
void cConnection::DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...)
|
||||
void cConnection::DataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::ArgList a_Args)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, a_Format);
|
||||
AString msg;
|
||||
AppendVPrintf(msg, a_Format, args);
|
||||
va_end(args);
|
||||
AString FullMsg;
|
||||
fmt::MemoryWriter FullMsg;
|
||||
fmt::printf(FullMsg, "[%5.3f] ", GetRelativeTime());
|
||||
fmt::printf(FullMsg, a_Format, a_Args);
|
||||
AString Hex;
|
||||
Printf(FullMsg, "[%5.3f] %s\n%s\n", GetRelativeTime(), msg.c_str(), CreateHexDump(Hex, a_Data, a_Size, 16).c_str());
|
||||
fmt::printf(FullMsg, "\n%s\n", CreateHexDump(Hex, a_Data, a_Size, 16));
|
||||
|
||||
// Log to file:
|
||||
cCSLock Lock(m_CSLog);
|
||||
|
|
|
@ -59,8 +59,12 @@ public:
|
|||
|
||||
void Run(void);
|
||||
|
||||
void Log(const char * a_Format, ...);
|
||||
void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, ...);
|
||||
void Log(const char * a_Format, fmt::ArgList);
|
||||
FMT_VARIADIC(void, Log, const char *)
|
||||
|
||||
void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::ArgList);
|
||||
FMT_VARIADIC(void, DataLog, const void *, size_t, const char *)
|
||||
|
||||
void LogFlush(void);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#define ALIGN_8
|
||||
#define ALIGN_16
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
|
||||
|
@ -37,8 +35,6 @@
|
|||
// Some portability macros :)
|
||||
#define stricmp strcasecmp
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
#else
|
||||
|
||||
#error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
|
||||
|
@ -57,8 +53,6 @@
|
|||
#define ALIGN_16
|
||||
*/
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -186,10 +180,11 @@ typedef unsigned char Byte;
|
|||
|
||||
|
||||
// Common headers (part 1, without macros):
|
||||
#include "fmt/format.h"
|
||||
#include "StringUtils.h"
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
|
||||
|
||||
#include "LoggerSimple.h"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 7a9c1ba190cb61b00f7ffac628ff30c9c0a9e076
|
|
@ -176,5 +176,5 @@ endif()
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Bindings ${SRCS} ${HDRS})
|
||||
target_link_libraries(Bindings lua sqlite tolualib mbedtls HTTPServer)
|
||||
target_link_libraries(Bindings fmt::fmt lua sqlite tolualib mbedtls HTTPServer)
|
||||
endif()
|
||||
|
|
|
@ -2004,7 +2004,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
|
|||
|
||||
|
||||
|
||||
int cLuaState::ApiParamError(const char * a_MsgFormat, ...)
|
||||
int cLuaState::ApiParamError(const char * a_MsgFormat, fmt::ArgList argp)
|
||||
{
|
||||
// Retrieve current function name
|
||||
lua_Debug entry;
|
||||
|
@ -2012,23 +2012,8 @@ int cLuaState::ApiParamError(const char * a_MsgFormat, ...)
|
|||
VERIFY(lua_getinfo(m_LuaState, "n", &entry));
|
||||
|
||||
// Compose the error message:
|
||||
va_list argp;
|
||||
va_start(argp, a_MsgFormat);
|
||||
AString msg;
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
|
||||
AppendVPrintf(msg, a_MsgFormat, argp);
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
va_end(argp);
|
||||
AString errorMsg = Printf("%s: %s", (entry.name != nullptr) ? entry.name : "<unknown function>", msg.c_str());
|
||||
AString msg = Printf(a_MsgFormat, argp);
|
||||
AString errorMsg = fmt::format("{0}: {1}", (entry.name != nullptr) ? entry.name : "<unknown function>", msg);
|
||||
|
||||
// Log everything into the console:
|
||||
LOGWARNING("%s", errorMsg.c_str());
|
||||
|
|
|
@ -823,7 +823,8 @@ public:
|
|||
/** Formats and prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
|
||||
To be used for bindings when they detect bad parameters.
|
||||
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
|
||||
int ApiParamError(const char * a_MsgFormat, ...);
|
||||
int ApiParamError(const char * a_MsgFormat, fmt::ArgList);
|
||||
FMT_VARIADIC(int, ApiParamError, const char *)
|
||||
|
||||
/** Returns the type of the item on the specified position in the stack */
|
||||
AString GetTypeText(int a_StackPos);
|
||||
|
|
|
@ -116,7 +116,7 @@ int cManualBindings::tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Er
|
|||
|
||||
|
||||
|
||||
int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, ...)
|
||||
int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, fmt::ArgList a_ArgList)
|
||||
{
|
||||
// Retrieve current function name
|
||||
lua_Debug entry;
|
||||
|
@ -128,11 +128,9 @@ int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, ...)
|
|||
ReplaceString(msg, "#funcname#", (entry.name != nullptr) ? entry.name : "?");
|
||||
|
||||
// Copied from luaL_error and modified
|
||||
va_list argp;
|
||||
va_start(argp, a_pFormat);
|
||||
luaL_where(L, 1);
|
||||
lua_pushvfstring(L, msg.c_str(), argp);
|
||||
va_end(argp);
|
||||
AString FmtMsg = Printf(msg.c_str(), a_ArgList);
|
||||
lua_pushlstring(L, FmtMsg.data(), FmtMsg.size());
|
||||
lua_concat(L, 2);
|
||||
return lua_error(L);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ public:
|
|||
// Helper functions:
|
||||
static cPluginLua * GetLuaPlugin(lua_State * L);
|
||||
static int tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Error * a_pToLuaError);
|
||||
static int lua_do_error(lua_State * L, const char * a_pFormat, ...);
|
||||
static int lua_do_error(lua_State * L, const char * a_pFormat, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(static int, lua_do_error, lua_State *, const char *)
|
||||
|
||||
|
||||
/** Binds the DoWith(ItemName) functions of regular classes. */
|
||||
|
|
|
@ -48,4 +48,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(BlockEntities ${SRCS} ${HDRS})
|
||||
target_link_libraries(BlockEntities fmt::fmt)
|
||||
endif()
|
||||
|
|
|
@ -104,4 +104,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Blocks ${SRCS} ${HDRS})
|
||||
target_link_libraries(Blocks fmt::fmt)
|
||||
endif()
|
||||
|
|
|
@ -55,7 +55,7 @@ void cBrewingRecipes::ReloadRecipes(void)
|
|||
AddRecipeFromLine(ParsingLine, LineNum);
|
||||
} // while (getline(ParsingLine))
|
||||
|
||||
LOG("Loaded " SIZE_T_FMT " brewing recipes", m_Recipes.size());
|
||||
LOG("Loaded %zu brewing recipes", m_Recipes.size());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ SET (HDRS
|
|||
LinearUpscale.h
|
||||
Logger.h
|
||||
LoggerListeners.h
|
||||
LoggerSimple.h
|
||||
Map.h
|
||||
MapManager.h
|
||||
Matrix4.h
|
||||
|
@ -359,7 +360,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|||
add_flags_lnk(-L/usr/ports/devel)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} luaexpat jsoncpp_lib_static mbedtls zlib sqlite lua SQLiteCpp event_core event_extra)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} luaexpat jsoncpp_lib_static mbedtls zlib sqlite lua SQLiteCpp event_core event_extra fmt::fmt)
|
||||
|
||||
# Create a folder for Bindings' documentation:
|
||||
FILE(MAKE_DIRECTORY "Bindings/docs")
|
||||
|
|
|
@ -699,7 +699,7 @@ void cClientHandle::HandlePing(void)
|
|||
AString Reply;
|
||||
const cServer & Server = *cRoot::Get()->GetServer();
|
||||
|
||||
Printf(Reply, "%s%s" SIZE_T_FMT "%s" SIZE_T_FMT,
|
||||
Printf(Reply, "%s%s%zu%s%zu",
|
||||
Server.GetDescription().c_str(),
|
||||
cChatColor::Delimiter,
|
||||
Server.GetNumPlayers(),
|
||||
|
|
|
@ -13,13 +13,9 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// cCommandOutputCallback:
|
||||
|
||||
void cCommandOutputCallback::Out(const char * a_Fmt, ...)
|
||||
void cCommandOutputCallback::Out(const char * a_Fmt, fmt::ArgList args)
|
||||
{
|
||||
AString Output;
|
||||
va_list args;
|
||||
va_start(args, a_Fmt);
|
||||
AppendVPrintf(Output, a_Fmt, args);
|
||||
va_end(args);
|
||||
AString Output = Printf(a_Fmt, args);
|
||||
Output.append("\n");
|
||||
Out(Output);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ public:
|
|||
virtual ~cCommandOutputCallback() {} // Force a virtual destructor in subclasses
|
||||
|
||||
/** Syntax sugar function, calls Out() with Printf()-ed parameters; appends a newline" */
|
||||
void Out(const char * a_Fmt, ...) FORMATSTRING(2, 3);
|
||||
void Out(const char * a_Fmt, fmt::ArgList);
|
||||
FMT_VARIADIC(void, Out, const char *)
|
||||
|
||||
/** Called when the command wants to output anything; may be called multiple times */
|
||||
virtual void Out(const AString & a_Text) = 0;
|
||||
|
|
|
@ -352,7 +352,7 @@ void cCraftingRecipes::LoadRecipes(void)
|
|||
}
|
||||
AddRecipeLine(LineNum, Recipe);
|
||||
} // for itr - Split[]
|
||||
LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
|
||||
LOG("Loaded %zu crafting recipes", m_Recipes.size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -380,7 +380,7 @@ void cCraftingRecipes::AddRecipeLine(int a_LineNum, const AString & a_RecipeLine
|
|||
AStringVector Sides = StringSplit(RecipeLine, "=");
|
||||
if (Sides.size() != 2)
|
||||
{
|
||||
LOGWARNING("crafting.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
|
||||
LOGWARNING("crafting.txt: line %d: A single '=' was expected, got %zu", a_LineNum, Sides.size() - 1);
|
||||
LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -62,5 +62,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Entities ${SRCS} ${HDRS})
|
||||
target_link_libraries(Entities WorldStorage)
|
||||
target_link_libraries(Entities fmt::fmt WorldStorage)
|
||||
endif()
|
||||
|
|
|
@ -106,7 +106,7 @@ void cFurnaceRecipe::ReloadRecipes(void)
|
|||
} // switch (ParsingLine[0])
|
||||
} // while (getline(ParsingLine))
|
||||
|
||||
LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
|
||||
LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,7 +125,7 @@ void cFurnaceRecipe::AddFuelFromLine(const AString & a_Line, unsigned int a_Line
|
|||
const AStringVector & Sides = StringSplit(Line, "=");
|
||||
if (Sides.size() != 2)
|
||||
{
|
||||
LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
|
||||
LOGWARNING("furnace.txt: line %d: A single '=' was expected, got %zu", a_LineNum, Sides.size() - 1);
|
||||
LOGINFO("Offending line: \"%s\"", a_Line.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ void cFurnaceRecipe::AddRecipeFromLine(const AString & a_Line, unsigned int a_Li
|
|||
const AStringVector & Sides = StringSplit(Line, "=");
|
||||
if (Sides.size() != 2)
|
||||
{
|
||||
LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
|
||||
LOGWARNING("furnace.txt: line %d: A single '=' was expected, got %zu", a_LineNum, Sides.size() - 1);
|
||||
LOGINFO("Offending line: \"%s\"", a_Line.c_str());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,5 +76,5 @@ endif()
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Generating ${SRCS} ${HDRS})
|
||||
target_link_libraries(Generating OSSupport Blocks Bindings)
|
||||
target_link_libraries(Generating fmt::fmt OSSupport Blocks Bindings)
|
||||
endif()
|
||||
|
|
|
@ -118,7 +118,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_Forc
|
|||
// Add to queue, issue a warning if too many:
|
||||
if (m_Queue.size() >= QUEUE_WARNING_LIMIT)
|
||||
{
|
||||
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
|
||||
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size());
|
||||
}
|
||||
m_Queue.push_back(cQueueItem{a_ChunkX, a_ChunkZ, a_ForceGenerate, a_Callback});
|
||||
}
|
||||
|
|
|
@ -294,14 +294,14 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe
|
|||
// DEBUG:
|
||||
void cPieceGeneratorBFSTree::DebugConnectorPool(const cPieceGeneratorBFSTree::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed)
|
||||
{
|
||||
printf(" Connector pool: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed);
|
||||
fmt::print(" Connector pool: {0} items\n", a_ConnectorPool.size() - a_NumProcessed);
|
||||
size_t idx = 0;
|
||||
|
||||
typedef cPieceGeneratorBFSTree::cFreeConnectors::difference_type difType;
|
||||
|
||||
for (auto itr = a_ConnectorPool.cbegin() + static_cast<difType>(a_NumProcessed), end = a_ConnectorPool.cend(); itr != end; ++itr, ++idx)
|
||||
{
|
||||
printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n",
|
||||
fmt::print(" {0}: {{{1}, {2}, {3}}}, type {4}, direction {5}, depth {6}\n",
|
||||
idx,
|
||||
itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z,
|
||||
itr->m_Connector.m_Type,
|
||||
|
|
|
@ -138,7 +138,7 @@ bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel,
|
|||
auto structures = StringSplitAndTrim(a_Prefabs, "|");
|
||||
for (const auto & s: structures)
|
||||
{
|
||||
auto fileName = Printf("Prefabs%cPieceStructures%c%s.cubeset", cFile::PathSeparator, cFile::PathSeparator, s.c_str());
|
||||
auto fileName = Printf("Prefabs%cPieceStructures%c%s.cubeset", cFile::PathSeparator(), cFile::PathSeparator(), s.c_str());
|
||||
if (!cFile::IsFile(fileName))
|
||||
{
|
||||
fileName.append(".gz");
|
||||
|
|
101
src/Globals.h
101
src/Globals.h
|
@ -38,13 +38,6 @@
|
|||
|
||||
#define OBSOLETE __declspec(deprecated)
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex)
|
||||
|
||||
// MSVC has its own custom version of zu format
|
||||
#define SIZE_T_FMT "%Iu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
|
||||
#define SIZE_T_FMT_HEX "%Ix"
|
||||
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#if (_MSC_VER < 1900) // noexcept support was added in VS 2015
|
||||
#define NOEXCEPT throw()
|
||||
|
@ -87,27 +80,6 @@
|
|||
|
||||
#define OBSOLETE __attribute__((deprecated))
|
||||
|
||||
#define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
|
||||
|
||||
#if defined(_WIN32)
|
||||
// We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing.
|
||||
// We need direct size formats:
|
||||
#if defined(_WIN64)
|
||||
#define SIZE_T_FMT "%I64u"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "I64u"
|
||||
#define SIZE_T_FMT_HEX "%I64x"
|
||||
#else
|
||||
#define SIZE_T_FMT "%u"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "u"
|
||||
#define SIZE_T_FMT_HEX "%x"
|
||||
#endif
|
||||
#else
|
||||
// We're compiling on Linux, so we can use libc's size_t printf format:
|
||||
#define SIZE_T_FMT "%zu"
|
||||
#define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
|
||||
#define SIZE_T_FMT_HEX "%zx"
|
||||
#endif
|
||||
|
||||
#define NORETURN __attribute((__noreturn__))
|
||||
#define NOEXCEPT noexcept
|
||||
#define CAN_THROW noexcept(false)
|
||||
|
@ -263,6 +235,7 @@ template class SizeChecker<UInt8, 1>;
|
|||
|
||||
|
||||
// Common headers (part 1, without macros):
|
||||
#include "fmt/format.h"
|
||||
#include "StringUtils.h"
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
#include "OSSupport/Event.h"
|
||||
|
@ -271,73 +244,39 @@ template class SizeChecker<UInt8, 1>;
|
|||
|
||||
#ifndef TEST_GLOBALS
|
||||
|
||||
// These functions are defined in Logger.cpp, but are declared here to avoid including all of logger.h
|
||||
extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGWARNING(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGERROR (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
// In debug builds, translate LOGD to LOG, otherwise leave it out altogether:
|
||||
#ifdef _DEBUG
|
||||
#define LOGD LOG
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif // _DEBUG
|
||||
|
||||
#define LOGWARN LOGWARNING
|
||||
#include "LoggerSimple.h"
|
||||
|
||||
#else
|
||||
#include "fmt/printf.h"
|
||||
|
||||
// Logging functions
|
||||
void inline LOGERROR(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
void inline LOGERROR(const char * a_Format, ...)
|
||||
template <typename ... Args>
|
||||
void LOG(const char * a_Format, const Args & ... a_Args)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
vprintf(a_Format, argList);
|
||||
fmt::printf(a_Format, a_Args...);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
void inline LOGWARNING(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
#define LOGERROR LOG
|
||||
#define LOGWARNING LOG
|
||||
#define LOGD LOG
|
||||
#define LOGINFO LOG
|
||||
#define LOGWARN LOG
|
||||
|
||||
void inline LOGWARNING(const char * a_Format, ...)
|
||||
template <typename ... Args>
|
||||
void FLOG(const char * a_Format, const Args & ... a_Args)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
vprintf(a_Format, argList);
|
||||
fmt::print(a_Format, a_Args...);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
void inline LOGD(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
void inline LOGD(const char * a_Format, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
vprintf(a_Format, argList);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
void inline LOG(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
void inline LOG(const char * a_Format, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
vprintf(a_Format, argList);
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
#define LOGINFO LOG
|
||||
#define LOGWARN LOGWARNING
|
||||
#define FLOGERROR FLOG
|
||||
#define FLOGWARNING FLOG
|
||||
#define FLOGD FLOG
|
||||
#define FLOGINFO FLOG
|
||||
#define FLOGWARN FLOG
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,4 +34,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(HTTPServer ${SRCS} ${HDRS})
|
||||
target_link_libraries(HTTPServer fmt::fmt)
|
||||
endif()
|
||||
|
|
|
@ -74,7 +74,7 @@ void cHTTPServerConnection::Send(const void * a_Data, size_t a_Size)
|
|||
{
|
||||
ASSERT(m_CurrentRequest != nullptr);
|
||||
// We're sending in Chunked transfer encoding
|
||||
SendData(Printf(SIZE_T_FMT_HEX "\r\n", a_Size));
|
||||
SendData(fmt::format("{0:x}\r\n", a_Size));
|
||||
SendData(a_Data, a_Size);
|
||||
SendData("\r\n");
|
||||
}
|
||||
|
|
|
@ -628,7 +628,7 @@ cItem * cItems::Get(int a_Idx)
|
|||
{
|
||||
if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
|
||||
{
|
||||
LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently " SIZE_T_FMT " items. Returning a nil.", a_Idx, size());
|
||||
LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size());
|
||||
return nullptr;
|
||||
}
|
||||
return &at(static_cast<size_t>(a_Idx));
|
||||
|
@ -642,7 +642,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item)
|
|||
{
|
||||
if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
|
||||
{
|
||||
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
|
||||
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
|
||||
return;
|
||||
}
|
||||
at(static_cast<size_t>(a_Idx)) = a_Item;
|
||||
|
@ -656,7 +656,7 @@ void cItems::Delete(int a_Idx)
|
|||
{
|
||||
if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
|
||||
{
|
||||
LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Ignoring.", a_Idx, size());
|
||||
LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size());
|
||||
return;
|
||||
}
|
||||
erase(begin() + a_Idx);
|
||||
|
@ -670,7 +670,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama
|
|||
{
|
||||
if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
|
||||
{
|
||||
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size());
|
||||
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
|
||||
return;
|
||||
}
|
||||
at(static_cast<size_t>(a_Idx)) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);
|
||||
|
|
|
@ -60,4 +60,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Items ${SRCS} ${HDRS})
|
||||
target_link_libraries(Items fmt::fmt)
|
||||
endif()
|
||||
|
|
|
@ -63,11 +63,18 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
|
|||
|
||||
|
||||
|
||||
void cLogger::Log(const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList)
|
||||
void cLogger::LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
|
||||
{
|
||||
AString Message;
|
||||
AppendVPrintf(Message, a_Format, a_ArgList);
|
||||
LogSimple(Message, a_LogLevel);
|
||||
LogSimple(Printf(a_Format, a_ArgList), a_LogLevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLogger::LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
|
||||
{
|
||||
LogSimple(fmt::format(a_Format, a_ArgList), a_LogLevel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,48 +117,72 @@ void cLogger::DetachListener(cListener * a_Listener)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global functions
|
||||
|
||||
void LOG(const char * a_Format, ...)
|
||||
void FLOG(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
cLogger::GetInstance().Log(a_Format, cLogger::llRegular, argList);
|
||||
va_end(argList);
|
||||
cLogger::GetInstance().LogFormat(a_Format, cLogger::llRegular, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGINFO(const char * a_Format, ...)
|
||||
void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
cLogger::GetInstance().Log( a_Format, cLogger::llInfo, argList);
|
||||
va_end(argList);
|
||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llInfo, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGWARNING(const char * a_Format, ...)
|
||||
void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
cLogger::GetInstance().Log( a_Format, cLogger::llWarning, argList);
|
||||
va_end(argList);
|
||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llWarning, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGERROR(const char * a_Format, ...)
|
||||
void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, a_Format);
|
||||
cLogger::GetInstance().Log( a_Format, cLogger::llError, argList);
|
||||
va_end(argList);
|
||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llError, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOG(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
cLogger::GetInstance().LogPrintf(a_Format, cLogger::llRegular, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llInfo, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llWarning, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
|
||||
{
|
||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llError, a_ArgList);
|
||||
}
|
||||
|
||||
|
||||
|
|
17
src/Logger.h
17
src/Logger.h
|
@ -58,7 +58,13 @@ public:
|
|||
cAttachment(cListener * a_listener) : m_listener(a_listener) {}
|
||||
};
|
||||
|
||||
void Log (const char * a_Format, eLogLevel a_LogLevel, va_list a_ArgList) FORMATSTRING(2, 0);
|
||||
/** Log a message formatted with a printf style formatting string. */
|
||||
void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LogPrintf, const char *, eLogLevel)
|
||||
|
||||
/** Log a message formatted with a python style formatting string. */
|
||||
void LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LogFormat, const char *, eLogLevel)
|
||||
|
||||
/** Logs the simple text message at the specified log level. */
|
||||
void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
|
||||
|
@ -79,12 +85,3 @@ private:
|
|||
|
||||
|
||||
|
||||
|
||||
// These declarations are duplicated in globals.h
|
||||
extern void LOG (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGINFO (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGWARNING(const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
extern void LOGERROR (const char * a_Format, ...) FORMATSTRING(1, 2);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
// Logging free functions defined in Logger.cpp
|
||||
#pragma once
|
||||
|
||||
// python style format specified logging
|
||||
|
||||
extern void FLOG(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, FLOG, const char *)
|
||||
|
||||
extern void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, FLOGINFO, const char *)
|
||||
|
||||
extern void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, FLOGWARNING, const char *)
|
||||
|
||||
extern void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, FLOGERROR, const char *)
|
||||
|
||||
// printf style format specified logging (DEPRECATED)
|
||||
|
||||
extern void LOG(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LOG, const char *)
|
||||
|
||||
extern void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LOGINFO, const char *)
|
||||
|
||||
extern void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LOGWARNING, const char *)
|
||||
|
||||
extern void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
|
||||
FMT_VARIADIC(void, LOGERROR, const char *)
|
||||
|
||||
|
||||
// Macro variants
|
||||
|
||||
// In debug builds, translate LOGD to LOG, otherwise leave it out altogether:
|
||||
#ifdef _DEBUG
|
||||
#define LOGD LOG
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#endif // _DEBUG
|
||||
|
||||
#define LOGWARN LOGWARNING
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define FLOGD FLOG
|
||||
#else
|
||||
#define FLOGD(...)
|
||||
#endif // _DEBUG
|
||||
|
||||
#define FLOGWARN FLOGWARNING
|
|
@ -83,4 +83,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Mobs ${SRCS} ${HDRS})
|
||||
target_link_libraries(Mobs fmt::fmt)
|
||||
endif()
|
||||
|
|
|
@ -15,5 +15,5 @@ SET (HDRS
|
|||
|
||||
if(NOT MSVC)
|
||||
add_library(Noise ${SRCS} ${HDRS})
|
||||
target_link_libraries(Noise OSSupport)
|
||||
target_link_libraries(Noise fmt::fmt OSSupport)
|
||||
endif()
|
||||
|
|
|
@ -119,7 +119,7 @@ void Debug3DNoise(const NOISE_DATATYPE * a_Noise, size_t a_SizeX, size_t a_SizeY
|
|||
|
||||
// Save in XY cuts:
|
||||
cFile f1;
|
||||
if (f1.Open(Printf("%s_XY (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite))
|
||||
if (f1.Open(Printf("%s_XY (%zu).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite))
|
||||
{
|
||||
for (size_t z = 0; z < a_SizeZ; z++)
|
||||
{
|
||||
|