mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-15 10:39:53 +08:00
update clang format again
This commit is contained in:
parent
968048ced6
commit
6dffd7c6e8
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
# BasedOnStyle: Google
|
BasedOnStyle: Google
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
Standard: c++17
|
Standard: c++17
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
@ -43,8 +43,7 @@ int count_lines(const char *filename) {
|
|||||||
auto *infile = fopen(filename, "r");
|
auto *infile = fopen(filename, "r");
|
||||||
int ch;
|
int ch;
|
||||||
while (EOF != (ch = getc(infile))) {
|
while (EOF != (ch = getc(infile))) {
|
||||||
if ('\n' == ch)
|
if ('\n' == ch) counter++;
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
|
||||||
@ -67,7 +66,6 @@ void verify_file(const char *filename, int expected_count) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
int howmany = 1000000;
|
int howmany = 1000000;
|
||||||
int queue_size = std::min(howmany + 2, 8192);
|
int queue_size = std::min(howmany + 2, 8192);
|
||||||
int threads = 10;
|
int threads = 10;
|
||||||
@ -80,10 +78,8 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1) howmany = atoi(argv[1]);
|
||||||
howmany = atoi(argv[1]);
|
if (argc > 2) threads = atoi(argv[2]);
|
||||||
if (argc > 2)
|
|
||||||
threads = atoi(argv[2]);
|
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
queue_size = atoi(argv[3]);
|
queue_size = atoi(argv[3]);
|
||||||
if (queue_size > 500000) {
|
if (queue_size > 500000) {
|
||||||
@ -92,8 +88,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 4)
|
if (argc > 4) iters = atoi(argv[4]);
|
||||||
iters = atoi(argv[4]);
|
|
||||||
|
|
||||||
auto slot_size = sizeof(spdlog::details::async_msg);
|
auto slot_size = sizeof(spdlog::details::async_msg);
|
||||||
spdlog::info("-------------------------------------------------");
|
spdlog::info("-------------------------------------------------");
|
||||||
|
@ -91,7 +91,6 @@ int main(int argc, char *argv[]) {
|
|||||||
int iters = 250000;
|
int iters = 250000;
|
||||||
size_t threads = 4;
|
size_t threads = 4;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
iters = std::stoi(argv[1]);
|
iters = std::stoi(argv[1]);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ void bench_formatters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
spdlog::set_pattern("[%^%l%$] %v");
|
spdlog::set_pattern("[%^%l%$] %v");
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
spdlog::error("Usage: {} <pattern> (or \"all\" to bench all)", argv[0]);
|
spdlog::error("Usage: {} <pattern> (or \"all\" to bench all)", argv[0]);
|
||||||
|
@ -311,8 +311,9 @@ void android_example() {
|
|||||||
#include "spdlog/pattern_formatter.h"
|
#include "spdlog/pattern_formatter.h"
|
||||||
class my_formatter_flag : public spdlog::custom_flag_formatter {
|
class my_formatter_flag : public spdlog::custom_flag_formatter {
|
||||||
public:
|
public:
|
||||||
void
|
void format(const spdlog::details::log_msg &,
|
||||||
format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override {
|
const std::tm &,
|
||||||
|
spdlog::memory_buf_t &dest) override {
|
||||||
std::string some_txt = "custom-flag";
|
std::string some_txt = "custom-flag";
|
||||||
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,9 @@ inline void init_thread_pool(size_t q_size,
|
|||||||
details::registry::instance().set_tp(std::move(tp));
|
details::registry::instance().set_tp(std::move(tp));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void init_thread_pool(size_t q_size,
|
||||||
init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start) {
|
size_t thread_count,
|
||||||
|
std::function<void()> on_thread_start) {
|
||||||
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
|
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +234,8 @@ struct source_loc {
|
|||||||
funcname{funcname_in} {}
|
funcname{funcname_in} {}
|
||||||
|
|
||||||
#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
|
#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
|
||||||
static constexpr source_loc
|
static constexpr source_loc current(
|
||||||
current(const std::source_location source_location = std::source_location::current()) {
|
const std::source_location source_location = std::source_location::current()) {
|
||||||
return source_loc{source_location.file_name(), source_location.line(),
|
return source_loc{source_location.file_name(), source_location.line(),
|
||||||
source_location.function_name()};
|
source_location.function_name()};
|
||||||
}
|
}
|
||||||
@ -312,21 +312,21 @@ namespace details {
|
|||||||
#if defined(SPDLOG_USE_STD_FORMAT)
|
#if defined(SPDLOG_USE_STD_FORMAT)
|
||||||
#if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
|
#if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
[[nodiscard]] constexpr std::basic_string_view<T>
|
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
|
||||||
to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
std::basic_format_string<T, Args...> fmt) noexcept {
|
||||||
return fmt.get();
|
return fmt.get();
|
||||||
}
|
}
|
||||||
#else // std::format and __cpp_lib_format < 202207L
|
#else // std::format and __cpp_lib_format < 202207L
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
[[nodiscard]] constexpr std::basic_string_view<T>
|
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
|
||||||
to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
std::basic_format_string<T, Args...> fmt) noexcept {
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else // {fmt} version
|
#else // {fmt} version
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
[[nodiscard]] constexpr fmt::basic_string_view<T>
|
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(
|
||||||
to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept {
|
fmt::basic_format_string<T, Args...> fmt) noexcept {
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,14 +53,10 @@ constexpr unsigned int count_digits_fallback(T n) {
|
|||||||
// Integer division is slow so do it for a group of four digits instead
|
// Integer division is slow so do it for a group of four digits instead
|
||||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||||
if (n < 10)
|
if (n < 10) return count;
|
||||||
return count;
|
if (n < 100) return count + 1;
|
||||||
if (n < 100)
|
if (n < 1000) return count + 2;
|
||||||
return count + 1;
|
if (n < 10000) return count + 3;
|
||||||
if (n < 1000)
|
|
||||||
return count + 2;
|
|
||||||
if (n < 10000)
|
|
||||||
return count + 3;
|
|
||||||
n /= 10000u;
|
n /= 10000u;
|
||||||
count += 4;
|
count += 4;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ inline details::dump_info<typename Container::const_iterator> to_hex(const Conta
|
|||||||
#if __cpp_lib_span >= 202002L
|
#if __cpp_lib_span >= 202002L
|
||||||
|
|
||||||
template <typename Value, size_t Extent>
|
template <typename Value, size_t Extent>
|
||||||
inline details::dump_info<typename std::span<Value, Extent>::iterator>
|
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
|
||||||
to_hex(const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
||||||
using Container = std::span<Value, Extent>;
|
using Container = std::span<Value, Extent>;
|
||||||
static_assert(sizeof(typename Container::value_type) == 1,
|
static_assert(sizeof(typename Container::value_type) == 1,
|
||||||
"sizeof(Container::value_type) != 1");
|
"sizeof(Container::value_type) != 1");
|
||||||
@ -84,8 +84,9 @@ to_hex(const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
|||||||
|
|
||||||
// create dump_info from ranges
|
// create dump_info from ranges
|
||||||
template <typename It>
|
template <typename It>
|
||||||
inline details::dump_info<It>
|
inline details::dump_info<It> to_hex(const It range_begin,
|
||||||
to_hex(const It range_begin, const It range_end, size_t size_per_line = 32) {
|
const It range_end,
|
||||||
|
size_t size_per_line = 32) {
|
||||||
return details::dump_info<It>(range_begin, range_end, size_per_line);
|
return details::dump_info<It>(range_begin, range_end, size_per_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,9 @@ public:
|
|||||||
: padinfo_(padinfo) {}
|
: padinfo_(padinfo) {}
|
||||||
flag_formatter() = default;
|
flag_formatter() = default;
|
||||||
virtual ~flag_formatter() = default;
|
virtual ~flag_formatter() = default;
|
||||||
virtual void
|
virtual void format(const details::log_msg &msg,
|
||||||
format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
|
const std::tm &tm_time,
|
||||||
|
memory_buf_t &dest) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
padding_info padinfo_;
|
padding_info padinfo_;
|
||||||
|
@ -74,14 +74,14 @@ private:
|
|||||||
// __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise,
|
// __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise,
|
||||||
// when using the default log buffer, always log via __android_log_write.
|
// when using the default log buffer, always log via __android_log_write.
|
||||||
template <int ID = BufferID>
|
template <int ID = BufferID>
|
||||||
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type
|
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
|
||||||
android_log(int prio, const char *tag, const char *text) {
|
int prio, const char *tag, const char *text) {
|
||||||
return __android_log_write(prio, tag, text);
|
return __android_log_write(prio, tag, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int ID = BufferID>
|
template <int ID = BufferID>
|
||||||
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type
|
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
|
||||||
android_log(int prio, const char *tag, const char *text) {
|
int prio, const char *tag, const char *text) {
|
||||||
return __android_log_buf_write(ID, prio, tag, text);
|
return __android_log_buf_write(ID, prio, tag, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +212,8 @@ inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> daily_logger_format_mt(
|
||||||
daily_logger_format_mt(const std::string &logger_name,
|
const std::string &logger_name,
|
||||||
const filename_t &filename,
|
const filename_t &filename,
|
||||||
int hour = 0,
|
int hour = 0,
|
||||||
int minute = 0,
|
int minute = 0,
|
||||||
@ -237,8 +237,8 @@ inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> daily_logger_format_st(
|
||||||
daily_logger_format_st(const std::string &logger_name,
|
const std::string &logger_name,
|
||||||
const filename_t &filename,
|
const filename_t &filename,
|
||||||
int hour = 0,
|
int hour = 0,
|
||||||
int minute = 0,
|
int minute = 0,
|
||||||
|
@ -105,14 +105,14 @@ inline std::shared_ptr<logger> kafka_logger_st(const std::string &logger_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::async_factory>
|
template <typename Factory = spdlog::async_factory>
|
||||||
inline std::shared_ptr<spdlog::logger>
|
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(
|
||||||
kafka_logger_async_mt(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||||
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
|
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::async_factory>
|
template <typename Factory = spdlog::async_factory>
|
||||||
inline std::shared_ptr<spdlog::logger>
|
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(
|
||||||
kafka_logger_async_st(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||||
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
|
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
|
|||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> mongo_logger_mt(
|
||||||
mongo_logger_mt(const std::string &logger_name,
|
const std::string &logger_name,
|
||||||
const std::string &db_name,
|
const std::string &db_name,
|
||||||
const std::string &collection_name,
|
const std::string &collection_name,
|
||||||
const std::string &uri = "mongodb://localhost:27017") {
|
const std::string &uri = "mongodb://localhost:27017") {
|
||||||
@ -96,8 +96,8 @@ mongo_logger_mt(const std::string &logger_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> mongo_logger_st(
|
||||||
mongo_logger_st(const std::string &logger_name,
|
const std::string &logger_name,
|
||||||
const std::string &db_name,
|
const std::string &db_name,
|
||||||
const std::string &collection_name,
|
const std::string &collection_name,
|
||||||
const std::string &uri = "mongodb://localhost:27017") {
|
const std::string &uri = "mongodb://localhost:27017") {
|
||||||
|
@ -269,14 +269,16 @@ inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
|||||||
}
|
}
|
||||||
// log to QObject
|
// log to QObject
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name,
|
||||||
qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
QObject *qt_object,
|
||||||
|
const std::string &meta_method) {
|
||||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
inline std::shared_ptr<logger>
|
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
||||||
qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
QObject *qt_object,
|
||||||
|
const std::string &meta_method) {
|
||||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ namespace sinks {
|
|||||||
*/
|
*/
|
||||||
template <typename Mutex>
|
template <typename Mutex>
|
||||||
class syslog_sink : public base_sink<Mutex> {
|
class syslog_sink : public base_sink<Mutex> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
||||||
: enable_formatting_{enable_formatting},
|
: enable_formatting_{enable_formatting},
|
||||||
|
@ -238,8 +238,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~win_eventlog_sink() {
|
~win_eventlog_sink() {
|
||||||
if (hEventLog_)
|
if (hEventLog_) DeregisterEventSource(hEventLog_);
|
||||||
DeregisterEventSource(hEventLog_);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ namespace details {
|
|||||||
namespace os {
|
namespace os {
|
||||||
|
|
||||||
spdlog::log_clock::time_point now() noexcept {
|
spdlog::log_clock::time_point now() noexcept {
|
||||||
|
|
||||||
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
||||||
timespec ts;
|
timespec ts;
|
||||||
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
||||||
@ -81,7 +80,6 @@ spdlog::log_clock::time_point now() noexcept {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::tm localtime(const std::time_t &time_tt) noexcept {
|
std::tm localtime(const std::time_t &time_tt) noexcept {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::tm tm;
|
std::tm tm;
|
||||||
::localtime_s(&tm, &time_tt);
|
::localtime_s(&tm, &time_tt);
|
||||||
@ -98,7 +96,6 @@ std::tm localtime() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::tm gmtime(const std::time_t &time_tt) noexcept {
|
std::tm gmtime(const std::time_t &time_tt) noexcept {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::tm tm;
|
std::tm tm;
|
||||||
::gmtime_s(&tm, &time_tt);
|
::gmtime_s(&tm, &time_tt);
|
||||||
@ -243,7 +240,6 @@ size_t filesize(FILE *f) {
|
|||||||
|
|
||||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||||
int utc_minutes_offset(const std::tm &tm) {
|
int utc_minutes_offset(const std::tm &tm) {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if _WIN32_WINNT < _WIN32_WINNT_WS08
|
#if _WIN32_WINNT < _WIN32_WINNT_WS08
|
||||||
TIME_ZONE_INFORMATION tzinfo;
|
TIME_ZONE_INFORMATION tzinfo;
|
||||||
@ -252,8 +248,7 @@ int utc_minutes_offset(const std::tm &tm) {
|
|||||||
DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
|
DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
|
||||||
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
|
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
|
||||||
#endif
|
#endif
|
||||||
if (rv == TIME_ZONE_ID_INVALID)
|
if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno);
|
||||||
throw_spdlog_ex("Failed getting timezone info. ", errno);
|
|
||||||
|
|
||||||
int offset = -tzinfo.Bias;
|
int offset = -tzinfo.Bias;
|
||||||
if (tm.tm_isdst) {
|
if (tm.tm_isdst) {
|
||||||
@ -379,7 +374,6 @@ std::string filename_to_str(const filename_t &filename) { return filename; }
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int pid() noexcept {
|
int pid() noexcept {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return static_cast<int>(::GetCurrentProcessId());
|
return static_cast<int>(::GetCurrentProcessId());
|
||||||
#else
|
#else
|
||||||
@ -421,7 +415,6 @@ bool is_color_terminal() noexcept {
|
|||||||
// Determine if the terminal attached
|
// Determine if the terminal attached
|
||||||
// Source: https://github.com/agauniyal/rang/
|
// Source: https://github.com/agauniyal/rang/
|
||||||
bool in_terminal(FILE *file) noexcept {
|
bool in_terminal(FILE *file) noexcept {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return ::_isatty(_fileno(file)) != 0;
|
return ::_isatty(_fileno(file)) != 0;
|
||||||
#else
|
#else
|
||||||
@ -546,7 +539,6 @@ filename_t dir_name(const filename_t &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string getenv(const char *field) {
|
std::string getenv(const char *field) {
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#if defined(__cplusplus_winrt)
|
#if defined(__cplusplus_winrt)
|
||||||
return std::string{}; // not supported under uwp
|
return std::string{}; // not supported under uwp
|
||||||
|
@ -28,7 +28,6 @@ namespace details {
|
|||||||
|
|
||||||
registry::registry()
|
registry::registry()
|
||||||
: formatter_(new pattern_formatter()) {
|
: formatter_(new pattern_formatter()) {
|
||||||
|
|
||||||
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
|
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
|
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -14,7 +14,8 @@ thread_pool::thread_pool(size_t q_max_items,
|
|||||||
std::function<void()> on_thread_stop)
|
std::function<void()> on_thread_stop)
|
||||||
: q_(q_max_items) {
|
: q_(q_max_items) {
|
||||||
if (threads_n == 0 || threads_n > 1000) {
|
if (threads_n == 0 || threads_n > 1000) {
|
||||||
throw_spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
throw_spdlog_ex(
|
||||||
|
"spdlog::thread_pool(): invalid threads_n param (valid "
|
||||||
"range is 1-1000)");
|
"range is 1-1000)");
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < threads_n; i++) {
|
for (size_t i = 0; i < threads_n; i++) {
|
||||||
|
@ -23,8 +23,10 @@ template FMT_API auto decimal_point_impl(locale_ref) -> char;
|
|||||||
|
|
||||||
template FMT_API void buffer<char>::append(const char *, const char *);
|
template FMT_API void buffer<char>::append(const char *, const char *);
|
||||||
|
|
||||||
template FMT_API void
|
template FMT_API void vformat_to(buffer<char> &,
|
||||||
vformat_to(buffer<char> &, string_view, typename vformat_args<>::type, locale_ref);
|
string_view,
|
||||||
|
typename vformat_args<>::type,
|
||||||
|
locale_ref);
|
||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
|
@ -958,7 +958,8 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L': // short level
|
case 'L': // short level
|
||||||
formatters_.push_back(std::make_unique<details::short_level_formatter<Padder>>(padding));
|
formatters_.push_back(
|
||||||
|
std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ('t'): // thread id
|
case ('t'): // thread id
|
||||||
@ -1101,7 +1102,8 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ('s'): // short source filename - without directory name
|
case ('s'): // short source filename - without directory name
|
||||||
formatters_.push_back(std::make_unique<details::short_filename_formatter<Padder>>(padding));
|
formatters_.push_back(
|
||||||
|
std::make_unique<details::short_filename_formatter<Padder>>(padding));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ('g'): // full source filename
|
case ('g'): // full source filename
|
||||||
@ -1110,7 +1112,8 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ('#'): // source line number
|
case ('#'): // source line number
|
||||||
formatters_.push_back(std::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
formatters_.push_back(
|
||||||
|
std::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ('!'): // source funcname
|
case ('!'): // source funcname
|
||||||
@ -1142,7 +1145,8 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
|||||||
|
|
||||||
case ('O'): // elapsed time since last log message in seconds
|
case ('O'): // elapsed time since last log message in seconds
|
||||||
formatters_.push_back(
|
formatters_.push_back(
|
||||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
|
std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(
|
||||||
|
padding));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // Unknown flag appears as is
|
default: // Unknown flag appears as is
|
||||||
@ -1153,9 +1157,9 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
|||||||
unknown_flag->add_ch(flag);
|
unknown_flag->add_ch(flag);
|
||||||
formatters_.push_back((std::move(unknown_flag)));
|
formatters_.push_back((std::move(unknown_flag)));
|
||||||
}
|
}
|
||||||
// fix issue #1617 (prev char was '!' and should have been treated as funcname flag instead
|
// fix issue #1617 (prev char was '!' and should have been treated as funcname flag
|
||||||
// of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some message"
|
// instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some
|
||||||
// spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
|
// message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
|
||||||
else {
|
else {
|
||||||
padding.truncate_ = false;
|
padding.truncate_ = false;
|
||||||
formatters_.push_back(
|
formatters_.push_back(
|
||||||
|
@ -106,11 +106,12 @@ void rotating_file_sink<Mutex>::rotate_() {
|
|||||||
if (!rename_file_(src, target)) {
|
if (!rename_file_(src, target)) {
|
||||||
// if failed try again after a small delay.
|
// if failed try again after a small delay.
|
||||||
// this is a workaround to a windows issue, where very high rotation
|
// this is a workaround to a windows issue, where very high rotation
|
||||||
// rates can cause the rename to fail with permission denied (because of antivirus?).
|
// rates can cause the rename to fail with permission denied (because of
|
||||||
|
// antivirus?).
|
||||||
details::os::sleep_for_millis(100);
|
details::os::sleep_for_millis(100);
|
||||||
if (!rename_file_(src, target)) {
|
if (!rename_file_(src, target)) {
|
||||||
file_helper_.reopen(
|
file_helper_.reopen(true); // truncate the log file anyway to prevent it
|
||||||
true); // truncate the log file anyway to prevent it to grow beyond its limit!
|
// to grow beyond its limit!
|
||||||
current_size_ = 0;
|
current_size_ = 0;
|
||||||
throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) +
|
throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) +
|
||||||
" to " + filename_to_str(target),
|
" to " + filename_to_str(target),
|
||||||
|
@ -47,14 +47,14 @@ template SPDLOG_API std::shared_ptr<spdlog::logger>
|
|||||||
spdlog::stderr_color_st<spdlog::synchronous_factory>(const std::string &logger_name,
|
spdlog::stderr_color_st<spdlog::synchronous_factory>(const std::string &logger_name,
|
||||||
color_mode mode);
|
color_mode mode);
|
||||||
|
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt<spdlog::async_factory>(
|
||||||
spdlog::stdout_color_mt<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
const std::string &logger_name, color_mode mode);
|
||||||
|
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::async_factory>(
|
||||||
spdlog::stdout_color_st<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
const std::string &logger_name, color_mode mode);
|
||||||
|
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::async_factory>(
|
||||||
spdlog::stderr_color_mt<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
const std::string &logger_name, color_mode mode);
|
||||||
|
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
|
||||||
spdlog::stderr_color_st<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
const std::string &logger_name, color_mode mode);
|
||||||
|
@ -141,11 +141,11 @@ spdlog::stderr_logger_mt<spdlog::synchronous_factory>(const std::string &logger_
|
|||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||||
spdlog::stderr_logger_st<spdlog::synchronous_factory>(const std::string &logger_name);
|
spdlog::stderr_logger_st<spdlog::synchronous_factory>(const std::string &logger_name);
|
||||||
|
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt<spdlog::async_factory>(
|
||||||
spdlog::stdout_logger_mt<spdlog::async_factory>(const std::string &logger_name);
|
const std::string &logger_name);
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(
|
||||||
spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name);
|
const std::string &logger_name);
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(
|
||||||
spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name);
|
const std::string &logger_name);
|
||||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(
|
||||||
spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name);
|
const std::string &logger_name);
|
||||||
|
@ -94,7 +94,6 @@ TEST_CASE("flush", "[async]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("async periodic flush", "[async]") {
|
TEST_CASE("async periodic flush", "[async]") {
|
||||||
|
|
||||||
auto logger = spdlog::create_async<spdlog::sinks::test_sink_mt>("as");
|
auto logger = spdlog::create_async<spdlog::sinks::test_sink_mt>("as");
|
||||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
|||||||
|
|
||||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
|
||||||
logger->info("Test message {}", i);
|
logger->info("Test message {}", i);
|
||||||
}
|
}
|
||||||
logger->flush();
|
logger->flush();
|
||||||
|
@ -100,8 +100,7 @@ TEST_CASE("async_error_handler2", "[errors]") {
|
|||||||
auto logger = spdlog::create_async<failing_sink>("failed_logger");
|
auto logger = spdlog::create_async<failing_sink>("failed_logger");
|
||||||
logger->set_error_handler([=](const std::string &) {
|
logger->set_error_handler([=](const std::string &) {
|
||||||
std::ofstream ofs("test_logs/custom_err2.txt");
|
std::ofstream ofs("test_logs/custom_err2.txt");
|
||||||
if (!ofs)
|
if (!ofs) throw std::runtime_error("Failed open test_logs/custom_err2.txt");
|
||||||
throw std::runtime_error("Failed open test_logs/custom_err2.txt");
|
|
||||||
ofs << err_msg;
|
ofs << err_msg;
|
||||||
});
|
});
|
||||||
logger->info("Hello failure");
|
logger->info("Hello failure");
|
||||||
|
@ -85,7 +85,6 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]") {
|
|||||||
require_message_count(ROTATING_LOG, 10);
|
require_message_count(ROTATING_LOG, 10);
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
|
||||||
logger->info("Test message {}", i);
|
logger->info("Test message {}", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#define TEST_FILENAME "test_logs/simple_log"
|
#define TEST_FILENAME "test_logs/simple_log"
|
||||||
|
|
||||||
TEST_CASE("debug and trace w/o format string", "[macros]") {
|
TEST_CASE("debug and trace w/o format string", "[macros]") {
|
||||||
|
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string log_info(const T &what, spdlog::level logger_level = spdlog::level::info) {
|
std::string log_info(const T &what, spdlog::level logger_level = spdlog::level::info) {
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") {
|
TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") {
|
||||||
|
|
||||||
size_t q_size = 100;
|
size_t q_size = 100;
|
||||||
milliseconds wait_ms(250);
|
milliseconds wait_ms(250);
|
||||||
milliseconds tolerance_wait(250);
|
milliseconds tolerance_wait(250);
|
||||||
@ -59,7 +58,6 @@ TEST_CASE("dequeue-full-wait", "[mpmc_blocking_q]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") {
|
TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") {
|
||||||
|
|
||||||
size_t q_size = 1;
|
size_t q_size = 1;
|
||||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||||
milliseconds tolerance_wait(10);
|
milliseconds tolerance_wait(10);
|
||||||
|
@ -35,8 +35,7 @@ std::size_t count_lines(const std::string &filename) {
|
|||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
size_t counter = 0;
|
size_t counter = 0;
|
||||||
while (std::getline(ifs, line))
|
while (std::getline(ifs, line)) counter++;
|
||||||
counter++;
|
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +75,7 @@ std::size_t count_files(const std::string &folder) {
|
|||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
do // Managed to locate and create an handle to that folder.
|
do // Managed to locate and create an handle to that folder.
|
||||||
{
|
{
|
||||||
if (ffd.cFileName[0] != '.')
|
if (ffd.cFileName[0] != '.') counter++;
|
||||||
counter++;
|
|
||||||
} while (::FindNextFileA(hFind, &ffd) != 0);
|
} while (::FindNextFileA(hFind, &ffd) != 0);
|
||||||
::FindClose(hFind);
|
::FindClose(hFind);
|
||||||
} else {
|
} else {
|
||||||
@ -97,8 +95,7 @@ std::size_t count_files(const std::string &folder) {
|
|||||||
|
|
||||||
struct dirent *ep = nullptr;
|
struct dirent *ep = nullptr;
|
||||||
while ((ep = readdir(dp)) != nullptr) {
|
while ((ep = readdir(dp)) != nullptr) {
|
||||||
if (ep->d_name[0] != '.')
|
if (ep->d_name[0] != '.') counter++;
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
(void)closedir(dp);
|
(void)closedir(dp);
|
||||||
return counter;
|
return counter;
|
||||||
|
Loading…
Reference in New Issue
Block a user