Skip to content

Commit 65e152f

Browse files
Merge branch 'gabime:v1.x' into v1.x
2 parents 911b078 + 6fd67ce commit 65e152f

File tree

9 files changed

+77
-92
lines changed

9 files changed

+77
-92
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -75,74 +75,5 @@ jobs:
7575
run: |
7676
build\tests\${{ matrix.config.BUILD_TYPE }}\spdlog-utests.exe
7777
78-
# -----------------------------------------------------------------------
79-
# MSVC 2019 build matrix
80-
# -----------------------------------------------------------------------
81-
build_2019:
82-
runs-on: windows-2019
83-
strategy:
84-
fail-fast: true
85-
matrix:
86-
config:
87-
- GENERATOR: "Visual Studio 16 2019"
88-
BUILD_TYPE: Release
89-
BUILD_SHARED: 'ON'
90-
FATAL_ERRORS: 'ON'
91-
WCHAR: 'OFF'
92-
WCHAR_FILES: 'OFF'
93-
BUILD_EXAMPLE: 'ON'
94-
USE_STD_FORMAT: 'OFF'
95-
CXX_STANDARD: 17
96-
- GENERATOR: "Visual Studio 16 2019"
97-
BUILD_TYPE: Release
98-
BUILD_SHARED: 'ON'
99-
FATAL_ERRORS: 'ON'
100-
WCHAR: 'OFF'
101-
WCHAR_FILES: 'OFF'
102-
BUILD_EXAMPLE: 'ON'
103-
USE_STD_FORMAT: 'OFF'
104-
CXX_STANDARD: 14
105-
- GENERATOR: "Visual Studio 16 2019"
106-
BUILD_TYPE: Release
107-
BUILD_SHARED: 'ON'
108-
FATAL_ERRORS: 'ON'
109-
WCHAR: 'OFF'
110-
WCHAR_FILES: 'OFF'
111-
BUILD_EXAMPLE: 'ON'
112-
USE_STD_FORMAT: 'OFF'
113-
CXX_STANDARD: 11
114-
115-
steps:
116-
- name: Checkout code
117-
uses: actions/checkout@v4
11878
119-
- name: CMake ${{ matrix.config.GENERATOR }} CXX=${{matrix.config.CXX_STANDARD}} WCHAR=${{matrix.config.WCHAR_FILES}} STD_FORMAT=${{matrix.config.USE_STD_FORMAT}}
120-
shell: pwsh
121-
run: |
122-
mkdir build
123-
cd build
124-
cmake -G "${{ matrix.config.GENERATOR }}" -A x64 `
125-
-D CMAKE_BUILD_TYPE=${{ matrix.config.BUILD_TYPE }} `
126-
-D BUILD_SHARED_LIBS=${{ matrix.config.BUILD_SHARED }} `
127-
-D SPDLOG_WCHAR_SUPPORT=${{ matrix.config.WCHAR }} `
128-
-D SPDLOG_WCHAR_FILENAMES=${{ matrix.config.WCHAR_FILES }} `
129-
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
130-
-D SPDLOG_BUILD_EXAMPLE_HO=${{ matrix.config.BUILD_EXAMPLE }} `
131-
-D SPDLOG_BUILD_TESTS=ON `
132-
-D SPDLOG_BUILD_TESTS_HO=OFF `
133-
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
134-
-D SPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} `
135-
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
136-
137-
- name: Build
138-
shell: pwsh
139-
run: |
140-
cd build
141-
cmake --build . --parallel --config ${{ matrix.config.BUILD_TYPE }}
142-
143-
- name: Run Tests
144-
shell: pwsh
145-
env:
146-
PATH: ${{ env.PATH }};${{ github.workspace }}\build\_deps\catch2-build\src\${{ matrix.config.BUILD_TYPE }};${{ github.workspace }}\build\${{ matrix.config.BUILD_TYPE }}
147-
run: |
148-
build\tests\${{ matrix.config.BUILD_TYPE }}\spdlog-utests.exe
79+

include/spdlog/cfg/helpers-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
7171
}
7272

7373
SPDLOG_INLINE void load_levels(const std::string &input) {
74-
if (input.empty() || input.size() > 512) {
74+
if (input.empty() || input.size() >= 32768) {
7575
return;
7676
}
7777

include/spdlog/details/os-inl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,21 +563,21 @@ SPDLOG_INLINE filename_t dir_name(const filename_t &path) {
563563
return pos != filename_t::npos ? path.substr(0, pos) : filename_t{};
564564
}
565565

566+
#ifdef _MSC_VER
567+
#pragma warning(push)
568+
#pragma warning(disable : 4996)
569+
#endif // _MSC_VER
566570
std::string SPDLOG_INLINE getenv(const char *field) {
567-
#if defined(_MSC_VER)
568-
#if defined(__cplusplus_winrt)
571+
#if defined(_MSC_VER) && defined(__cplusplus_winrt)
569572
return std::string{}; // not supported under uwp
570-
#else
571-
size_t len = 0;
572-
char buf[128];
573-
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
574-
return ok ? buf : std::string{};
575-
#endif
576-
#else // revert to getenv
577-
char *buf = ::getenv(field);
573+
#else
574+
char *buf = std::getenv(field);
578575
return buf ? buf : std::string{};
579576
#endif
580577
}
578+
#ifdef _MSC_VER
579+
#pragma warning(pop)
580+
#endif // _MSC_VER
581581

582582
// Do fsync by FILE handlerpointer
583583
// Return true on success

include/spdlog/fmt/fmt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
#ifndef FMT_USE_WINDOWS_H
2121
#define FMT_USE_WINDOWS_H 0
2222
#endif
23-
24-
#include <spdlog/fmt/bundled/base.h>
2523
#include <spdlog/fmt/bundled/format.h>
26-
2724
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
28-
#include <fmt/base.h>
2925
#include <fmt/format.h>
3026
#endif

include/spdlog/sinks/ansicolor_sink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ansicolor_sink : public sink {
4040

4141
void log(const details::log_msg &msg) override;
4242
void flush() override;
43-
void set_pattern(const std::string &pattern) final override;
43+
void set_pattern(const std::string &pattern) override;
4444
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
4545

4646
// Formatting codes

include/spdlog/sinks/ringbuffer_sink.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ template <typename Mutex>
2121
class ringbuffer_sink final : public base_sink<Mutex> {
2222
public:
2323
explicit ringbuffer_sink(size_t n_items)
24-
: q_{n_items} {}
24+
: q_{n_items} {
25+
if (n_items == 0) {
26+
throw_spdlog_ex("ringbuffer_sink: n_items cannot be zero");
27+
}
28+
}
2529

2630
std::vector<details::log_msg_buffer> last_raw(size_t lim = 0) {
2731
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);

include/spdlog/sinks/wincolor_sink.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class wincolor_sink : public sink {
3131

3232
// change the color for the given level
3333
void set_color(level::level_enum level, std::uint16_t color);
34-
void log(const details::log_msg &msg) final override;
35-
void flush() final override;
36-
void set_pattern(const std::string &pattern) override final;
37-
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
34+
void log(const details::log_msg &msg) override;
35+
void flush() override;
36+
void set_pattern(const std::string &pattern) override;
37+
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override;
3838
void set_color_mode(color_mode mode);
3939

4040
protected:

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ set(SPDLOG_UTESTS_SOURCES
4949
test_time_point.cpp
5050
test_stopwatch.cpp
5151
test_circular_q.cpp
52-
test_bin_to_hex.cpp)
52+
test_bin_to_hex.cpp
53+
test_ringbuffer.cpp)
5354

5455
if(NOT SPDLOG_NO_EXCEPTIONS)
5556
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)

tests/test_ringbuffer.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "includes.h"
2+
#include "spdlog/sinks/ringbuffer_sink.h"
3+
4+
TEST_CASE("ringbuffer invalid size", "[ringbuffer]") {
5+
REQUIRE_THROWS_AS(spdlog::sinks::ringbuffer_sink_mt(0), spdlog::spdlog_ex);
6+
}
7+
8+
TEST_CASE("ringbuffer stores formatted messages", "[ringbuffer]") {
9+
spdlog::sinks::ringbuffer_sink_st sink(3);
10+
sink.set_pattern("%v");
11+
12+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg1"});
13+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg2"});
14+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "msg3"});
15+
16+
auto formatted = sink.last_formatted();
17+
REQUIRE(formatted.size() == 3);
18+
using spdlog::details::os::default_eol;
19+
REQUIRE(formatted[0] == spdlog::fmt_lib::format("msg1{}", default_eol));
20+
REQUIRE(formatted[1] == spdlog::fmt_lib::format("msg2{}", default_eol));
21+
REQUIRE(formatted[2] == spdlog::fmt_lib::format("msg3{}", default_eol));
22+
}
23+
24+
TEST_CASE("ringbuffer overrun keeps last items", "[ringbuffer]") {
25+
spdlog::sinks::ringbuffer_sink_st sink(2);
26+
sink.set_pattern("%v");
27+
28+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "first"});
29+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "second"});
30+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "third"});
31+
32+
auto formatted = sink.last_formatted();
33+
REQUIRE(formatted.size() == 2);
34+
using spdlog::details::os::default_eol;
35+
REQUIRE(formatted[0] == spdlog::fmt_lib::format("second{}", default_eol));
36+
REQUIRE(formatted[1] == spdlog::fmt_lib::format("third{}", default_eol));
37+
}
38+
39+
TEST_CASE("ringbuffer retrieval limit", "[ringbuffer]") {
40+
spdlog::sinks::ringbuffer_sink_st sink(3);
41+
sink.set_pattern("%v");
42+
43+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "A"});
44+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "B"});
45+
sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "C"});
46+
47+
auto formatted = sink.last_formatted(2);
48+
REQUIRE(formatted.size() == 2);
49+
using spdlog::details::os::default_eol;
50+
REQUIRE(formatted[0] == spdlog::fmt_lib::format("B{}", default_eol));
51+
REQUIRE(formatted[1] == spdlog::fmt_lib::format("C{}", default_eol));
52+
}
53+

0 commit comments

Comments
 (0)