mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ccd675a286 | ||
![]() |
5372d58adc | ||
![]() |
751520f0cf | ||
![]() |
357a63d914 | ||
![]() |
a938045135 | ||
![]() |
32177aa77a | ||
![]() |
ce1df17262 | ||
![]() |
9f8413308a | ||
![]() |
f25f0e0e40 | ||
![]() |
a2890f2778 | ||
![]() |
de4644b44a | ||
![]() |
03db102375 | ||
![]() |
3d967dd716 | ||
![]() |
b53d207f44 | ||
![]() |
fde12195ee | ||
![]() |
4ca6991828 |
@@ -21,7 +21,7 @@ Very fast, header only, C++ logging library. [
|
* Windows (vc 2013+, cygwin)
|
||||||
* Mac OSX (clang 3.5+)
|
* Mac OSX (clang 3.5+)
|
||||||
* Android
|
* Android
|
||||||
|
|
||||||
|
@@ -358,7 +358,6 @@ inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_f
|
|||||||
// spin, yield or sleep. use the time passed since last message as a hint
|
// spin, yield or sleep. use the time passed since last message as a hint
|
||||||
inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time)
|
inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time)
|
||||||
{
|
{
|
||||||
using namespace std::this_thread;
|
|
||||||
using std::chrono::milliseconds;
|
using std::chrono::milliseconds;
|
||||||
using std::chrono::microseconds;
|
using std::chrono::microseconds;
|
||||||
|
|
||||||
@@ -374,10 +373,10 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_
|
|||||||
|
|
||||||
// sleep for 20 ms upto 200 ms
|
// sleep for 20 ms upto 200 ms
|
||||||
if (time_since_op <= milliseconds(200))
|
if (time_since_op <= milliseconds(200))
|
||||||
return sleep_for(milliseconds(20));
|
return details::os::sleep_for_millis(20);
|
||||||
|
|
||||||
// sleep for 500 ms
|
// sleep for 500 ms
|
||||||
return sleep_for(milliseconds(500));
|
return details::os::sleep_for_millis(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for the queue to be empty
|
// wait for the queue to be empty
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
if (!os::fopen_s(&_fd, fname, mode))
|
if (!os::fopen_s(&_fd, fname, mode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(open_interval));
|
details::os::sleep_for_millis(open_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
|
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
|
||||||
@@ -130,12 +130,11 @@ public:
|
|||||||
return std::make_tuple(fname, spdlog::filename_t());
|
return std::make_tuple(fname, spdlog::filename_t());
|
||||||
|
|
||||||
// treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile"
|
// treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile"
|
||||||
//auto folder_index = fname.find('\\', ext_index);
|
|
||||||
auto folder_index = fname.rfind(details::os::folder_sep);
|
auto folder_index = fname.rfind(details::os::folder_sep);
|
||||||
if (folder_index != fname.npos && folder_index >= ext_index - 1)
|
if (folder_index != fname.npos && folder_index >= ext_index - 1)
|
||||||
return std::make_tuple(fname, spdlog::filename_t());
|
return std::make_tuple(fname, spdlog::filename_t());
|
||||||
|
|
||||||
// finally - return a valid base and extnetion tuple
|
// finally - return a valid base and extension tuple
|
||||||
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
|
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
@@ -363,6 +363,17 @@ inline size_t thread_id()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This is avoid msvc issue in sleep_for that happens if the clock changes.
|
||||||
|
// See https://github.com/gabime/spdlog/issues/609
|
||||||
|
inline void sleep_for_millis(int milliseconds)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
Sleep(milliseconds);
|
||||||
|
#else
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||||
#define SPDLOG_FILENAME_T(s) L ## s
|
#define SPDLOG_FILENAME_T(s) L ## s
|
||||||
|
@@ -64,6 +64,7 @@ public:
|
|||||||
new_logger->set_error_handler(_err_handler);
|
new_logger->set_error_handler(_err_handler);
|
||||||
|
|
||||||
new_logger->set_level(_level);
|
new_logger->set_level(_level);
|
||||||
|
new_logger->flush_on(_flush_level);
|
||||||
|
|
||||||
|
|
||||||
//Add to registry
|
//Add to registry
|
||||||
@@ -85,6 +86,7 @@ public:
|
|||||||
new_logger->set_error_handler(_err_handler);
|
new_logger->set_error_handler(_err_handler);
|
||||||
|
|
||||||
new_logger->set_level(_level);
|
new_logger->set_level(_level);
|
||||||
|
new_logger->flush_on(_flush_level);
|
||||||
|
|
||||||
//Add to registry
|
//Add to registry
|
||||||
_loggers[logger_name] = new_logger;
|
_loggers[logger_name] = new_logger;
|
||||||
@@ -153,6 +155,14 @@ public:
|
|||||||
_level = log_level;
|
_level = log_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flush_on(level::level_enum log_level)
|
||||||
|
{
|
||||||
|
std::lock_guard<Mutex> lock(_mutex);
|
||||||
|
for (auto& l : _loggers)
|
||||||
|
l.second->flush_on(log_level);
|
||||||
|
_flush_level = log_level;
|
||||||
|
}
|
||||||
|
|
||||||
void set_error_handler(log_err_handler handler)
|
void set_error_handler(log_err_handler handler)
|
||||||
{
|
{
|
||||||
for (auto& l : _loggers)
|
for (auto& l : _loggers)
|
||||||
@@ -197,6 +207,7 @@ private:
|
|||||||
std::unordered_map <std::string, std::shared_ptr<logger>> _loggers;
|
std::unordered_map <std::string, std::shared_ptr<logger>> _loggers;
|
||||||
formatter_ptr _formatter;
|
formatter_ptr _formatter;
|
||||||
level::level_enum _level = level::info;
|
level::level_enum _level = level::info;
|
||||||
|
level::level_enum _flush_level = level::off;
|
||||||
log_err_handler _err_handler;
|
log_err_handler _err_handler;
|
||||||
bool _async_mode = false;
|
bool _async_mode = false;
|
||||||
size_t _async_q_size = 0;
|
size_t _async_q_size = 0;
|
||||||
|
@@ -236,6 +236,11 @@ inline void spdlog::set_level(level::level_enum log_level)
|
|||||||
return details::registry::instance().set_level(log_level);
|
return details::registry::instance().set_level(log_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void spdlog::flush_on(level::level_enum log_level)
|
||||||
|
{
|
||||||
|
return details::registry::instance().flush_on(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
inline void spdlog::set_error_handler(log_err_handler handler)
|
inline void spdlog::set_error_handler(log_err_handler handler)
|
||||||
{
|
{
|
||||||
return details::registry::instance().set_error_handler(handler);
|
return details::registry::instance().set_error_handler(handler);
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
|
||||||
#include "sink.h"
|
#include "sink.h"
|
||||||
|
#include "../details/os.h"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -43,7 +44,7 @@ public:
|
|||||||
int retry_count = 0;
|
int retry_count = 0;
|
||||||
while ((ret == -11/*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
|
while ((ret == -11/*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
details::os::sleep_for_millis(5);
|
||||||
ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
||||||
retry_count++;
|
retry_count++;
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,7 @@ private:
|
|||||||
GetConsoleScreenBufferInfo(out_handle_, &orig_buffer_info);
|
GetConsoleScreenBufferInfo(out_handle_, &orig_buffer_info);
|
||||||
WORD back_color = orig_buffer_info.wAttributes;
|
WORD back_color = orig_buffer_info.wAttributes;
|
||||||
// retrieve the current background color
|
// retrieve the current background color
|
||||||
back_color &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
back_color &= static_cast<WORD>(~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
|
||||||
// keep the background color unchanged
|
// keep the background color unchanged
|
||||||
SetConsoleTextAttribute(out_handle_, attribs | back_color);
|
SetConsoleTextAttribute(out_handle_, attribs | back_color);
|
||||||
return orig_buffer_info.wAttributes; //return orig attribs
|
return orig_buffer_info.wAttributes; //return orig attribs
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define SPDLOG_VERSION "0.16.2"
|
#define SPDLOG_VERSION "0.16.3"
|
||||||
|
|
||||||
#include "tweakme.h"
|
#include "tweakme.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -36,10 +36,15 @@ void set_pattern(const std::string& format_string);
|
|||||||
void set_formatter(formatter_ptr f);
|
void set_formatter(formatter_ptr f);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set global logging level for
|
// Set global logging level
|
||||||
//
|
//
|
||||||
void set_level(level::level_enum log_level);
|
void set_level(level::level_enum log_level);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set global flush level
|
||||||
|
//
|
||||||
|
void flush_on(level::level_enum log_level);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set global error handler
|
// Set global error handler
|
||||||
//
|
//
|
||||||
@@ -165,24 +170,23 @@ void drop_all();
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef SPDLOG_TRACE_ON
|
#ifdef SPDLOG_TRACE_ON
|
||||||
#define SPDLOG_STR_H(x) #x
|
# define SPDLOG_STR_H(x) #x
|
||||||
#define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
|
# define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
|
||||||
#ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
|
# define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
|
||||||
|
# else
|
||||||
|
# define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
|
# define SPDLOG_TRACE(logger, ...) (void)0
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define SPDLOG_TRACE(logger, ...)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPDLOG_DEBUG_ON
|
#ifdef SPDLOG_DEBUG_ON
|
||||||
#define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
|
# define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_DEBUG(logger, ...)
|
# define SPDLOG_DEBUG(logger, ...) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "details/spdlog_impl.h"
|
#include "details/spdlog_impl.h"
|
||||||
|
23
tests/catch.license
Normal file
23
tests/catch.license
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
Boost Software License - Version 1.0 - August 17th, 2003
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
Reference in New Issue
Block a user