Commit 8ad95e57 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: merge upstream loguru changes

parent d1fdd981
......@@ -175,6 +175,10 @@ Website: www.ilikebigbits.com
#define LOGURU_USE_FMTLIB 0
#endif
#ifndef LOGURU_USE_LOCALE
#define LOGURU_USE_LOCALE 0
#endif
#ifndef LOGURU_WITH_FILEABS
#define LOGURU_WITH_FILEABS 0
#endif
......@@ -195,6 +199,14 @@ Website: www.ilikebigbits.com
#endif
#endif
#ifdef LOGURU_USE_ANONYMOUS_NAMESPACE
#define LOGURU_ANONYMOUS_NAMESPACE_BEGIN namespace {
#define LOGURU_ANONYMOUS_NAMESPACE_END }
#else
#define LOGURU_ANONYMOUS_NAMESPACE_BEGIN
#define LOGURU_ANONYMOUS_NAMESPACE_END
#endif
// --------------------------------------------------------------------
// Utility macros
......@@ -250,7 +262,10 @@ Website: www.ilikebigbits.com
#define LOGURU_FREE(p) _xfree(p)
// END EDUKE32 MODIFICATION
#include <stdarg.h>
// --------------------------------------------------------------------
LOGURU_ANONYMOUS_NAMESPACE_BEGIN
namespace loguru
{
......@@ -637,6 +652,10 @@ namespace loguru
LOGURU_EXPORT
void log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5);
// Actual logging function.
LOGURU_EXPORT
void vlog(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, va_list) LOGURU_PRINTF_LIKE(4, 0);
// Log without any preamble or indentation.
LOGURU_EXPORT
void raw_log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5);
......@@ -647,9 +666,12 @@ namespace loguru
{
public:
LogScopeRAII() : _file(nullptr) {} // No logging
LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, va_list vlist) LOGURU_PRINTF_LIKE(5, 0);
LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(5, 6);
~LogScopeRAII();
void Init(LOGURU_FORMAT_STRING_TYPE format, va_list vlist) LOGURU_PRINTF_LIKE(2, 0);
#if defined(_MSC_VER) && _MSC_VER > 1800
// older MSVC default move ctors close the scope on move. See
// issue #43
......@@ -1022,6 +1044,8 @@ namespace loguru
*/
} // namespace loguru
LOGURU_ANONYMOUS_NAMESPACE_END
// --------------------------------------------------------------------
// Logging macros
......@@ -1193,6 +1217,8 @@ namespace loguru
#include <sstream> // Adds about 38 kLoC on clang.
#include <string>
LOGURU_ANONYMOUS_NAMESPACE_BEGIN
namespace loguru
{
// Like sprintf, but returns the formated text.
......@@ -1308,6 +1334,8 @@ namespace loguru
inline unsigned long long referenceable_value(unsigned long long t) { return t; }
} // namespace loguru
LOGURU_ANONYMOUS_NAMESPACE_END
// -----------------------------------------------
// Logging macros:
......
......@@ -82,23 +82,27 @@
// TODO: use defined(_POSIX_VERSION) for some of these things?
#ifndef LOGURU_USE_LOCALE
#define LOGURU_USE_LOCALE 0
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
#define LOGURU_PTHREADS 0
#define LOGURU_WINTHREADS 1
#ifndef LOGURU_STACKTRACES
#define LOGURU_STACKTRACES 0
#endif
#elif defined(__rtems__) || defined(__ANDROID__) || defined(__FreeBSD__) || !defined(__GLIBC__)
#define LOGURU_PTHREADS 1
#define LOGURU_WINTHREADS 0
#ifndef LOGURU_STACKTRACES
#define LOGURU_STACKTRACES 0
#endif
#else
#define LOGURU_PTHREADS 1
#define LOGURU_WINTHREADS 0
#ifndef LOGURU_STACKTRACES
#define LOGURU_STACKTRACES 1
#ifdef __GLIBC__
#ifndef LOGURU_STACKTRACES
#define LOGURU_STACKTRACES 1
#endif
#else
#ifndef LOGURU_STACKTRACES
#define LOGURU_STACKTRACES 0
#endif
#endif
#endif
......@@ -146,6 +150,7 @@
#define LOGURU_PTLS_NAMES 0
#endif
LOGURU_ANONYMOUS_NAMESPACE_BEGIN
namespace loguru
{
......@@ -497,8 +502,19 @@ namespace loguru
for (int arg_it = 1; arg_it < argc; ++arg_it) {
auto cmd = argv[arg_it];
auto arg_len = strlen(verbosity_flag);
bool is_alpha = std::isalpha(cmd[arg_len], std::locale(""));
if (strncmp(cmd, verbosity_flag, arg_len) == 0 && !is_alpha) {
bool last_is_alpha = false;
#if LOGURU_USE_LOCALE
try { // locale variant of isalpha will throw on error
last_is_alpha = std::isalpha(cmd[arg_len], std::locale(""));
}
catch (...) {
last_is_alpha = std::isalpha(cmd[arg_len]);
}
#else
last_is_alpha = std::isalpha(cmd[arg_len]);
#endif
if (strncmp(cmd, verbosity_flag, arg_len) == 0 && !last_is_alpha) {
out_argc -= 1;
auto value_str = cmd + arg_len;
if (value_str[0] == '\0') {
......@@ -1589,9 +1605,14 @@ namespace loguru
{
va_list vlist;
va_start(vlist, format);
vlog(verbosity, file, line, format, vlist);
va_end(vlist);
}
void vlog(Verbosity verbosity, const char* file, unsigned line, const char* format, va_list vlist)
{
auto buff = vtextprintf(format, vlist);
log_to_everywhere(1, verbosity, file, line, "", buff.c_str());
va_end(vlist);
}
void raw_log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)
......@@ -1618,31 +1639,19 @@ namespace loguru
s_needs_flushing = false;
}
LogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, ...)
: _verbosity(verbosity), _file(file), _line(line)
LogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, va_list vlist) :
_verbosity(verbosity), _file(file), _line(line)
{
if (verbosity <= current_verbosity_cutoff()) {
std::lock_guard<std::recursive_mutex> lock(s_mutex);
_indent_stderr = (verbosity <= g_stderr_verbosity);
_start_time_ns = now_ns();
va_list vlist;
va_start(vlist, format);
vsnprintf(_name, sizeof(_name), format, vlist);
log_to_everywhere(1, _verbosity, file, line, "{ ", _name);
va_end(vlist);
if (_indent_stderr) {
++s_stderr_indentation;
}
this->Init(format, vlist);
}
for (auto& p : s_callbacks) {
if (verbosity <= p.verbosity) {
++p.indentation;
}
}
} else {
_file = nullptr;
}
LogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) :
_verbosity(verbosity), _file(file), _line(line)
{
va_list vlist;
va_start(vlist, format);
this->Init(format, vlist);
va_end(vlist);
}
LogScopeRAII::~LogScopeRAII()
......@@ -1675,6 +1684,29 @@ namespace loguru
}
}
void LogScopeRAII::Init(const char* format, va_list vlist)
{
if (_verbosity <= current_verbosity_cutoff()) {
std::lock_guard<std::recursive_mutex> lock(s_mutex);
_indent_stderr = (_verbosity <= g_stderr_verbosity);
_start_time_ns = now_ns();
vsnprintf(_name, sizeof(_name), format, vlist);
log_to_everywhere(1, _verbosity, _file, _line, "{ ", _name);
if (_indent_stderr) {
++s_stderr_indentation;
}
for (auto& p : s_callbacks) {
if (_verbosity <= p.verbosity) {
++p.indentation;
}
}
} else {
_file = nullptr;
}
}
#if LOGURU_USE_FMTLIB
void vlog_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, const char* format, fmt::format_args args)
{
......@@ -2148,4 +2180,6 @@ namespace loguru
#pragma warning(pop)
#endif
LOGURU_ANONYMOUS_NAMESPACE_END
#endif // LOGURU_IMPLEMENTATION
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment