Merge remote-tracking branch 'origin/v1.x' into pwm1234/rotate_on_open

This commit is contained in:
Philip Miller
2018-09-06 11:40:46 -04:00
51 changed files with 718 additions and 318 deletions

View File

@@ -30,8 +30,8 @@ template<typename Mutex>
class android_sink SPDLOG_FINAL : public base_sink<Mutex>
{
public:
explicit android_sink(const std::string &tag = "spdlog", bool use_raw_msg = false)
: tag_(tag)
explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false)
: tag_(std::move(tag))
, use_raw_msg_(use_raw_msg)
{
}
@@ -43,11 +43,11 @@ protected:
fmt::memory_buffer formatted;
if (use_raw_msg_)
{
fmt_helper::append_buf(msg.raw, formatted);
details::fmt_helper::append_buf(msg.raw, formatted);
}
else
{
formatter_->format(msg, formatted);
sink::formatter_->format(msg, formatted);
}
formatted.push_back('\0');
const char *msg_output = formatted.data();

View File

@@ -24,7 +24,7 @@ namespace sinks {
* If no color terminal detected, omit the escape codes.
*/
template<typename TargetStream, class ConsoleMutex>
class ansicolor_sink : public sink
class ansicolor_sink SPDLOG_FINAL : public sink
{
public:
using mutex_t = typename ConsoleMutex::mutex_t;
@@ -84,7 +84,7 @@ public:
const std::string on_cyan = "\033[46m";
const std::string on_white = "\033[47m";
void log(const details::log_msg &msg) SPDLOG_FINAL override
void log(const details::log_msg &msg) override
{
// Wrap the originally formatted message in color codes.
// If color is not supported in the terminal, log as is instead.
@@ -110,19 +110,19 @@ public:
fflush(target_file_);
}
void flush() SPDLOG_FINAL override
void flush() override
{
std::lock_guard<mutex_t> lock(mutex_);
fflush(target_file_);
}
void set_pattern(const std::string &pattern) override SPDLOG_FINAL
void set_pattern(const std::string &pattern) SPDLOG_FINAL
{
std::lock_guard<mutex_t> lock(mutex_);
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
}
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override SPDLOG_FINAL
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override
{
std::lock_guard<mutex_t> lock(mutex_);
formatter_ = std::move(sink_formatter);

View File

@@ -30,7 +30,7 @@ public:
base_sink(const base_sink &) = delete;
base_sink &operator=(const base_sink &) = delete;
void log(const details::log_msg &msg) SPDLOG_FINAL override
void log(const details::log_msg &msg) SPDLOG_FINAL
{
std::lock_guard<Mutex> lock(mutex_);
sink_it_(msg);

View File

@@ -40,6 +40,12 @@ public:
sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end());
}
void set_sinks(std::vector<std::shared_ptr<sink>> sinks)
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
sinks_ = std::move(sinks);
}
protected:
void sink_it_(const details::log_msg &msg) override
{

View File

@@ -30,7 +30,7 @@ protected:
{
fmt::memory_buffer formatted;
sink::formatter_->format(msg, formatted);
ostream_.write(formatted.data(), formatted.size());
ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
if (force_flush_)
ostream_.flush();
}

View File

@@ -20,9 +20,11 @@ public:
{
}
sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
explicit sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
: level_(level::trace)
, formatter_(std::move(formatter)){};
, formatter_(std::move(formatter))
{
}
virtual ~sink() = default;
virtual void log(const details::log_msg &msg) = 0;

View File

@@ -12,14 +12,13 @@
#include <cstdio>
#include <memory>
#include <mutex>
#include <spdlog/details/console_globals.h>
namespace spdlog {
namespace sinks {
template<typename TargetStream, typename ConsoleMutex>
class stdout_sink : public sink
class stdout_sink SPDLOG_FINAL : public sink
{
public:
using mutex_t = typename ConsoleMutex::mutex_t;
@@ -28,7 +27,7 @@ public:
, file_(TargetStream::stream())
{
}
~stdout_sink() = default;
~stdout_sink() override = default;
stdout_sink(const stdout_sink &other) = delete;
stdout_sink &operator=(const stdout_sink &other) = delete;
@@ -48,13 +47,13 @@ public:
fflush(file_);
}
void set_pattern(const std::string &pattern) override SPDLOG_FINAL
void set_pattern(const std::string &pattern) override
{
std::lock_guard<mutex_t> lock(mutex_);
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
}
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override SPDLOG_FINAL
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override
{
std::lock_guard<mutex_t> lock(mutex_);
formatter_ = std::move(sink_formatter);

View File

@@ -24,8 +24,8 @@ class syslog_sink : public base_sink<Mutex>
{
public:
//
syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
: ident_(ident)
explicit syslog_sink(std::string ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
: ident_(std::move(ident))
{
priorities_[static_cast<size_t>(level::trace)] = LOG_DEBUG;
priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;