1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-05-05 06:03:52 +00:00

Compare commits

..

No commits in common. "v1.x" and "v1.15.2" have entirely different histories.

3 changed files with 13 additions and 14 deletions

View File

@ -304,13 +304,12 @@ endif ()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
if (SPDLOG_NO_EXCEPTIONS) if (SPDLOG_NO_EXCEPTIONS)
if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO) if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
target_compile_definitions(spdlog PUBLIC FMT_USE_EXCEPTIONS=0) target_compile_definitions(spdlog PUBLIC FMT_EXCEPTIONS=0)
endif () endif ()
if (NOT MSVC) if (NOT MSVC)
target_compile_options(spdlog PRIVATE -fno-exceptions) target_compile_options(spdlog PRIVATE -fno-exceptions)
else () else ()
target_compile_options(spdlog PRIVATE /EHs-c-) target_compile_options(spdlog PRIVATE /EHs-c-)
target_compile_definitions(spdlog PRIVATE _HAS_EXCEPTIONS=0)
endif () endif ()
endif () endif ()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------

View File

@ -11,7 +11,7 @@ Fast C++ logging library
## Install ## Install
#### Header-only version #### Header-only version
Copy the include [folder](include/spdlog) to your build tree and use a C++11 compiler. Copy the include [folder](https://github.com/gabime/spdlog/tree/v1.x/include/spdlog) to your build tree and use a C++11 compiler.
#### Compiled version (recommended - much faster compile times) #### Compiled version (recommended - much faster compile times)
```console ```console
@ -19,7 +19,7 @@ $ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build $ cd spdlog && mkdir build && cd build
$ cmake .. && cmake --build . $ cmake .. && cmake --build .
``` ```
see example [CMakeLists.txt](example/CMakeLists.txt) on how to use. see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt) on how to use.
## Platforms ## Platforms
* Linux, FreeBSD, OpenBSD, Solaris, AIX * Linux, FreeBSD, OpenBSD, Solaris, AIX
@ -48,7 +48,7 @@ see example [CMakeLists.txt](example/CMakeLists.txt) on how to use.
* Headers only or compiled * Headers only or compiled
* Feature-rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library. * Feature-rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
* Asynchronous mode (optional) * Asynchronous mode (optional)
* [Custom](https://github.com/gabime/spdlog/wiki/Custom-formatting) formatting. * [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
* Multi/Single threaded loggers. * Multi/Single threaded loggers.
* Various log targets: * Various log targets:
* Rotating log files. * Rotating log files.
@ -58,7 +58,7 @@ see example [CMakeLists.txt](example/CMakeLists.txt) on how to use.
* Windows event log. * Windows event log.
* Windows debugger (```OutputDebugString(..)```). * Windows debugger (```OutputDebugString(..)```).
* Log to Qt widgets ([example](#log-to-qt-with-nice-colors)). * Log to Qt widgets ([example](#log-to-qt-with-nice-colors)).
* Easily [extendable](https://github.com/gabime/spdlog/wiki/Sinks#implementing-your-own-sink) with custom log targets. * Easily [extendable](https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink) with custom log targets.
* Log filtering - log levels can be modified at runtime as well as compile time. * Log filtering - log levels can be modified at runtime as well as compile time.
* Support for loading log levels from argv or environment var. * Support for loading log levels from argv or environment var.
* [Backtrace](#backtrace-support) support - store debug messages in a ring buffer and display them later on demand. * [Backtrace](#backtrace-support) support - store debug messages in a ring buffer and display them later on demand.
@ -467,7 +467,7 @@ void mdc_example()
--- ---
## Benchmarks ## Benchmarks
Below are some [benchmarks](bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
#### Synchronous mode #### Synchronous mode
``` ```
@ -519,8 +519,7 @@ Below are some [benchmarks](bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-477
``` ```
## Documentation ## Documentation
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki/1.-QuickStart) pages.
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki) pages.
--- ---

View File

@ -40,21 +40,22 @@ template <typename Mutex>
class dup_filter_sink : public dist_sink<Mutex> { class dup_filter_sink : public dist_sink<Mutex> {
public: public:
template <class Rep, class Period> template <class Rep, class Period>
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration) explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration,
: max_skip_duration_{max_skip_duration} {} level::level_enum notification_level = level::info)
: max_skip_duration_{max_skip_duration},
log_level_{notification_level} {}
protected: protected:
std::chrono::microseconds max_skip_duration_; std::chrono::microseconds max_skip_duration_;
log_clock::time_point last_msg_time_; log_clock::time_point last_msg_time_;
std::string last_msg_payload_; std::string last_msg_payload_;
size_t skip_counter_ = 0; size_t skip_counter_ = 0;
level::level_enum skipped_msg_log_level_ = spdlog::level::level_enum::off; level::level_enum log_level_;
void sink_it_(const details::log_msg &msg) override { void sink_it_(const details::log_msg &msg) override {
bool filtered = filter_(msg); bool filtered = filter_(msg);
if (!filtered) { if (!filtered) {
skip_counter_ += 1; skip_counter_ += 1;
skipped_msg_log_level_ = msg.level;
return; return;
} }
@ -64,7 +65,7 @@ protected:
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..",
static_cast<unsigned>(skip_counter_)); static_cast<unsigned>(skip_counter_));
if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf)) { if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf)) {
details::log_msg skipped_msg{msg.source, msg.logger_name, skipped_msg_log_level_, details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_,
string_view_t{buf, static_cast<size_t>(msg_size)}}; string_view_t{buf, static_cast<size_t>(msg_size)}};
dist_sink<Mutex>::sink_it_(skipped_msg); dist_sink<Mutex>::sink_it_(skipped_msg);
} }