Skip to content

Commit bf64ae1

Browse files
committed
Merge pull request #11 from ko4life-net/fix-spdlog-compile-errors
Fix spdlog compile errors
2 parents 273c04f + a2c12c1 commit bf64ae1

File tree

112 files changed

+3738
-18898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3738
-18898
lines changed

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

spdlog/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
Static archives compiled with the following commands:
44
```bat
5-
git clone https://github.com/gabime/spdlog.git --branch=1.10.0
5+
git clone https://github.com/gabime/spdlog.git --branch=v1.13.0
66
cd spdlog
7-
mkdir _build
8-
cd _build
9-
cmake .. -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX=pkg
7+
mkdir _build && cd _build
8+
9+
cmake .. -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX=pkg -DSPDLOG_USE_STD_FORMAT=ON -DSPDLOG_BUILD_EXAMPLE=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
1010
cmake --build . --config Debug --target install
1111
cmake --build . --config Release --target install
1212
```
1313

14-
Note that I had to modify CMake code after add_library call to add this:
15-
```cmake
16-
set_property(TARGET spdlog PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
17-
```
14+
Note that with the existing spdlog cmake project files, setting `MSVC_RUNTIME_LIBRARY` is completely ignored unless we tell `CMP0091` cmake policy to use the new behavior. Read more here: https://discourse.cmake.org/t/msvc-runtime-library-completely-ignored/10004
15+
16+
Also note that using turning `SPDLOG_USE_STD_FORMAT` to `ON` requires C++20, which the ko codebase uses.

spdlog/include/spdlog/async.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include <spdlog/details/registry.h>
1919
#include <spdlog/details/thread_pool.h>
2020

21+
#include <functional>
2122
#include <memory>
2223
#include <mutex>
23-
#include <functional>
2424

2525
namespace spdlog {
2626

@@ -31,27 +31,25 @@ static const size_t default_async_q_size = 8192;
3131
// async logger factory - creates async loggers backed with thread pool.
3232
// if a global thread pool doesn't already exist, create it with default queue
3333
// size of 8192 items and single thread.
34-
template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
35-
struct async_factory_impl
36-
{
37-
template<typename Sink, typename... SinkArgs>
38-
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&... args)
39-
{
34+
template <async_overflow_policy OverflowPolicy = async_overflow_policy::block>
35+
struct async_factory_impl {
36+
template <typename Sink, typename... SinkArgs>
37+
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&...args) {
4038
auto &registry_inst = details::registry::instance();
4139

4240
// create global thread pool if not already exists..
4341

4442
auto &mutex = registry_inst.tp_mutex();
4543
std::lock_guard<std::recursive_mutex> tp_lock(mutex);
4644
auto tp = registry_inst.get_tp();
47-
if (tp == nullptr)
48-
{
45+
if (tp == nullptr) {
4946
tp = std::make_shared<details::thread_pool>(details::default_async_q_size, 1U);
5047
registry_inst.set_tp(tp);
5148
}
5249

5350
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
54-
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
51+
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink),
52+
std::move(tp), OverflowPolicy);
5553
registry_inst.initialize_logger(new_logger);
5654
return new_logger;
5755
}
@@ -60,40 +58,43 @@ struct async_factory_impl
6058
using async_factory = async_factory_impl<async_overflow_policy::block>;
6159
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
6260

63-
template<typename Sink, typename... SinkArgs>
64-
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&... sink_args)
65-
{
66-
return async_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
61+
template <typename Sink, typename... SinkArgs>
62+
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name,
63+
SinkArgs &&...sink_args) {
64+
return async_factory::create<Sink>(std::move(logger_name),
65+
std::forward<SinkArgs>(sink_args)...);
6766
}
6867

69-
template<typename Sink, typename... SinkArgs>
70-
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&... sink_args)
71-
{
72-
return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
68+
template <typename Sink, typename... SinkArgs>
69+
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name,
70+
SinkArgs &&...sink_args) {
71+
return async_factory_nonblock::create<Sink>(std::move(logger_name),
72+
std::forward<SinkArgs>(sink_args)...);
7373
}
7474

7575
// set global thread pool.
76-
inline void init_thread_pool(
77-
size_t q_size, size_t thread_count, std::function<void()> on_thread_start, std::function<void()> on_thread_stop)
78-
{
79-
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start, on_thread_stop);
76+
inline void init_thread_pool(size_t q_size,
77+
size_t thread_count,
78+
std::function<void()> on_thread_start,
79+
std::function<void()> on_thread_stop) {
80+
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start,
81+
on_thread_stop);
8082
details::registry::instance().set_tp(std::move(tp));
8183
}
8284

83-
inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start)
84-
{
85+
inline void init_thread_pool(size_t q_size,
86+
size_t thread_count,
87+
std::function<void()> on_thread_start) {
8588
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
8689
}
8790

88-
inline void init_thread_pool(size_t q_size, size_t thread_count)
89-
{
91+
inline void init_thread_pool(size_t q_size, size_t thread_count) {
9092
init_thread_pool(
9193
q_size, thread_count, [] {}, [] {});
9294
}
9395

9496
// get the global thread pool.
95-
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool()
96-
{
97+
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() {
9798
return details::registry::instance().get_tp();
9899
}
99-
} // namespace spdlog
100+
} // namespace spdlog

spdlog/include/spdlog/async_logger-inl.h

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,80 @@
44
#pragma once
55

66
#ifndef SPDLOG_HEADER_ONLY
7-
# include <spdlog/async_logger.h>
7+
#include <spdlog/async_logger.h>
88
#endif
99

10-
#include <spdlog/sinks/sink.h>
1110
#include <spdlog/details/thread_pool.h>
11+
#include <spdlog/sinks/sink.h>
1212

1313
#include <memory>
1414
#include <string>
1515

16-
SPDLOG_INLINE spdlog::async_logger::async_logger(
17-
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
18-
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
19-
{}
16+
SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name,
17+
sinks_init_list sinks_list,
18+
std::weak_ptr<details::thread_pool> tp,
19+
async_overflow_policy overflow_policy)
20+
: async_logger(std::move(logger_name),
21+
sinks_list.begin(),
22+
sinks_list.end(),
23+
std::move(tp),
24+
overflow_policy) {}
2025

21-
SPDLOG_INLINE spdlog::async_logger::async_logger(
22-
std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
23-
: async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
24-
{}
26+
SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name,
27+
sink_ptr single_sink,
28+
std::weak_ptr<details::thread_pool> tp,
29+
async_overflow_policy overflow_policy)
30+
: async_logger(
31+
std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {}
2532

2633
// send the log message to the thread pool
27-
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
28-
{
29-
if (auto pool_ptr = thread_pool_.lock())
30-
{
34+
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){
35+
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
3136
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
32-
}
33-
else
34-
{
35-
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
36-
}
37+
}
38+
else {
39+
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
40+
}
41+
}
42+
SPDLOG_LOGGER_CATCH(msg.source)
3743
}
3844

3945
// send flush request to the thread pool
40-
SPDLOG_INLINE void spdlog::async_logger::flush_()
41-
{
42-
if (auto pool_ptr = thread_pool_.lock())
43-
{
46+
SPDLOG_INLINE void spdlog::async_logger::flush_(){
47+
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
4448
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
45-
}
46-
else
47-
{
48-
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
49-
}
49+
}
50+
else {
51+
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
52+
}
53+
}
54+
SPDLOG_LOGGER_CATCH(source_loc())
5055
}
5156

5257
//
5358
// backend functions - called from the thread pool to do the actual job
5459
//
55-
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg)
56-
{
57-
for (auto &sink : sinks_)
58-
{
59-
if (sink->should_log(msg.level))
60-
{
61-
SPDLOG_TRY
62-
{
63-
sink->log(msg);
64-
}
60+
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) {
61+
for (auto &sink : sinks_) {
62+
if (sink->should_log(msg.level)) {
63+
SPDLOG_TRY { sink->log(msg); }
6564
SPDLOG_LOGGER_CATCH(msg.source)
6665
}
6766
}
6867

69-
if (should_flush_(msg))
70-
{
68+
if (should_flush_(msg)) {
7169
backend_flush_();
7270
}
7371
}
7472

75-
SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
76-
{
77-
for (auto &sink : sinks_)
78-
{
79-
SPDLOG_TRY
80-
{
81-
sink->flush();
82-
}
73+
SPDLOG_INLINE void spdlog::async_logger::backend_flush_() {
74+
for (auto &sink : sinks_) {
75+
SPDLOG_TRY { sink->flush(); }
8376
SPDLOG_LOGGER_CATCH(source_loc())
8477
}
8578
}
8679

87-
SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
88-
{
80+
SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name) {
8981
auto cloned = std::make_shared<spdlog::async_logger>(*this);
9082
cloned->name_ = std::move(new_name);
9183
return cloned;

spdlog/include/spdlog/async_logger.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,41 @@
1919
namespace spdlog {
2020

2121
// Async overflow policy - block by default.
22-
enum class async_overflow_policy
23-
{
24-
block, // Block until message can be enqueued
25-
overrun_oldest // Discard oldest message in the queue if full when trying to
26-
// add new item.
22+
enum class async_overflow_policy {
23+
block, // Block until message can be enqueued
24+
overrun_oldest, // Discard oldest message in the queue if full when trying to
25+
// add new item.
26+
discard_new // Discard new message if the queue is full when trying to add new item.
2727
};
2828

2929
namespace details {
3030
class thread_pool;
3131
}
3232

33-
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>, public logger
34-
{
33+
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
34+
public logger {
3535
friend class details::thread_pool;
3636

3737
public:
38-
template<typename It>
39-
async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp,
40-
async_overflow_policy overflow_policy = async_overflow_policy::block)
41-
: logger(std::move(logger_name), begin, end)
42-
, thread_pool_(std::move(tp))
43-
, overflow_policy_(overflow_policy)
44-
{}
38+
template <typename It>
39+
async_logger(std::string logger_name,
40+
It begin,
41+
It end,
42+
std::weak_ptr<details::thread_pool> tp,
43+
async_overflow_policy overflow_policy = async_overflow_policy::block)
44+
: logger(std::move(logger_name), begin, end),
45+
thread_pool_(std::move(tp)),
46+
overflow_policy_(overflow_policy) {}
4547

46-
async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
47-
async_overflow_policy overflow_policy = async_overflow_policy::block);
48+
async_logger(std::string logger_name,
49+
sinks_init_list sinks_list,
50+
std::weak_ptr<details::thread_pool> tp,
51+
async_overflow_policy overflow_policy = async_overflow_policy::block);
4852

49-
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
50-
async_overflow_policy overflow_policy = async_overflow_policy::block);
53+
async_logger(std::string logger_name,
54+
sink_ptr single_sink,
55+
std::weak_ptr<details::thread_pool> tp,
56+
async_overflow_policy overflow_policy = async_overflow_policy::block);
5157

5258
std::shared_ptr<logger> clone(std::string new_name) override;
5359

@@ -61,8 +67,8 @@ class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_
6167
std::weak_ptr<details::thread_pool> thread_pool_;
6268
async_overflow_policy overflow_policy_;
6369
};
64-
} // namespace spdlog
70+
} // namespace spdlog
6571

6672
#ifdef SPDLOG_HEADER_ONLY
67-
# include "async_logger-inl.h"
73+
#include "async_logger-inl.h"
6874
#endif

spdlog/include/spdlog/cfg/argv.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,20 @@ namespace spdlog {
2121
namespace cfg {
2222

2323
// search for SPDLOG_LEVEL= in the args and use it to init the levels
24-
inline void load_argv_levels(int argc, const char **argv)
25-
{
24+
inline void load_argv_levels(int argc, const char **argv) {
2625
const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
27-
for (int i = 1; i < argc; i++)
28-
{
26+
for (int i = 1; i < argc; i++) {
2927
std::string arg = argv[i];
30-
if (arg.find(spdlog_level_prefix) == 0)
31-
{
28+
if (arg.find(spdlog_level_prefix) == 0) {
3229
auto levels_string = arg.substr(spdlog_level_prefix.size());
3330
helpers::load_levels(levels_string);
3431
}
3532
}
3633
}
3734

38-
inline void load_argv_levels(int argc, char **argv)
39-
{
35+
inline void load_argv_levels(int argc, char **argv) {
4036
load_argv_levels(argc, const_cast<const char **>(argv));
4137
}
4238

43-
} // namespace cfg
44-
} // namespace spdlog
39+
} // namespace cfg
40+
} // namespace spdlog

spdlog/include/spdlog/cfg/env.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#pragma once
55
#include <spdlog/cfg/helpers.h>
6-
#include <spdlog/details/registry.h>
76
#include <spdlog/details/os.h>
7+
#include <spdlog/details/registry.h>
88

99
//
1010
// Init levels and patterns from env variables SPDLOG_LEVEL
@@ -25,14 +25,12 @@
2525

2626
namespace spdlog {
2727
namespace cfg {
28-
inline void load_env_levels()
29-
{
28+
inline void load_env_levels() {
3029
auto env_val = details::os::getenv("SPDLOG_LEVEL");
31-
if (!env_val.empty())
32-
{
30+
if (!env_val.empty()) {
3331
helpers::load_levels(env_val);
3432
}
3533
}
3634

37-
} // namespace cfg
38-
} // namespace spdlog
35+
} // namespace cfg
36+
} // namespace spdlog

0 commit comments

Comments
 (0)