mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Compare commits
6 Commits
update-jet
...
codex/fix-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0d5d8140ec | ||
![]() |
287333ee00 | ||
![]() |
ad725d34cc | ||
![]() |
e655dbb685 | ||
![]() |
b18a234ed6 | ||
![]() |
5d89b5b91c |
3
.github/workflows/coverity_scan.yml
vendored
3
.github/workflows/coverity_scan.yml
vendored
@@ -1,6 +1,6 @@
|
||||
name: coverity-linux
|
||||
|
||||
on: [pull_request]
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -35,6 +35,7 @@ jobs:
|
||||
run: |
|
||||
tar czf cov-int.tgz cov-int
|
||||
response=$(curl --silent --show-error --fail \
|
||||
--form email="${{ secrets.EMAIL }}" \
|
||||
--form token="${{ secrets.COVERITY_TOKEN }}" \
|
||||
--form file=@cov-int.tgz \
|
||||
--form version="GitHub PR #${{ github.event.pull_request.number }}" \
|
||||
|
@@ -71,7 +71,7 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void load_levels(const std::string &input) {
|
||||
if (input.empty() || input.size() > 512) {
|
||||
if (input.empty() || input.size() >= 32768) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -563,21 +563,21 @@ SPDLOG_INLINE filename_t dir_name(const filename_t &path) {
|
||||
return pos != filename_t::npos ? path.substr(0, pos) : filename_t{};
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif // _MSC_VER
|
||||
std::string SPDLOG_INLINE getenv(const char *field) {
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(__cplusplus_winrt)
|
||||
#if defined(_MSC_VER) && defined(__cplusplus_winrt)
|
||||
return std::string{}; // not supported under uwp
|
||||
#else
|
||||
size_t len = 0;
|
||||
char buf[128];
|
||||
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
|
||||
return ok ? buf : std::string{};
|
||||
#endif
|
||||
#else // revert to getenv
|
||||
char *buf = ::getenv(field);
|
||||
#else
|
||||
char *buf = std::getenv(field);
|
||||
return buf ? buf : std::string{};
|
||||
#endif
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Do fsync by FILE handlerpointer
|
||||
// Return true on success
|
||||
|
@@ -20,11 +20,7 @@
|
||||
#ifndef FMT_USE_WINDOWS_H
|
||||
#define FMT_USE_WINDOWS_H 0
|
||||
#endif
|
||||
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
#include <spdlog/fmt/bundled/format.h>
|
||||
|
||||
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
|
||||
#include <fmt/base.h>
|
||||
#include <fmt/format.h>
|
||||
#endif
|
||||
|
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
void log(const details::log_msg &msg) override;
|
||||
void flush() override;
|
||||
void set_pattern(const std::string &pattern) final override;
|
||||
void set_pattern(const std::string &pattern) override;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
|
||||
|
||||
// Formatting codes
|
||||
|
@@ -21,7 +21,11 @@ template <typename Mutex>
|
||||
class ringbuffer_sink final : public base_sink<Mutex> {
|
||||
public:
|
||||
explicit ringbuffer_sink(size_t n_items)
|
||||
: q_{n_items} {}
|
||||
: q_{n_items} {
|
||||
if (n_items == 0) {
|
||||
throw_spdlog_ex("ringbuffer_sink: n_items cannot be zero");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<details::log_msg_buffer> last_raw(size_t lim = 0) {
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
|
@@ -31,10 +31,10 @@ public:
|
||||
|
||||
// change the color for the given level
|
||||
void set_color(level::level_enum level, std::uint16_t color);
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) override final;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
|
||||
void log(const details::log_msg &msg) override;
|
||||
void flush() override;
|
||||
void set_pattern(const std::string &pattern) override;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
|
||||
void set_color_mode(color_mode mode);
|
||||
|
||||
protected:
|
||||
|
@@ -49,7 +49,8 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_time_point.cpp
|
||||
test_stopwatch.cpp
|
||||
test_circular_q.cpp
|
||||
test_bin_to_hex.cpp)
|
||||
test_bin_to_hex.cpp
|
||||
test_ringbuffer.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
|
50
tests/test_ringbuffer.cpp
Normal file
50
tests/test_ringbuffer.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/ringbuffer_sink.h"
|
||||
|
||||
TEST_CASE("ringbuffer invalid size", "[ringbuffer]") {
|
||||
REQUIRE_THROWS_AS(spdlog::sinks::ringbuffer_sink_mt(0), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
TEST_CASE("ringbuffer stores formatted messages", "[ringbuffer]") {
|
||||
spdlog::sinks::ringbuffer_sink_st sink(3);
|
||||
sink.set_pattern("%v");
|
||||
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg1"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg2"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg3"});
|
||||
|
||||
auto formatted = sink.last_formatted();
|
||||
REQUIRE(formatted.size() == 3);
|
||||
REQUIRE(formatted[0] == "msg1");
|
||||
REQUIRE(formatted[1] == "msg2");
|
||||
REQUIRE(formatted[2] == "msg3");
|
||||
}
|
||||
|
||||
TEST_CASE("ringbuffer overrun keeps last items", "[ringbuffer]") {
|
||||
spdlog::sinks::ringbuffer_sink_st sink(2);
|
||||
sink.set_pattern("%v");
|
||||
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "first"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "second"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "third"});
|
||||
|
||||
auto formatted = sink.last_formatted();
|
||||
REQUIRE(formatted.size() == 2);
|
||||
REQUIRE(formatted[0] == "second");
|
||||
REQUIRE(formatted[1] == "third");
|
||||
}
|
||||
|
||||
TEST_CASE("ringbuffer retrieval limit", "[ringbuffer]") {
|
||||
spdlog::sinks::ringbuffer_sink_st sink(3);
|
||||
sink.set_pattern("%v");
|
||||
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "A"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "B"});
|
||||
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "C"});
|
||||
|
||||
auto formatted = sink.last_formatted(2);
|
||||
REQUIRE(formatted.size() == 2);
|
||||
REQUIRE(formatted[0] == "B");
|
||||
REQUIRE(formatted[1] == "C");
|
||||
}
|
||||
|
Reference in New Issue
Block a user