Skip to content

Commit f3b71f0

Browse files
committed
Update to spdlog 1.3.1
1 parent e927a00 commit f3b71f0

69 files changed

Lines changed: 12792 additions & 9337 deletions

Some content is hidden

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

src/cpp-utils/logging/Logger.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
#ifndef MESSMER_CPPUTILS_LOGGING_LOGGER_H
33
#define MESSMER_CPPUTILS_LOGGING_LOGGER_H
44

5-
#if !defined(_MSC_VER)
6-
#define SPDLOG_ENABLE_SYSLOG
7-
#endif
8-
95
#include <spdlog/spdlog.h>
106
#include "../macros.h"
117

8+
#include <spdlog/sinks/stdout_sinks.h>
9+
1210
namespace cpputils {
1311
namespace logging {
1412
class Logger final {

src/cpp-utils/logging/logging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
#include "Logger.h"
66
#include <stdexcept>
77
#include <spdlog/fmt/ostr.h>
8+
#include <spdlog/sinks/basic_file_sink.h>
89

910
#if defined(_MSC_VER)
1011
#include <spdlog/sinks/msvc_sink.h>
12+
#else
13+
#include <spdlog/sinks/syslog_sink.h>
1114
#endif
1215

1316
namespace cpputils {
@@ -75,7 +78,7 @@ namespace cpputils {
7578
#if defined(_MSC_VER)
7679
return spdlog::create<spdlog::sinks::msvc_sink_mt>(name);
7780
#else
78-
return spdlog::syslog_logger(name, name, LOG_PID);
81+
return spdlog::syslog_logger_mt(name, name, LOG_PID);
7982
#endif
8083
}
8184
}

src/cryfs-cli/Cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ namespace cryfs_cli {
315315
//TODO Test that --logfile parameter works. Should be: file if specified, otherwise stderr if foreground, else syslog.
316316
if (options.logFile() != none) {
317317
cpputils::logging::setLogger(
318-
spdlog::create<spdlog::sinks::simple_file_sink<std::mutex>>("cryfs", options.logFile()->string()));
318+
spdlog::create<spdlog::sinks::basic_file_sink_mt>("cryfs", options.logFile()->string()));
319319
} else if (options.foreground()) {
320320
cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs"));
321321
} else {

src/fspp/fstest/FsppDirTest_Timestamps.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ TYPED_TEST_P(FsppDirTest_Timestamps, createAndOpenFile_inRootDir) {
2929

3030
TYPED_TEST_P(FsppDirTest_Timestamps, createAndOpenFile_TimestampsOfCreatedFile) {
3131
auto dir = this->CreateDir("/mydir");
32-
timespec lowerBound = now();
32+
timespec lowerBound = cpputils::time::now();
3333
dir->createAndOpenFile("childname", fspp::mode_t().addFileFlag(), fspp::uid_t(1000), fspp::gid_t(1000));
34-
timespec upperBound = now();
34+
timespec upperBound = cpputils::time::now();
3535
auto child = this->Load("/mydir/childname");
3636
this->EXPECT_ACCESS_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);
3737
this->EXPECT_MODIFICATION_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);
@@ -57,9 +57,9 @@ TYPED_TEST_P(FsppDirTest_Timestamps, createDir_inRootDir) {
5757

5858
TYPED_TEST_P(FsppDirTest_Timestamps, createDir_TimestampsOfCreatedDir) {
5959
auto dir = this->CreateDir("/mydir");
60-
timespec lowerBound = now();
60+
timespec lowerBound = cpputils::time::now();
6161
dir->createDir("childname", fspp::mode_t().addDirFlag(), fspp::uid_t(1000), fspp::gid_t(1000));
62-
timespec upperBound = now();
62+
timespec upperBound = cpputils::time::now();
6363
auto child = this->Load("/mydir/childname");
6464
this->EXPECT_ACCESS_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);
6565
this->EXPECT_MODIFICATION_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);
@@ -85,9 +85,9 @@ TYPED_TEST_P(FsppDirTest_Timestamps, createSymlink_inRootDir) {
8585

8686
TYPED_TEST_P(FsppDirTest_Timestamps, createSymlink_TimestampsOfCreatedSymlink) {
8787
auto dir = this->CreateDir("/mydir");
88-
timespec lowerBound = now();
88+
timespec lowerBound = cpputils::time::now();
8989
dir->createSymlink("childname", "/target", fspp::uid_t(1000), fspp::gid_t(1000));
90-
timespec upperBound = now();
90+
timespec upperBound = cpputils::time::now();
9191
auto child = this->Load("/mydir/childname");
9292
this->EXPECT_ACCESS_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);
9393
this->EXPECT_MODIFICATION_TIMESTAMP_BETWEEN (lowerBound, upperBound, *child);

src/fspp/fstest/FsppNodeTest_Timestamps.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
#include "testutils/TimestampTestUtils.h"
88
#include <cpp-utils/system/stat.h>
99

10-
using namespace cpputils::time;
11-
using std::function;
1210

1311
template<class ConcreteFileSystemTestFixture>
1412
class FsppNodeTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<ConcreteFileSystemTestFixture> {
1513
public:
1614

1715
void Test_Create() {
18-
timespec lowerBound = now();
16+
timespec lowerBound = cpputils::time::now();
1917
auto node = this->CreateNode("/mynode");
20-
timespec upperBound = now();
18+
timespec upperBound = cpputils::time::now();
2119
this->EXPECT_ACCESS_TIMESTAMP_BETWEEN (lowerBound, upperBound, *node);
2220
this->EXPECT_MODIFICATION_TIMESTAMP_BETWEEN (lowerBound, upperBound, *node);
2321
this->EXPECT_METADATACHANGE_TIMESTAMP_BETWEEN(lowerBound, upperBound, *node);

src/stats/main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919

2020
#include <set>
2121

22-
using namespace boost;
23-
using namespace boost::filesystem;
24-
using namespace std;
22+
using std::endl;
23+
using std::cout;
24+
using std::set;
25+
using std::flush;
26+
using std::vector;
27+
using boost::none;
28+
using boost::filesystem::path;
29+
2530
using namespace cryfs;
2631
using namespace cpputils;
2732
using namespace blockstore;

test/cpp-utils/logging/testutils/LoggingTest.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class MockLogger final {
1111
public:
1212
MockLogger():
1313
_capturedLogData(),
14-
_sink(std::make_shared<spdlog::sinks::ostream_sink<std::mutex>>(_capturedLogData, true)),
15-
_logger(spdlog::create("MockLogger", {_sink})) {
14+
_logger(spdlog::create<spdlog::sinks::ostream_sink_mt>("MockLogger", _capturedLogData, true)) {
1615
}
1716

1817
~MockLogger() {
@@ -28,7 +27,6 @@ class MockLogger final {
2827
}
2928
private:
3029
std::ostringstream _capturedLogData;
31-
std::shared_ptr<spdlog::sinks::ostream_sink<std::mutex>> _sink;
3230
std::shared_ptr<spdlog::logger> _logger;
3331
};
3432

vendor/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This directory contains external projects, taken from the following locations:
22
googletest: https://github.com/google/googletest/tree/release-1.8.1
3-
spdlog: https://github.com/gabime/spdlog/tree/v0.16.3/include/spdlog
3+
spdlog: https://github.com/gabime/spdlog/tree/v1.3.1/include/spdlog
44
cryptopp: https://github.com/weidai11/cryptopp/tree/CRYPTOPP_8_1_0
55
- changed: added CMakeLists.txt and cryptopp-config.cmake from https://github.com/noloader/cryptopp-cmake/tree/07a064d57d97477cb055f994a498f45425df0c1d
66
- changed: commented out line including winapifamily.h in CMakeLists.txt

vendor/spdlog/spdlog/async.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
//
3+
// Copyright(c) 2018 Gabi Melman.
4+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
5+
//
6+
7+
#pragma once
8+
9+
//
10+
// Async logging using global thread pool
11+
// All loggers created here share same global thread pool.
12+
// Each log message is pushed to a queue along withe a shared pointer to the
13+
// logger.
14+
// If a logger deleted while having pending messages in the queue, it's actual
15+
// destruction will defer
16+
// until all its messages are processed by the thread pool.
17+
// This is because each message in the queue holds a shared_ptr to the
18+
// originating logger.
19+
20+
#include "spdlog/async_logger.h"
21+
#include "spdlog/details/registry.h"
22+
#include "spdlog/details/thread_pool.h"
23+
24+
#include <memory>
25+
#include <mutex>
26+
27+
namespace spdlog {
28+
29+
namespace details {
30+
static const size_t default_async_q_size = 8192;
31+
}
32+
33+
// async logger factory - creates async loggers backed with thread pool.
34+
// if a global thread pool doesn't already exist, create it with default queue
35+
// size of 8192 items and single thread.
36+
template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
37+
struct async_factory_impl
38+
{
39+
template<typename Sink, typename... SinkArgs>
40+
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&... args)
41+
{
42+
auto &registry_inst = details::registry::instance();
43+
44+
// create global thread pool if not already exists..
45+
std::lock_guard<std::recursive_mutex> tp_lock(registry_inst.tp_mutex());
46+
auto tp = registry_inst.get_tp();
47+
if (tp == nullptr)
48+
{
49+
tp = std::make_shared<details::thread_pool>(details::default_async_q_size, 1);
50+
registry_inst.set_tp(tp);
51+
}
52+
53+
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);
55+
registry_inst.initialize_logger(new_logger);
56+
return new_logger;
57+
}
58+
};
59+
60+
using async_factory = async_factory_impl<async_overflow_policy::block>;
61+
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
62+
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)...);
67+
}
68+
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)...);
73+
}
74+
75+
// set global thread pool.
76+
inline void init_thread_pool(size_t q_size, size_t thread_count)
77+
{
78+
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count);
79+
details::registry::instance().set_tp(std::move(tp));
80+
}
81+
82+
// get the global thread pool.
83+
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool()
84+
{
85+
return details::registry::instance().get_tp();
86+
}
87+
} // namespace spdlog

vendor/spdlog/spdlog/async_logger.h

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,69 @@
55

66
#pragma once
77

8-
// Very fast asynchronous logger (millions of logs per second on an average desktop)
9-
// Uses pre allocated lockfree queue for maximum throughput even under large number of threads.
8+
// Very fast asynchronous logger (millions of logs per second on an average
9+
// desktop)
10+
// Uses pre allocated lockfree queue for maximum throughput even under large
11+
// number of threads.
1012
// Creates a single back thread to pop messages from the queue and log them.
1113
//
1214
// Upon each log write the logger:
1315
// 1. Checks if its log level is enough to log the message
14-
// 2. Push a new copy of the message to a queue (or block the caller until space is available in the queue)
16+
// 2. Push a new copy of the message to a queue (or block the caller until
17+
// space is available in the queue)
1518
// 3. will throw spdlog_ex upon log exceptions
16-
// Upon destruction, logs all remaining messages in the queue before destructing..
19+
// Upon destruction, logs all remaining messages in the queue before
20+
// destructing..
1721

18-
#include "common.h"
19-
#include "logger.h"
22+
#include "spdlog/common.h"
23+
#include "spdlog/logger.h"
2024

2125
#include <chrono>
22-
#include <functional>
23-
#include <string>
2426
#include <memory>
27+
#include <string>
2528

26-
namespace spdlog
27-
{
29+
namespace spdlog {
2830

29-
namespace details
31+
// Async overflow policy - block by default.
32+
enum class async_overflow_policy
3033
{
31-
class async_log_helper;
34+
block, // Block until message can be enqueued
35+
overrun_oldest // Discard oldest message in the queue if full when trying to
36+
// add new item.
37+
};
38+
39+
namespace details {
40+
class thread_pool;
3241
}
3342

34-
class async_logger SPDLOG_FINAL :public logger
43+
class async_logger final : public std::enable_shared_from_this<async_logger>, public logger
3544
{
45+
friend class details::thread_pool;
46+
3647
public:
37-
template<class It>
38-
async_logger(const std::string& name,
39-
const It& begin,
40-
const It& end,
41-
size_t queue_size,
42-
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
43-
const std::function<void()>& worker_warmup_cb = nullptr,
44-
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
45-
const std::function<void()>& worker_teardown_cb = nullptr);
46-
47-
async_logger(const std::string& logger_name,
48-
sinks_init_list sinks,
49-
size_t queue_size,
50-
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
51-
const std::function<void()>& worker_warmup_cb = nullptr,
52-
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
53-
const std::function<void()>& worker_teardown_cb = nullptr);
54-
55-
async_logger(const std::string& logger_name,
56-
sink_ptr single_sink,
57-
size_t queue_size,
58-
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
59-
const std::function<void()>& worker_warmup_cb = nullptr,
60-
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
61-
const std::function<void()>& worker_teardown_cb = nullptr);
62-
63-
//Wait for the queue to be empty, and flush synchronously
64-
//Warning: this can potentially last forever as we wait it to complete
65-
void flush() override;
66-
67-
// Error handler
68-
virtual void set_error_handler(log_err_handler) override;
69-
virtual log_err_handler error_handler() override;
48+
template<typename It>
49+
async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp,
50+
async_overflow_policy overflow_policy = async_overflow_policy::block);
51+
52+
async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
53+
async_overflow_policy overflow_policy = async_overflow_policy::block);
54+
55+
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
56+
async_overflow_policy overflow_policy = async_overflow_policy::block);
57+
58+
std::shared_ptr<logger> clone(std::string new_name) override;
7059

7160
protected:
72-
void _sink_it(details::log_msg& msg) override;
73-
void _set_formatter(spdlog::formatter_ptr msg_formatter) override;
74-
void _set_pattern(const std::string& pattern, pattern_time_type pattern_time) override;
61+
void sink_it_(details::log_msg &msg) override;
62+
void flush_() override;
63+
64+
void backend_log_(const details::log_msg &incoming_log_msg);
65+
void backend_flush_();
7566

7667
private:
77-
std::unique_ptr<details::async_log_helper> _async_log_helper;
68+
std::weak_ptr<details::thread_pool> thread_pool_;
69+
async_overflow_policy overflow_policy_;
7870
};
79-
}
80-
71+
} // namespace spdlog
8172

8273
#include "details/async_logger_impl.h"

0 commit comments

Comments
 (0)