mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-16 00:45:48 +08:00
Merge branch 'master' of https://github.com/gabime/spdlog.git
This commit is contained in:
commit
e9b8286714
@ -31,7 +31,7 @@ namespace details
|
|||||||
class async_log_helper;
|
class async_log_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
class async_logger :public logger
|
class async_logger SPDLOG_FINAL :public logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class It>
|
template<class It>
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
#define SPDLOG_CONSTEXPR constexpr
|
#define SPDLOG_CONSTEXPR constexpr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// See tweakme.h
|
||||||
|
#if !defined(SPDLOG_FINAL)
|
||||||
|
#define SPDLOG_FINAL
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define SPDLOG_DEPRECATED __attribute__((deprecated))
|
#define SPDLOG_DEPRECATED __attribute__((deprecated))
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
|
@ -99,7 +99,7 @@ static const days_array& full_days()
|
|||||||
static const days_array arr{ { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } };
|
static const days_array arr{ { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } };
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
class A_formatter:public flag_formatter
|
class A_formatter SPDLOG_FINAL :public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -128,7 +128,7 @@ static const months_array& full_months()
|
|||||||
static const months_array arr{ { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } };
|
static const months_array arr{ { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } };
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
class B_formatter:public flag_formatter
|
class B_formatter SPDLOG_FINAL :public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -153,7 +153,7 @@ static fmt::MemoryWriter& pad_n_join(fmt::MemoryWriter& w, int v1, int v2, int v
|
|||||||
|
|
||||||
|
|
||||||
//Date and time representation (Thu Aug 23 15:35:46 2014)
|
//Date and time representation (Thu Aug 23 15:35:46 2014)
|
||||||
class c_formatter:public flag_formatter
|
class c_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -164,7 +164,7 @@ class c_formatter:public flag_formatter
|
|||||||
|
|
||||||
|
|
||||||
// year - 2 digit
|
// year - 2 digit
|
||||||
class C_formatter:public flag_formatter
|
class C_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -175,7 +175,7 @@ class C_formatter:public flag_formatter
|
|||||||
|
|
||||||
|
|
||||||
// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
|
// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
|
||||||
class D_formatter:public flag_formatter
|
class D_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -185,7 +185,7 @@ class D_formatter:public flag_formatter
|
|||||||
|
|
||||||
|
|
||||||
// year - 4 digit
|
// year - 4 digit
|
||||||
class Y_formatter:public flag_formatter
|
class Y_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -194,7 +194,7 @@ class Y_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// month 1-12
|
// month 1-12
|
||||||
class m_formatter:public flag_formatter
|
class m_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -203,7 +203,7 @@ class m_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// day of month 1-31
|
// day of month 1-31
|
||||||
class d_formatter:public flag_formatter
|
class d_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -212,7 +212,7 @@ class d_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// hours in 24 format 0-23
|
// hours in 24 format 0-23
|
||||||
class H_formatter:public flag_formatter
|
class H_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -221,7 +221,7 @@ class H_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// hours in 12 format 1-12
|
// hours in 12 format 1-12
|
||||||
class I_formatter:public flag_formatter
|
class I_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -230,7 +230,7 @@ class I_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// minutes 0-59
|
// minutes 0-59
|
||||||
class M_formatter:public flag_formatter
|
class M_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -239,7 +239,7 @@ class M_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// seconds 0-59
|
// seconds 0-59
|
||||||
class S_formatter:public flag_formatter
|
class S_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -248,7 +248,7 @@ class S_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// milliseconds
|
// milliseconds
|
||||||
class e_formatter:public flag_formatter
|
class e_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -259,7 +259,7 @@ class e_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// microseconds
|
// microseconds
|
||||||
class f_formatter:public flag_formatter
|
class f_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -270,7 +270,7 @@ class f_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// nanoseconds
|
// nanoseconds
|
||||||
class F_formatter:public flag_formatter
|
class F_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -281,7 +281,7 @@ class F_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// AM/PM
|
// AM/PM
|
||||||
class p_formatter:public flag_formatter
|
class p_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -291,7 +291,7 @@ class p_formatter:public flag_formatter
|
|||||||
|
|
||||||
|
|
||||||
// 12 hour clock 02:55:02 pm
|
// 12 hour clock 02:55:02 pm
|
||||||
class r_formatter:public flag_formatter
|
class r_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -300,7 +300,7 @@ class r_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 24-hour HH:MM time, equivalent to %H:%M
|
// 24-hour HH:MM time, equivalent to %H:%M
|
||||||
class R_formatter:public flag_formatter
|
class R_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -309,7 +309,7 @@ class R_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
|
// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
|
||||||
class T_formatter:public flag_formatter
|
class T_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
@ -319,7 +319,7 @@ class T_formatter:public flag_formatter
|
|||||||
|
|
||||||
|
|
||||||
// ISO 8601 offset from UTC in timezone (+-HH:MM)
|
// ISO 8601 offset from UTC in timezone (+-HH:MM)
|
||||||
class z_formatter:public flag_formatter
|
class z_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
|
const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
|
||||||
@ -376,7 +376,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// Thread id
|
// Thread id
|
||||||
class t_formatter:public flag_formatter
|
class t_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -385,7 +385,7 @@ class t_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Current pid
|
// Current pid
|
||||||
class pid_formatter:public flag_formatter
|
class pid_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -394,7 +394,7 @@ class pid_formatter:public flag_formatter
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class v_formatter:public flag_formatter
|
class v_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm&) override
|
void format(details::log_msg& msg, const std::tm&) override
|
||||||
{
|
{
|
||||||
@ -402,7 +402,7 @@ class v_formatter:public flag_formatter
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ch_formatter:public flag_formatter
|
class ch_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ch_formatter(char ch): _ch(ch)
|
explicit ch_formatter(char ch): _ch(ch)
|
||||||
@ -417,7 +417,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
//aggregate user chars to display as is
|
//aggregate user chars to display as is
|
||||||
class aggregate_formatter:public flag_formatter
|
class aggregate_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
aggregate_formatter()
|
aggregate_formatter()
|
||||||
@ -436,7 +436,7 @@ private:
|
|||||||
|
|
||||||
// Full info formatter
|
// Full info formatter
|
||||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
||||||
class full_formatter:public flag_formatter
|
class full_formatter SPDLOG_FINAL:public flag_formatter
|
||||||
{
|
{
|
||||||
void format(details::log_msg& msg, const std::tm& tm_time) override
|
void format(details::log_msg& msg, const std::tm& tm_time) override
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ public:
|
|||||||
virtual void format(details::log_msg& msg) = 0;
|
virtual void format(details::log_msg& msg) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class pattern_formatter : public formatter
|
class pattern_formatter SPDLOG_FINAL : public formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -12,6 +12,12 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#if !defined(SPDLOG_ANDROID_RETRIES)
|
||||||
|
#define SPDLOG_ANDROID_RETRIES 2
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace spdlog
|
namespace spdlog
|
||||||
{
|
{
|
||||||
@ -25,15 +31,23 @@ namespace sinks
|
|||||||
class android_sink : public sink
|
class android_sink : public sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit android_sink(const std::string& tag = "spdlog"): _tag(tag) {}
|
explicit android_sink(const std::string& tag = "spdlog", bool use_raw_msg = false): _tag(tag), _use_raw_msg(use_raw_msg){}
|
||||||
|
|
||||||
void log(const details::log_msg& msg) override
|
void log(const details::log_msg& msg) override
|
||||||
{
|
{
|
||||||
const android_LogPriority priority = convert_to_android(msg.level);
|
const android_LogPriority priority = convert_to_android(msg.level);
|
||||||
|
const char *msg_output = (_use_raw_msg ? msg.raw.c_str() : msg.formatted.c_str());
|
||||||
|
|
||||||
// See system/core/liblog/logger_write.c for explanation of return value
|
// See system/core/liblog/logger_write.c for explanation of return value
|
||||||
const int ret = __android_log_write(
|
int ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
||||||
priority, _tag.c_str(), msg.formatted.c_str()
|
int retry_count = 0;
|
||||||
);
|
while ((ret == -11/*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||||
|
ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
||||||
|
retry_count++;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
throw spdlog_ex("__android_log_write() failed", ret);
|
throw spdlog_ex("__android_log_write() failed", ret);
|
||||||
@ -67,6 +81,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string _tag;
|
std::string _tag;
|
||||||
|
bool _use_raw_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace sinks
|
|||||||
* the output with an ANSI escape sequence color code depending on the severity
|
* the output with an ANSI escape sequence color code depending on the severity
|
||||||
* of the message.
|
* of the message.
|
||||||
*/
|
*/
|
||||||
class ansicolor_sink : public sink
|
class ansicolor_sink SPDLOG_FINAL : public sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ansicolor_sink(sink_ptr wrapped_sink);
|
ansicolor_sink(sink_ptr wrapped_sink);
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
base_sink(const base_sink&) = delete;
|
base_sink(const base_sink&) = delete;
|
||||||
base_sink& operator=(const base_sink&) = delete;
|
base_sink& operator=(const base_sink&) = delete;
|
||||||
|
|
||||||
void log(const details::log_msg& msg) override
|
void log(const details::log_msg& msg) SPDLOG_FINAL override
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(_mutex);
|
std::lock_guard<Mutex> lock(_mutex);
|
||||||
_sink_it(msg);
|
_sink_it(msg);
|
||||||
|
@ -26,7 +26,7 @@ namespace sinks
|
|||||||
* Trivial file sink with single file as target
|
* Trivial file sink with single file as target
|
||||||
*/
|
*/
|
||||||
template<class Mutex>
|
template<class Mutex>
|
||||||
class simple_file_sink : public base_sink < Mutex >
|
class simple_file_sink SPDLOG_FINAL : public base_sink < Mutex >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false)
|
explicit simple_file_sink(const filename_t &filename, bool truncate = false):_force_flush(false)
|
||||||
@ -61,7 +61,7 @@ typedef simple_file_sink<details::null_mutex> simple_file_sink_st;
|
|||||||
* Rotating file sink based on size
|
* Rotating file sink based on size
|
||||||
*/
|
*/
|
||||||
template<class Mutex>
|
template<class Mutex>
|
||||||
class rotating_file_sink : public base_sink < Mutex >
|
class rotating_file_sink SPDLOG_FINAL : public base_sink < Mutex >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rotating_file_sink(const filename_t &base_filename,
|
rotating_file_sink(const filename_t &base_filename,
|
||||||
@ -177,7 +177,7 @@ struct dateonly_daily_file_name_calculator
|
|||||||
* Rotating file sink based on date. rotates at midnight
|
* Rotating file sink based on date. rotates at midnight
|
||||||
*/
|
*/
|
||||||
template<class Mutex, class FileNameCalc = default_daily_file_name_calculator>
|
template<class Mutex, class FileNameCalc = default_daily_file_name_calculator>
|
||||||
class daily_file_sink :public base_sink < Mutex >
|
class daily_file_sink SPDLOG_FINAL :public base_sink < Mutex >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//create daily file sink which rotates on given time
|
//create daily file sink which rotates on given time
|
||||||
|
@ -18,7 +18,7 @@ namespace sinks
|
|||||||
{
|
{
|
||||||
|
|
||||||
template <class Mutex>
|
template <class Mutex>
|
||||||
class stdout_sink: public base_sink<Mutex>
|
class stdout_sink SPDLOG_FINAL : public base_sink<Mutex>
|
||||||
{
|
{
|
||||||
using MyType = stdout_sink<Mutex>;
|
using MyType = stdout_sink<Mutex>;
|
||||||
public:
|
public:
|
||||||
@ -47,7 +47,7 @@ typedef stdout_sink<std::mutex> stdout_sink_mt;
|
|||||||
|
|
||||||
|
|
||||||
template <class Mutex>
|
template <class Mutex>
|
||||||
class stderr_sink: public base_sink<Mutex>
|
class stderr_sink SPDLOG_FINAL : public base_sink<Mutex>
|
||||||
{
|
{
|
||||||
using MyType = stderr_sink<Mutex>;
|
using MyType = stderr_sink<Mutex>;
|
||||||
public:
|
public:
|
||||||
|
@ -106,3 +106,11 @@
|
|||||||
//
|
//
|
||||||
// #define SPDLOG_PREVENT_CHILD_FD
|
// #define SPDLOG_PREVENT_CHILD_FD
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Uncomment to mark some types as final, allowing more optimizations in release
|
||||||
|
// mode with recent compilers. See GCC's documentation for -Wsuggest-final-types
|
||||||
|
// for instance.
|
||||||
|
//
|
||||||
|
// #define SPDLOG_FINAL final
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user