Compare commits

..

13 Commits

Author SHA1 Message Date
gabime
1d418eef5a Fix coverity yml 2025-05-12 12:15:44 +03:00
gabime
4a4acc31e6 Fix coverity yml 2025-05-12 12:14:24 +03:00
gabime
7c155b99c1 Fix coverity yml 2025-05-12 11:43:31 +03:00
gabime
e1d4ed9cef Fix coverity yml 2025-05-12 11:37:53 +03:00
gabime
9926fd8ff8 Added coverity to ci 2025-05-12 11:13:49 +03:00
gabime
6c174aa5b7 Wrap main content in try block for exception safety. 2025-05-12 10:36:31 +03:00
gabime
a9e09baeec Use std::move in example 2025-05-12 10:33:10 +03:00
gabime
13fbf73a70 Use std::move for old_logger in set_default_logger. 2025-05-12 10:31:01 +03:00
gabime
2d761504a3 Fix typo in comment for set_default_logger method. 2025-05-12 10:30:48 +03:00
gabime
f9bf4511bf Fix comments and remove unused include from helpers-inl.h 2025-05-12 10:27:48 +03:00
gabime
37e24d6970 Remove unused includes from file_helper-inl.h 2025-05-12 10:19:26 +03:00
gabime
de127876c7 Added const qualifiers to logger.h 2025-05-12 10:17:11 +03:00
gabime
b0620c8523 Move callback function in thread_pool ctor 2025-05-12 10:09:05 +03:00
10 changed files with 26 additions and 79 deletions

View File

@@ -1,6 +1,6 @@
name: coverity-linux
on: [push, pull_request]
on: [pull_request]
permissions:
contents: read
@@ -35,7 +35,6 @@ 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 }}" \

View File

@@ -524,7 +524,6 @@ Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki)
---
### Powered by
<a href="https://jb.gg/OpenSource">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg" alt="JetBrains logo" width="200">
</a>
Thanks to [JetBrains](https://www.jetbrains.com/?from=spdlog) for donating product licenses to help develop **spdlog** <a href="https://www.jetbrains.com/?from=spdlog"><img src="logos/jetbrains-variant-4.svg" width="94" align="center" /></a>

View File

@@ -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() >= 32768) {
if (input.empty() || input.size() > 512) {
return;
}

View File

@@ -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) && defined(__cplusplus_winrt)
#if defined(_MSC_VER)
#if defined(__cplusplus_winrt)
return std::string{}; // not supported under uwp
#else
char *buf = std::getenv(field);
#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);
return buf ? buf : std::string{};
#endif
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
// Do fsync by FILE handlerpointer
// Return true on success

View File

@@ -20,7 +20,11 @@
#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

View File

@@ -40,7 +40,7 @@ public:
void log(const details::log_msg &msg) override;
void flush() override;
void set_pattern(const std::string &pattern) override;
void set_pattern(const std::string &pattern) final override;
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
// Formatting codes

View File

@@ -21,11 +21,7 @@ template <typename Mutex>
class ringbuffer_sink final : public base_sink<Mutex> {
public:
explicit ringbuffer_sink(size_t n_items)
: q_{n_items} {
if (n_items == 0) {
throw_spdlog_ex("ringbuffer_sink: n_items cannot be zero");
}
}
: q_{n_items} {}
std::vector<details::log_msg_buffer> last_raw(size_t lim = 0) {
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);

View File

@@ -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) override;
void flush() override;
void set_pattern(const std::string &pattern) override;
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
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 set_color_mode(color_mode mode);
protected:

View File

@@ -49,8 +49,7 @@ set(SPDLOG_UTESTS_SOURCES
test_time_point.cpp
test_stopwatch.cpp
test_circular_q.cpp
test_bin_to_hex.cpp
test_ringbuffer.cpp)
test_bin_to_hex.cpp)
if(NOT SPDLOG_NO_EXCEPTIONS)
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)

View File

@@ -1,50 +0,0 @@
#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");
}