mirror of
https://github.com/gabime/spdlog.git
synced 2025-02-26 02:05:50 +08:00
code format
Some checks failed
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 4s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 2s
Some checks failed
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:OFF BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019]) (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 4s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 2s
This commit is contained in:
parent
b9f0243405
commit
47fe6ef92a
@ -6,14 +6,14 @@
|
|||||||
//
|
//
|
||||||
// bench.cpp : spdlog benchmarks
|
// bench.cpp : spdlog benchmarks
|
||||||
//
|
//
|
||||||
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <locale>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <locale>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "spdlog/sinks/async_sink.h"
|
#include "spdlog/sinks/async_sink.h"
|
||||||
#include "spdlog/sinks/basic_file_sink.h"
|
#include "spdlog/sinks/basic_file_sink.h"
|
||||||
|
@ -124,7 +124,8 @@ int main(int argc, char *argv[]) {
|
|||||||
benchmark::RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime();
|
benchmark::RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime();
|
||||||
|
|
||||||
// rotating st
|
// rotating st
|
||||||
auto rotating_st = spdlog::create<rotating_file_sink_st>("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files);
|
auto rotating_st =
|
||||||
|
spdlog::create<rotating_file_sink_st>("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files);
|
||||||
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))->UseRealTime();
|
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))->UseRealTime();
|
||||||
|
|
||||||
// daily st
|
// daily st
|
||||||
@ -142,7 +143,8 @@ int main(int argc, char *argv[]) {
|
|||||||
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))->Threads(n_threads)->UseRealTime();
|
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))->Threads(n_threads)->UseRealTime();
|
||||||
|
|
||||||
// rotating mt
|
// rotating mt
|
||||||
auto rotating_mt = spdlog::create<rotating_file_sink_mt>("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files);
|
auto rotating_mt =
|
||||||
|
spdlog::create<rotating_file_sink_mt>("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files);
|
||||||
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))->Threads(n_threads)->UseRealTime();
|
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))->Threads(n_threads)->UseRealTime();
|
||||||
|
|
||||||
// daily mt
|
// daily mt
|
||||||
@ -151,7 +153,8 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
using spdlog::sinks::async_sink;
|
using spdlog::sinks::async_sink;
|
||||||
async_sink::config config;
|
async_sink::config config;
|
||||||
config.queue_size = 3 * 1024 * 1024;;
|
config.queue_size = 3 * 1024 * 1024;
|
||||||
|
;
|
||||||
config.sinks.push_back(std::make_shared<null_sink_st>());
|
config.sinks.push_back(std::make_shared<null_sink_st>());
|
||||||
config.policy = async_sink::overflow_policy::overrun_oldest;
|
config.policy = async_sink::overflow_policy::overrun_oldest;
|
||||||
auto async_logger = std::make_shared<spdlog::logger>("async_logger", std::make_shared<async_sink>(config));
|
auto async_logger = std::make_shared<spdlog::logger>("async_logger", std::make_shared<async_sink>(config));
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#include "./source_loc.h"
|
#include "./source_loc.h"
|
||||||
#include "fmt/base.h"
|
#include "fmt/base.h"
|
||||||
|
@ -4,29 +4,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "./log_msg.h"
|
#include "./log_msg.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
// Extend log_msg with internal buffer to store its payload.
|
// Extend log_msg with internal buffer to store its payload.
|
||||||
// This is needed since log_msg holds string_views that points to stack data.
|
// This is needed since log_msg holds string_views that points to stack data.
|
||||||
|
|
||||||
class SPDLOG_API async_log_msg : public log_msg {
|
class SPDLOG_API async_log_msg : public log_msg {
|
||||||
public:
|
public:
|
||||||
enum class type : std::uint8_t { log, flush, terminate };
|
enum class type : std::uint8_t { log, flush, terminate };
|
||||||
async_log_msg() = default;
|
async_log_msg() = default;
|
||||||
explicit async_log_msg(type type);
|
explicit async_log_msg(type type);
|
||||||
async_log_msg(type type, const log_msg &orig_msg);
|
async_log_msg(type type, const log_msg &orig_msg);
|
||||||
|
|
||||||
~async_log_msg() = default;
|
~async_log_msg() = default;
|
||||||
async_log_msg(const async_log_msg &other);
|
async_log_msg(const async_log_msg &other);
|
||||||
async_log_msg(async_log_msg &&other) noexcept;
|
async_log_msg(async_log_msg &&other) noexcept;
|
||||||
async_log_msg &operator=(const async_log_msg &other);
|
async_log_msg &operator=(const async_log_msg &other);
|
||||||
async_log_msg &operator=(async_log_msg &&other) noexcept;
|
async_log_msg &operator=(async_log_msg &&other) noexcept;
|
||||||
|
[[nodiscard]] type message_type() const { return msg_type_; }
|
||||||
|
|
||||||
type message_type() const {return msg_type_;}
|
|
||||||
private:
|
private:
|
||||||
type msg_type_{type::log};
|
type msg_type_{type::log};
|
||||||
memory_buf_t buffer_;
|
memory_buf_t buffer_;
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
|
|
||||||
// by default, prints the error to stderr, at max rate of 1/sec thread safe
|
// by default, prints the error to stderr, at max rate of 1/sec thread safe
|
||||||
@ -16,6 +17,7 @@ class SPDLOG_API err_helper {
|
|||||||
err_handler custom_err_handler_;
|
err_handler custom_err_handler_;
|
||||||
std::chrono::steady_clock::time_point last_report_time_;
|
std::chrono::steady_clock::time_point last_report_time_;
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
err_helper() = default;
|
err_helper() = default;
|
||||||
~err_helper() = default;
|
~err_helper() = default;
|
||||||
|
@ -91,7 +91,6 @@ public:
|
|||||||
return std::make_shared<async_sink>(cfg);
|
return std::make_shared<async_sink>(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using async_log_msg = details::async_log_msg;
|
using async_log_msg = details::async_log_msg;
|
||||||
using queue_t = details::mpmc_blocking_queue<async_log_msg>;
|
using queue_t = details::mpmc_blocking_queue<async_log_msg>;
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
#include <mongocxx/client.hpp>
|
#include <mongocxx/client.hpp>
|
||||||
#include <mongocxx/instance.hpp>
|
#include <mongocxx/instance.hpp>
|
||||||
#include <mongocxx/uri.hpp>
|
#include <mongocxx/uri.hpp>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "../details/null_mutex.h"
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../details/log_msg.h"
|
#include "../details/log_msg.h"
|
||||||
|
#include "../details/null_mutex.h"
|
||||||
#include "./base_sink.h"
|
#include "./base_sink.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "./base_sink.h"
|
#include "./base_sink.h"
|
||||||
|
|
||||||
|
@ -46,7 +46,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sink_it_(const details::log_msg &msg) override { q_.push_back(details::async_log_msg{details::async_log_msg::type::log, msg}); }
|
void sink_it_(const details::log_msg &msg) override {
|
||||||
|
q_.push_back(details::async_log_msg{details::async_log_msg::type::log, msg});
|
||||||
|
}
|
||||||
void flush_() override {}
|
void flush_() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
async_log_msg::async_log_msg(const type type)
|
async_log_msg::async_log_msg(const type type)
|
||||||
: msg_type_{type} {}
|
: msg_type_{type} {}
|
||||||
|
|
||||||
@ -15,21 +14,25 @@ async_log_msg::async_log_msg(const type type)
|
|||||||
// are compiler generated const chars* (__FILE__, __LINE__, __FUNCTION__)
|
// are compiler generated const chars* (__FILE__, __LINE__, __FUNCTION__)
|
||||||
// if you pass custom strings to source location, make sure they outlive the async_log_msg
|
// if you pass custom strings to source location, make sure they outlive the async_log_msg
|
||||||
async_log_msg::async_log_msg(const type type, const log_msg &orig_msg)
|
async_log_msg::async_log_msg(const type type, const log_msg &orig_msg)
|
||||||
: log_msg{orig_msg}, msg_type_(type) {
|
: log_msg{orig_msg},
|
||||||
|
msg_type_(type) {
|
||||||
buffer_.append(logger_name);
|
buffer_.append(logger_name);
|
||||||
buffer_.append(payload);
|
buffer_.append(payload);
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
async_log_msg::async_log_msg(const async_log_msg &other)
|
async_log_msg::async_log_msg(const async_log_msg &other)
|
||||||
: log_msg{other}, msg_type_{other.msg_type_} {
|
: log_msg{other},
|
||||||
|
msg_type_{other.msg_type_} {
|
||||||
buffer_.append(logger_name);
|
buffer_.append(logger_name);
|
||||||
buffer_.append(payload);
|
buffer_.append(payload);
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
async_log_msg::async_log_msg(async_log_msg &&other) noexcept
|
async_log_msg::async_log_msg(async_log_msg &&other) noexcept
|
||||||
: log_msg{other}, msg_type_{other.msg_type_}, buffer_{std::move(other.buffer_)} {
|
: log_msg{other},
|
||||||
|
msg_type_{other.msg_type_},
|
||||||
|
buffer_{std::move(other.buffer_)} {
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,6 @@ template <typename Mutex>
|
|||||||
ansicolor_stderr_sink<Mutex>::ansicolor_stderr_sink(color_mode mode)
|
ansicolor_stderr_sink<Mutex>::ansicolor_stderr_sink(color_mode mode)
|
||||||
: ansicolor_sink<Mutex>(stderr, mode) {}
|
: ansicolor_sink<Mutex>(stderr, mode) {}
|
||||||
|
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ async_sink::async_sink(config async_config)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async_sink::~async_sink() {
|
async_sink::~async_sink() {
|
||||||
try {
|
try {
|
||||||
q_->enqueue(async_log_msg(async_log_msg::type::terminate));
|
q_->enqueue(async_log_msg(async_log_msg::type::terminate));
|
||||||
@ -46,13 +45,9 @@ async_sink::~async_sink() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void async_sink::log(const details::log_msg &msg) {
|
void async_sink::log(const details::log_msg &msg) { enqueue_message_(async_log_msg(async_log_msg::type::log, msg)); }
|
||||||
enqueue_message_(async_log_msg(async_log_msg::type::log, msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
void async_sink::flush() {
|
void async_sink::flush() { enqueue_message_(details::async_log_msg(async_log_msg::type::flush)); }
|
||||||
enqueue_message_(details::async_log_msg(async_log_msg::type::flush));
|
|
||||||
}
|
|
||||||
|
|
||||||
void async_sink::set_pattern(const std::string &pattern) { set_formatter(std::make_unique<pattern_formatter>(pattern)); }
|
void async_sink::set_pattern(const std::string &pattern) { set_formatter(std::make_unique<pattern_formatter>(pattern)); }
|
||||||
|
|
||||||
@ -83,7 +78,8 @@ bool async_sink::wait_all(const std::chrono::milliseconds timeout) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void async_sink::wait_all() const {
|
void async_sink::wait_all() const {
|
||||||
while (!wait_all(std::chrono::milliseconds(10))) { /* empty */ }
|
while (!wait_all(std::chrono::milliseconds(10))) { /* empty */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t async_sink::get_overrun_counter() const { return q_->overrun_counter(); }
|
size_t async_sink::get_overrun_counter() const { return q_->overrun_counter(); }
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/pattern_formatter.h"
|
#include "spdlog/pattern_formatter.h"
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
#include "spdlog/sinks/basic_file_sink.h"
|
#include "spdlog/sinks/basic_file_sink.h"
|
||||||
#include "spdlog/common.h"
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "spdlog/common.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
|
|
||||||
@ -34,7 +36,6 @@ void basic_file_sink<Mutex>::flush_() {
|
|||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
|
|
||||||
// template instantiations
|
// template instantiations
|
||||||
#include "spdlog/details/null_mutex.h"
|
#include "spdlog/details/null_mutex.h"
|
||||||
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;
|
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
#include "spdlog/sinks/wincolor_sink.h"
|
#include "spdlog/sinks/wincolor_sink.h"
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
@ -131,7 +132,6 @@ template <typename Mutex>
|
|||||||
wincolor_stderr_sink<Mutex>::wincolor_stderr_sink(color_mode mode)
|
wincolor_stderr_sink<Mutex>::wincolor_stderr_sink(color_mode mode)
|
||||||
: wincolor_sink<Mutex>(::GetStdHandle(STD_ERROR_HANDLE), mode) {}
|
: wincolor_sink<Mutex>(::GetStdHandle(STD_ERROR_HANDLE), mode) {}
|
||||||
|
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
|
@ -13,21 +13,17 @@
|
|||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
|
|
||||||
|
|
||||||
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
|
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
|
||||||
static std::shared_ptr<logger> s_logger = std::make_shared<logger>("", std::make_shared<sinks::stdout_color_sink_mt>());
|
static std::shared_ptr<logger> s_logger = std::make_shared<logger>("", std::make_shared<sinks::stdout_color_sink_mt>());
|
||||||
#else
|
#else
|
||||||
static std::short_ptr<logger> s_logger = nullptr;
|
static std::short_ptr<logger> s_logger = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<logger> global_logger() { return s_logger; }
|
std::shared_ptr<logger> global_logger() { return s_logger; }
|
||||||
|
|
||||||
void set_global_logger(std::shared_ptr<logger> global_logger) { s_logger = std::move(global_logger); }
|
void set_global_logger(std::shared_ptr<logger> global_logger) { s_logger = std::move(global_logger); }
|
||||||
|
|
||||||
logger *global_logger_raw() noexcept {
|
logger *global_logger_raw() noexcept { return s_logger.get(); }
|
||||||
return s_logger.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_formatter(std::unique_ptr<formatter> formatter) { global_logger()->set_formatter(std::move(formatter)); }
|
void set_formatter(std::unique_ptr<formatter> formatter) { global_logger()->set_formatter(std::move(formatter)); }
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ TEST_CASE("discard policy discard_new ", "[async]") {
|
|||||||
auto as = std::make_shared<async_sink>(config);
|
auto as = std::make_shared<async_sink>(config);
|
||||||
auto logger = std::make_shared<spdlog::logger>("async_logger", as);
|
auto logger = std::make_shared<spdlog::logger>("async_logger", as);
|
||||||
|
|
||||||
|
|
||||||
REQUIRE(as->get_config().policy == async_sink::overflow_policy::discard_new);
|
REQUIRE(as->get_config().policy == async_sink::overflow_policy::discard_new);
|
||||||
REQUIRE(as->get_discard_counter() == 0);
|
REQUIRE(as->get_discard_counter() == 0);
|
||||||
REQUIRE(as->get_overrun_counter() == 0);
|
REQUIRE(as->get_overrun_counter() == 0);
|
||||||
@ -167,7 +166,6 @@ TEST_CASE("to_file", "[async]") {
|
|||||||
REQUIRE(ends_with(contents, spdlog::fmt_lib::format("Hello message #1023{}", default_eol)));
|
REQUIRE(ends_with(contents, spdlog::fmt_lib::format("Hello message #1023{}", default_eol)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("bad_ctor", "[async]") {
|
TEST_CASE("bad_ctor", "[async]") {
|
||||||
async_sink::config cfg;
|
async_sink::config cfg;
|
||||||
cfg.queue_size = 0;
|
cfg.queue_size = 0;
|
||||||
|
@ -18,7 +18,6 @@ protected:
|
|||||||
};
|
};
|
||||||
struct custom_ex {};
|
struct custom_ex {};
|
||||||
|
|
||||||
|
|
||||||
using namespace spdlog::sinks;
|
using namespace spdlog::sinks;
|
||||||
TEST_CASE("default_error_handler", "[errors]") {
|
TEST_CASE("default_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
@ -36,9 +35,7 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
|||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
auto logger = spdlog::create<basic_file_sink_mt>("test-format-error", log_filename);
|
auto logger = spdlog::create<basic_file_sink_mt>("test-format-error", log_filename);
|
||||||
logger->flush_on(spdlog::level::info);
|
logger->flush_on(spdlog::level::info);
|
||||||
logger->set_error_handler([=](const std::string & msg) {
|
logger->set_error_handler([=](const std::string &msg) { REQUIRE(msg == "argument not found"); });
|
||||||
REQUIRE(msg == "argument not found");
|
|
||||||
});
|
|
||||||
logger->info("Good message #1");
|
logger->info("Good message #1");
|
||||||
REQUIRE_NOTHROW(logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx"));
|
REQUIRE_NOTHROW(logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx"));
|
||||||
logger->info("Good message #2");
|
logger->info("Good message #2");
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <exception>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
#include "spdlog/details/null_mutex.h"
|
#include "spdlog/details/null_mutex.h"
|
||||||
#include "spdlog/details/os.h"
|
#include "spdlog/details/os.h"
|
||||||
@ -37,13 +37,9 @@ public:
|
|||||||
delay_ = delay;
|
delay_ = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_exception(const std::runtime_error& ex) {
|
void set_exception(const std::runtime_error& ex) { exception_ptr_ = std::make_exception_ptr(ex); }
|
||||||
exception_ptr_ = std::make_exception_ptr(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear_exception() {
|
void clear_exception() { exception_ptr_ = nullptr; }
|
||||||
exception_ptr_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return last output without the eol
|
// return last output without the eol
|
||||||
std::vector<std::string> lines() {
|
std::vector<std::string> lines() {
|
||||||
|
Loading…
Reference in New Issue
Block a user