parent
8e2dfce84b
commit
57952505e5
@ -279,6 +279,9 @@ macro(set_exe_flags)
|
|||||||
# flags introduced in 3.2
|
# flags introduced in 3.2
|
||||||
add_flags_cxx("-Wno-documentation")
|
add_flags_cxx("-Wno-documentation")
|
||||||
endif()
|
endif()
|
||||||
|
if ("${CLANG_VERSION}" VERSION_GREATER 3.4)
|
||||||
|
add_flags_cxx("-Wno-error=disabled-macro-expansion")
|
||||||
|
endif()
|
||||||
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
|
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
check_cxx_compiler_flag(-Wno-reserved-id-macro HAS_NO_RESERVED_ID_MACRO)
|
check_cxx_compiler_flag(-Wno-reserved-id-macro HAS_NO_RESERVED_ID_MACRO)
|
||||||
@ -292,9 +295,6 @@ macro(set_exe_flags)
|
|||||||
add_flags_cxx("-Wno-documentation-unknown-command")
|
add_flags_cxx("-Wno-documentation-unknown-command")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
|
|
||||||
add_flags_cxx("-Wno-error=disabled-macro-expansion")
|
|
||||||
endif()
|
|
||||||
if ("${CLANG_VERSION}" VERSION_GREATER 3.7)
|
if ("${CLANG_VERSION}" VERSION_GREATER 3.7)
|
||||||
check_cxx_compiler_flag(-Wno-double-promotion HAS_NO_DOUBLE_PROMOTION)
|
check_cxx_compiler_flag(-Wno-double-promotion HAS_NO_DOUBLE_PROMOTION)
|
||||||
if (HAS_NO_DOUBLE_PROMOTION)
|
if (HAS_NO_DOUBLE_PROMOTION)
|
||||||
|
@ -191,7 +191,7 @@ typedef unsigned char Byte;
|
|||||||
|
|
||||||
|
|
||||||
// Common headers (without macros):
|
// Common headers (without macros):
|
||||||
#include "fmt/format.h"
|
#include "fmt.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ typedef unsigned char Byte;
|
|||||||
|
|
||||||
|
|
||||||
// Common headers (without macros):
|
// Common headers (without macros):
|
||||||
#include "fmt/format.h"
|
#include "fmt.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "OSSupport/CriticalSection.h"
|
#include "OSSupport/CriticalSection.h"
|
||||||
#include "OSSupport/Event.h"
|
#include "OSSupport/Event.h"
|
||||||
|
@ -184,7 +184,7 @@ typedef unsigned char Byte;
|
|||||||
|
|
||||||
|
|
||||||
// Common headers (without macros):
|
// Common headers (without macros):
|
||||||
#include "fmt/format.h"
|
#include "fmt.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "OSSupport/CriticalSection.h"
|
#include "OSSupport/CriticalSection.h"
|
||||||
#include "OSSupport/Event.h"
|
#include "OSSupport/Event.h"
|
||||||
|
@ -284,16 +284,13 @@ void cConnection::Run(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cConnection::Log(const char * a_Format, fmt::ArgList a_Args)
|
void cConnection::vLog(const char * a_Format, fmt::printf_args a_Args)
|
||||||
{
|
{
|
||||||
fmt::MemoryWriter FullMsg;
|
|
||||||
fmt::printf(FullMsg, "[%5.3f] ", GetRelativeTime());
|
|
||||||
fmt::printf(FullMsg, a_Format, a_Args);
|
|
||||||
fmt::printf(FullMsg, "\n");
|
|
||||||
|
|
||||||
// Log to file:
|
// Log to file:
|
||||||
cCSLock Lock(m_CSLog);
|
cCSLock Lock(m_CSLog);
|
||||||
fputs(FullMsg.c_str(), m_LogFile);
|
fmt::fprintf(m_LogFile, "[%5.3f] ", GetRelativeTime());
|
||||||
|
fmt::vfprintf(m_LogFile, a_Format, a_Args);
|
||||||
|
fmt::fprintf(m_LogFile, "\n");
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
fflush(m_LogFile);
|
fflush(m_LogFile);
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
@ -306,17 +303,16 @@ void cConnection::Log(const char * a_Format, fmt::ArgList a_Args)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cConnection::DataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::ArgList a_Args)
|
void cConnection::vDataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::printf_args a_Args)
|
||||||
{
|
{
|
||||||
fmt::MemoryWriter FullMsg;
|
|
||||||
fmt::printf(FullMsg, "[%5.3f] ", GetRelativeTime());
|
|
||||||
fmt::printf(FullMsg, a_Format, a_Args);
|
|
||||||
AString Hex;
|
AString Hex;
|
||||||
fmt::printf(FullMsg, "\n%s\n", CreateHexDump(Hex, a_Data, a_Size, 16));
|
CreateHexDump(Hex, a_Data, a_Size, 16);
|
||||||
|
|
||||||
// Log to file:
|
// Log to file:
|
||||||
cCSLock Lock(m_CSLog);
|
cCSLock Lock(m_CSLog);
|
||||||
fputs(FullMsg.c_str(), m_LogFile);
|
fmt::fprintf(m_LogFile, "[%5.3f] ", GetRelativeTime());
|
||||||
|
fmt::vfprintf(m_LogFile, a_Format, a_Args);
|
||||||
|
fmt::fprintf(m_LogFile, "\n%s\n", Hex);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Log to screen:
|
// Log to screen:
|
||||||
|
@ -59,11 +59,21 @@ public:
|
|||||||
|
|
||||||
void Run(void);
|
void Run(void);
|
||||||
|
|
||||||
void Log(const char * a_Format, fmt::ArgList);
|
void vLog(const char * a_Format, fmt::printf_args);
|
||||||
FMT_VARIADIC(void, Log, const char *)
|
|
||||||
|
|
||||||
void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::ArgList);
|
template <typename... Args>
|
||||||
FMT_VARIADIC(void, DataLog, const void *, size_t, const char *)
|
void Log(const char * a_Format, const Args & ... a_Args)
|
||||||
|
{
|
||||||
|
vLog(a_Format, fmt::make_printf_args(a_Args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
void vDataLog(const void * a_Data, size_t a_Size, const char * a_Format, fmt::printf_args);
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void DataLog(const void * a_Data, size_t a_Size, const char * a_Format, const Args & ... a_Args)
|
||||||
|
{
|
||||||
|
vDataLog(a_Data, a_Size, a_Format, fmt::make_printf_args(a_Args...));
|
||||||
|
}
|
||||||
|
|
||||||
void LogFlush(void);
|
void LogFlush(void);
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ typedef unsigned char Byte;
|
|||||||
|
|
||||||
|
|
||||||
// Common headers (part 1, without macros):
|
// Common headers (part 1, without macros):
|
||||||
#include "fmt/format.h"
|
#include "fmt.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "OSSupport/CriticalSection.h"
|
#include "OSSupport/CriticalSection.h"
|
||||||
|
|
||||||
|
2
lib/fmt
2
lib/fmt
@ -1 +1 @@
|
|||||||
Subproject commit f78c3e41be6e01aad47fc47163c1ad2caff101c0
|
Subproject commit 9bdd1596cef1b57b9556f8bef32dc4a32322ef3e
|
@ -2107,7 +2107,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cLuaState::ApiParamError(fmt::StringRef a_Msg)
|
int cLuaState::ApiParamError(fmt::string_view a_Msg)
|
||||||
{
|
{
|
||||||
// Retrieve current function name
|
// Retrieve current function name
|
||||||
lua_Debug entry;
|
lua_Debug entry;
|
||||||
|
@ -838,7 +838,7 @@ public:
|
|||||||
/** Prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
|
/** 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.
|
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(...)". */
|
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
|
||||||
int ApiParamError(fmt::StringRef a_Msg);
|
int ApiParamError(fmt::string_view a_Msg);
|
||||||
|
|
||||||
/** Formats and prints the message using printf-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
|
/** Formats and prints the message using printf-style format specifiers, but 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.
|
To be used for bindings when they detect bad parameters.
|
||||||
|
@ -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, fmt::ArgList a_ArgList)
|
int cManualBindings::vlua_do_error(lua_State * L, const char * a_pFormat, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
// Retrieve current function name
|
// Retrieve current function name
|
||||||
lua_Debug entry;
|
lua_Debug entry;
|
||||||
@ -129,7 +129,7 @@ int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, fmt::Ar
|
|||||||
|
|
||||||
// Copied from luaL_error and modified
|
// Copied from luaL_error and modified
|
||||||
luaL_where(L, 1);
|
luaL_where(L, 1);
|
||||||
AString FmtMsg = Printf(msg.c_str(), a_ArgList);
|
AString FmtMsg = vPrintf(msg.c_str(), a_ArgList);
|
||||||
lua_pushlstring(L, FmtMsg.data(), FmtMsg.size());
|
lua_pushlstring(L, FmtMsg.data(), FmtMsg.size());
|
||||||
lua_concat(L, 2);
|
lua_concat(L, 2);
|
||||||
return lua_error(L);
|
return lua_error(L);
|
||||||
|
@ -51,8 +51,12 @@ public:
|
|||||||
// Helper functions:
|
// Helper functions:
|
||||||
static cPluginLua * GetLuaPlugin(lua_State * L);
|
static cPluginLua * GetLuaPlugin(lua_State * L);
|
||||||
static int tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Error * a_pToLuaError);
|
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, fmt::ArgList a_ArgList);
|
static int vlua_do_error(lua_State * L, const char * a_pFormat, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(static int, lua_do_error, lua_State *, const char *)
|
template <typename... Args>
|
||||||
|
static int lua_do_error(lua_State * L, const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
return vlua_do_error(L, a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Binds the DoWith(ItemName) functions of regular classes. */
|
/** Binds the DoWith(ItemName) functions of regular classes. */
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// cCommandOutputCallback:
|
// cCommandOutputCallback:
|
||||||
|
|
||||||
void cCommandOutputCallback::Out(const char * a_Fmt, fmt::ArgList args)
|
void cCommandOutputCallback::vOut(const char * a_Fmt, fmt::printf_args args)
|
||||||
{
|
{
|
||||||
AString Output = Printf(a_Fmt, args);
|
AString Output = ::vPrintf(a_Fmt, args);
|
||||||
Output.append("\n");
|
Output.append("\n");
|
||||||
Out(Output);
|
Out(Output);
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,14 @@ class cCommandOutputCallback
|
|||||||
public:
|
public:
|
||||||
virtual ~cCommandOutputCallback() {} // Force a virtual destructor in subclasses
|
virtual ~cCommandOutputCallback() {} // Force a virtual destructor in subclasses
|
||||||
|
|
||||||
|
void vOut(const char * a_Fmt, fmt::printf_args);
|
||||||
|
|
||||||
/** Syntax sugar function, calls Out() with Printf()-ed parameters; appends a newline" */
|
/** Syntax sugar function, calls Out() with Printf()-ed parameters; appends a newline" */
|
||||||
void Out(const char * a_Fmt, fmt::ArgList);
|
template <typename... Args>
|
||||||
FMT_VARIADIC(void, Out, const char *)
|
void Out(const char * a_Fmt, const Args & ... a_Args)
|
||||||
|
{
|
||||||
|
vOut(a_Fmt, fmt::make_printf_args(a_Args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when the command wants to output anything; may be called multiple times */
|
/** Called when the command wants to output anything; may be called multiple times */
|
||||||
virtual void Out(const AString & a_Text) = 0;
|
virtual void Out(const AString & a_Text) = 0;
|
||||||
|
@ -235,7 +235,7 @@ template class SizeChecker<UInt8, 1>;
|
|||||||
|
|
||||||
|
|
||||||
// Common headers (part 1, without macros):
|
// Common headers (part 1, without macros):
|
||||||
#include "fmt/format.h"
|
#include "fmt.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "OSSupport/CriticalSection.h"
|
#include "OSSupport/CriticalSection.h"
|
||||||
#include "OSSupport/Event.h"
|
#include "OSSupport/Event.h"
|
||||||
|
@ -46,9 +46,9 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
|
|||||||
|
|
||||||
AString Line;
|
AString Line;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Printf(Line, "[%04llx|%02d:%02d:%02d] %s\n", static_cast<UInt64>(std::hash<std::thread::id>()(std::this_thread::get_id())), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
|
Printf(Line, "[%04llx|%02d:%02d:%02d] %s\n", static_cast<UInt64>(std::hash<std::thread::id>()(std::this_thread::get_id())), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message);
|
||||||
#else
|
#else
|
||||||
Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
|
Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -63,18 +63,18 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cLogger::LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
|
void cLogger::vLogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
LogSimple(Printf(a_Format, a_ArgList), a_LogLevel);
|
LogSimple(vPrintf(a_Format, a_ArgList), a_LogLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cLogger::LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
|
void cLogger::vLogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList)
|
||||||
{
|
{
|
||||||
LogSimple(fmt::format(a_Format, a_ArgList), a_LogLevel);
|
LogSimple(fmt::vformat(a_Format, a_ArgList), a_LogLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -117,72 +117,72 @@ void cLogger::DetachListener(cListener * a_Listener)
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Global functions
|
// Global functions
|
||||||
|
|
||||||
void FLOG(const char * a_Format, fmt::ArgList a_ArgList)
|
void vFLOG(const char * a_Format, fmt::format_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogFormat(a_Format, cLogger::llRegular, a_ArgList);
|
cLogger::GetInstance().vLogFormat(a_Format, cLogger::llRegular, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
|
void vFLOGINFO(const char * a_Format, fmt::format_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llInfo, a_ArgList);
|
cLogger::GetInstance().vLogFormat( a_Format, cLogger::llInfo, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
|
void vFLOGWARNING(const char * a_Format, fmt::format_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llWarning, a_ArgList);
|
cLogger::GetInstance().vLogFormat( a_Format, cLogger::llWarning, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
|
void vFLOGERROR(const char * a_Format, fmt::format_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogFormat( a_Format, cLogger::llError, a_ArgList);
|
cLogger::GetInstance().vLogFormat(a_Format, cLogger::llError, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LOG(const char * a_Format, fmt::ArgList a_ArgList)
|
void vLOG(const char * a_Format, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogPrintf(a_Format, cLogger::llRegular, a_ArgList);
|
cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llRegular, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
|
void vLOGINFO(const char * a_Format, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llInfo, a_ArgList);
|
cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llInfo, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
|
void vLOGWARNING(const char * a_Format, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llWarning, a_ArgList);
|
cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llWarning, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
|
void vLOGERROR(const char * a_Format, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
cLogger::GetInstance().LogPrintf( a_Format, cLogger::llError, a_ArgList);
|
cLogger::GetInstance().vLogPrintf( a_Format, cLogger::llError, a_ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
16
src/Logger.h
16
src/Logger.h
@ -59,12 +59,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Log a message formatted with a printf style formatting string. */
|
/** Log a message formatted with a printf style formatting string. */
|
||||||
void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
|
void vLogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LogPrintf, const char *, eLogLevel)
|
template <typename... Args>
|
||||||
|
void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLogPrintf(a_Format, a_LogLevel, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Log a message formatted with a python style formatting string. */
|
/** Log a message formatted with a python style formatting string. */
|
||||||
void LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
|
void vLogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LogFormat, const char *, eLogLevel)
|
template <typename... Args>
|
||||||
|
void LogFormat(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLogFormat(a_Format, a_LogLevel, fmt::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Logs the simple text message at the specified log level. */
|
/** Logs the simple text message at the specified log level. */
|
||||||
void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
|
void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
|
||||||
|
@ -4,31 +4,63 @@
|
|||||||
|
|
||||||
// python style format specified logging
|
// python style format specified logging
|
||||||
|
|
||||||
extern void FLOG(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vFLOG(const char * a_Format, fmt::format_args a_ArgList);
|
||||||
FMT_VARIADIC(void, FLOG, const char *)
|
template <typename... Args>
|
||||||
|
void FLOG(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vFLOG(a_Format, fmt::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vFLOGINFO(const char * a_Format, fmt::format_args a_ArgList);
|
||||||
FMT_VARIADIC(void, FLOGINFO, const char *)
|
template <typename... Args>
|
||||||
|
void FLOGINFO(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vFLOGINFO(a_Format, fmt::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vFLOGWARNING(const char * a_Format, fmt::format_args a_ArgList);
|
||||||
FMT_VARIADIC(void, FLOGWARNING, const char *)
|
template <typename... Args>
|
||||||
|
void FLOGWARNING(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vFLOGWARNING(a_Format, fmt::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vFLOGERROR(const char * a_Format, fmt::format_args a_ArgList);
|
||||||
FMT_VARIADIC(void, FLOGERROR, const char *)
|
template <typename... Args>
|
||||||
|
void FLOGERROR(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vFLOGERROR(a_Format, fmt::make_format_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
// printf style format specified logging (DEPRECATED)
|
// printf style format specified logging (DEPRECATED)
|
||||||
|
|
||||||
extern void LOG(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vLOG(const char * a_Format, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LOG, const char *)
|
template <typename... Args>
|
||||||
|
void LOG(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLOG(a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vLOGINFO(const char * a_Format, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LOGINFO, const char *)
|
template <typename... Args>
|
||||||
|
void LOGINFO(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLOGINFO(a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vLOGWARNING(const char * a_Format, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LOGWARNING, const char *)
|
template <typename... Args>
|
||||||
|
void LOGWARNING(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLOGWARNING(a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
extern void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
|
extern void vLOGERROR(const char * a_Format, fmt::printf_args a_ArgList);
|
||||||
FMT_VARIADIC(void, LOGERROR, const char *)
|
template <typename... Args>
|
||||||
|
void LOGERROR(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
vLOGERROR(a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Macro variants
|
// Macro variants
|
||||||
|
@ -692,10 +692,11 @@ AString cFile::GetExecutableExt(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cFile::Printf(const char * a_Fmt, fmt::ArgList a_ArgList)
|
int cFile::vPrintf(const char * a_Fmt, fmt::printf_args a_ArgList)
|
||||||
{
|
{
|
||||||
AString buf = ::Printf(a_Fmt, a_ArgList);
|
fmt::memory_buffer Buffer;
|
||||||
return Write(buf.c_str(), buf.length());
|
fmt::printf(Buffer, fmt::to_string_view(a_Fmt), a_ArgList);
|
||||||
|
return Write(Buffer.data(), Buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,8 +163,12 @@ public:
|
|||||||
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */
|
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */
|
||||||
static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp
|
static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp
|
||||||
|
|
||||||
int Printf(const char * a_Fmt, fmt::ArgList);
|
int vPrintf(const char * a_Fmt, fmt::printf_args);
|
||||||
FMT_VARIADIC(int, Printf, const char *)
|
template <typename... Args>
|
||||||
|
int Printf(const char * a_Fmt, const Args & ... a_Args)
|
||||||
|
{
|
||||||
|
return vPrintf(a_Fmt, fmt::make_printf_args(a_Args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Flushes all the bufferef output into the file (only when writing) */
|
/** Flushes all the bufferef output into the file (only when writing) */
|
||||||
void Flush(void);
|
void Flush(void);
|
||||||
|
@ -52,10 +52,12 @@ static unsigned char HexToDec(char a_HexChar)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AString & Printf(AString & str, const char * format, fmt::ArgList args)
|
AString & vPrintf(AString & str, const char * format, fmt::printf_args args)
|
||||||
{
|
{
|
||||||
ASSERT(format != nullptr);
|
ASSERT(format != nullptr);
|
||||||
str = fmt::sprintf(format, args);
|
fmt::memory_buffer Buffer;
|
||||||
|
fmt::printf(Buffer, fmt::to_string_view(format), args);
|
||||||
|
str.assign(Buffer.data(), Buffer.size());
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +65,23 @@ AString & Printf(AString & str, const char * format, fmt::ArgList args)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AString Printf(const char * format, fmt::ArgList args)
|
AString vPrintf(const char * format, fmt::printf_args args)
|
||||||
{
|
{
|
||||||
ASSERT(format != nullptr);
|
ASSERT(format != nullptr);
|
||||||
return fmt::sprintf(format, args);
|
return fmt::vsprintf(format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AString & vAppendPrintf(AString & a_String, const char * format, fmt::printf_args args)
|
||||||
|
{
|
||||||
|
ASSERT(format != nullptr);
|
||||||
|
fmt::memory_buffer Buffer;
|
||||||
|
fmt::printf(Buffer, fmt::to_string_view(format), args);
|
||||||
|
a_String.append(Buffer.data(), Buffer.size());
|
||||||
|
return a_String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -630,18 +645,18 @@ format binary data this way:
|
|||||||
*/
|
*/
|
||||||
AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine)
|
AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine)
|
||||||
{
|
{
|
||||||
fmt::MemoryWriter Output;
|
fmt::memory_buffer Output;
|
||||||
/* If formatting the data from the comment above:
|
/* If formatting the data from the comment above:
|
||||||
Hex holds: "31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 "
|
Hex holds: "31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 "
|
||||||
Chars holds: "1234567890abcdef" */
|
Chars holds: "1234567890abcdef" */
|
||||||
fmt::MemoryWriter Hex, Chars;
|
fmt::memory_buffer Hex, Chars;
|
||||||
|
|
||||||
if (a_Size > 0)
|
if (a_Size > 0)
|
||||||
{
|
{
|
||||||
// Same as std::ceil(static_cast<float>(a_Size) / a_BytesPerLine);
|
// Same as std::ceil(static_cast<float>(a_Size) / a_BytesPerLine);
|
||||||
const size_t NumLines = a_Size / a_BytesPerLine + (a_Size % a_BytesPerLine != 0);
|
const size_t NumLines = a_Size / a_BytesPerLine + (a_Size % a_BytesPerLine != 0);
|
||||||
const size_t CharsPerLine = 14 + 4 * a_BytesPerLine;
|
const size_t CharsPerLine = 14 + 4 * a_BytesPerLine;
|
||||||
Output.buffer().reserve(NumLines * CharsPerLine);
|
Output.reserve(NumLines * CharsPerLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
|
for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
|
||||||
@ -650,12 +665,20 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz
|
|||||||
for (size_t j = 0; j < k; j++)
|
for (size_t j = 0; j < k; j++)
|
||||||
{
|
{
|
||||||
Byte c = (static_cast<const Byte *>(a_Data))[i + j];
|
Byte c = (static_cast<const Byte *>(a_Data))[i + j];
|
||||||
Hex << HEX(c >> 4) << HEX(c & 0xf) << ' ';
|
Hex.push_back(HEX(c >> 4));
|
||||||
Chars << ((c >= ' ') ? static_cast<char>(c) : '.');
|
Hex.push_back(HEX(c & 0xf));
|
||||||
|
Hex.push_back(' ');
|
||||||
|
Chars.push_back((c >= ' ') ? static_cast<char>(c) : '.');
|
||||||
} // for j
|
} // for j
|
||||||
|
|
||||||
// Write Hex with a dynamic fixed width
|
// Write Hex with a dynamic fixed width
|
||||||
Output.write("{0:08x}: {1:{2}} {3}\n", i, Hex.c_str(), a_BytesPerLine * 3, Chars.c_str());
|
auto HexStr = fmt::string_view(Hex.data(), Hex.size());
|
||||||
|
auto CharsStr = fmt::string_view(Chars.data(), Chars.size());
|
||||||
|
fmt::format_to(
|
||||||
|
Output, "{0:08x}: {1:{2}} {3}\n",
|
||||||
|
i, HexStr, a_BytesPerLine * 3, CharsStr
|
||||||
|
);
|
||||||
|
|
||||||
Hex.clear();
|
Hex.clear();
|
||||||
Chars.clear();
|
Chars.clear();
|
||||||
} // for i
|
} // for i
|
||||||
|
@ -23,21 +23,29 @@ typedef std::map<AString, AString> AStringMap;
|
|||||||
|
|
||||||
/** Output the formatted text into the string.
|
/** Output the formatted text into the string.
|
||||||
Returns a_Dst. */
|
Returns a_Dst. */
|
||||||
extern AString & Printf(AString & a_Dst, const char * format, fmt::ArgList args);
|
extern AString & vPrintf(AString & a_Dst, const char * format, fmt::printf_args args);
|
||||||
FMT_VARIADIC(AString &, Printf, AString &, const char *)
|
template <typename... Args>
|
||||||
|
AString & Printf(AString & a_Dst, const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
return vPrintf(a_Dst, a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Output the formatted text into string
|
/** Output the formatted text into string
|
||||||
Returns the formatted string by value. */
|
Returns the formatted string by value. */
|
||||||
extern AString Printf(const char * format, fmt::ArgList args);
|
extern AString vPrintf(const char * format, fmt::printf_args args);
|
||||||
FMT_VARIADIC(AString, Printf, const char *)
|
template <typename... Args>
|
||||||
|
AString Printf(const char * a_Format, const Args & ... args)
|
||||||
|
{
|
||||||
|
return vPrintf(a_Format, fmt::make_printf_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
/** Add the formated string to the existing data in the string.
|
/** Add the formated string to the existing data in the string.
|
||||||
Returns a_Dst. */
|
Returns a_Dst. */
|
||||||
|
extern AString & vAppendPrintf(AString & a_Dst, const char * a_Format, fmt::printf_args args);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
extern AString & AppendPrintf(AString & a_Dst, const char * format, const Args & ... args)
|
extern AString & AppendPrintf(AString & a_Dst, const char * a_Format, const Args & ... a_Args)
|
||||||
{
|
{
|
||||||
a_Dst += Printf(format, args...);
|
return vAppendPrintf(a_Dst, a_Format, fmt::make_printf_args(a_Args...));
|
||||||
return a_Dst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Split the string at any of the listed delimiters.
|
/** Split the string at any of the listed delimiters.
|
||||||
|
@ -384,22 +384,6 @@ public:
|
|||||||
z = -z;
|
z = -z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tolua_end
|
|
||||||
|
|
||||||
/** Allows formatting a Vector<T> using the same format specifiers as for T
|
|
||||||
e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */
|
|
||||||
template <typename ArgFormatter>
|
|
||||||
friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec)
|
|
||||||
{
|
|
||||||
std::array<T, 3> Data{{a_Vec.x, a_Vec.y, a_Vec.z}};
|
|
||||||
|
|
||||||
a_Formatter.writer() << '{';
|
|
||||||
fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", "));
|
|
||||||
a_Formatter.writer() << '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
// tolua_begin
|
|
||||||
|
|
||||||
/** The max difference between two coords for which the coords are assumed equal. */
|
/** The max difference between two coords for which the coords are assumed equal. */
|
||||||
static const double EPS;
|
static const double EPS;
|
||||||
|
|
||||||
@ -411,6 +395,51 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace fmt
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename What>
|
||||||
|
class formatter<Vector3<What>>:
|
||||||
|
public fmt::formatter<What>
|
||||||
|
{
|
||||||
|
using Super = fmt::formatter<What>;
|
||||||
|
|
||||||
|
template <typename FormatContext, size_t Len>
|
||||||
|
void Write(FormatContext & a_Ctx, const char (& a_Str)[Len])
|
||||||
|
{
|
||||||
|
auto Itr = std::copy_n(&a_Str[0], Len - 1, a_Ctx.out());
|
||||||
|
a_Ctx.advance_to(Itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
void Write(FormatContext & a_Ctx, const What & a_Arg)
|
||||||
|
{
|
||||||
|
auto Itr = Super::format(a_Arg, a_Ctx);
|
||||||
|
a_Ctx.advance_to(Itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const Vector3<What> & a_Vec, FormatContext & a_Ctx)
|
||||||
|
-> typename FormatContext::iterator
|
||||||
|
{
|
||||||
|
Write(a_Ctx, "{");
|
||||||
|
Write(a_Ctx, a_Vec.x);
|
||||||
|
Write(a_Ctx, ", ");
|
||||||
|
Write(a_Ctx, a_Vec.y);
|
||||||
|
Write(a_Ctx, ", ");
|
||||||
|
Write(a_Ctx, a_Vec.z);
|
||||||
|
Write(a_Ctx, "}");
|
||||||
|
return a_Ctx.out();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <> inline Vector3<int> Vector3<int>::Floor(void) const
|
template <> inline Vector3<int> Vector3<int>::Floor(void) const
|
||||||
{
|
{
|
||||||
|
18
src/fmt.h
Normal file
18
src/fmt.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
|
#pragma clang diagnostic ignored "-Wunknown-warning-option"
|
||||||
|
#pragma clang diagnostic ignored "-Wsigned-enum-bitfield"
|
||||||
|
#pragma clang diagnostic ignored "-Wundefined-func-template"
|
||||||
|
#pragma clang diagnostic ignored "-Wc++2a-compat"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <fmt/printf.h>
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
@ -235,7 +235,7 @@ static void UniversalMain(std::unique_ptr<cSettingsRepositoryInterface> a_Overri
|
|||||||
cRoot Root;
|
cRoot Root;
|
||||||
Root.Start(std::move(a_OverridesRepo));
|
Root.Start(std::move(a_OverridesRepo));
|
||||||
}
|
}
|
||||||
catch (const fmt::FormatError & exc)
|
catch (const fmt::format_error & exc)
|
||||||
{
|
{
|
||||||
cRoot::m_TerminateEventRaised = true;
|
cRoot::m_TerminateEventRaised = true;
|
||||||
FLOGERROR("Formatting exception: {0}", exc.what());
|
FLOGERROR("Formatting exception: {0}", exc.what());
|
||||||
|
Loading…
Reference in New Issue
Block a user