mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
move underscores to the end of private members
This commit is contained in:
@@ -31,23 +31,23 @@ class android_sink : public sink
|
||||
{
|
||||
public:
|
||||
explicit android_sink(const std::string &tag = "spdlog", bool use_raw_msg = false)
|
||||
: _tag(tag)
|
||||
, _use_raw_msg(use_raw_msg)
|
||||
: tag_(tag)
|
||||
, use_raw_msg_(use_raw_msg)
|
||||
{
|
||||
}
|
||||
|
||||
void log(const details::log_msg &msg) override
|
||||
{
|
||||
const android_LogPriority priority = convert_to_android(msg.level);
|
||||
const char *msg_output = (_use_raw_msg ? msg.raw.c_str() : msg.formatted.c_str());
|
||||
const char *msg_output = (use_raw_msg_ ? msg.raw.c_str() : msg.formatted.c_str());
|
||||
|
||||
// See system/core/liblog/logger_write.c for explanation of return value
|
||||
int ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
||||
int ret = __android_log_write(priority, tag_.c_str(), msg_output);
|
||||
int retry_count = 0;
|
||||
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
|
||||
{
|
||||
details::os::sleep_for_millis(5);
|
||||
ret = __android_log_write(priority, _tag.c_str(), msg_output);
|
||||
ret = __android_log_write(priority, tag_.c_str(), msg_output);
|
||||
retry_count++;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::string _tag;
|
||||
bool _use_raw_msg;
|
||||
std::string tag_;
|
||||
bool use_raw_msg_;
|
||||
};
|
||||
|
||||
} // namespace sinks
|
||||
|
@@ -29,7 +29,7 @@ public:
|
||||
using mutex_t = typename ConsoleMutexTrait::mutex_t;
|
||||
ansicolor_sink()
|
||||
: target_file_(StreamTrait::stream())
|
||||
, _mutex(ConsoleMutexTrait::console_mutex())
|
||||
, mutex_(ConsoleMutexTrait::console_mutex())
|
||||
|
||||
{
|
||||
should_do_colors_ = details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
|
||||
void set_color(level::level_enum color_level, const std::string &color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_[color_level] = color;
|
||||
}
|
||||
|
||||
@@ -87,43 +87,43 @@ public:
|
||||
{
|
||||
// Wrap the originally formatted message in color codes.
|
||||
// If color is not supported in the terminal, log as is instead.
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
|
||||
{
|
||||
// before color range
|
||||
_print_range(msg, 0, msg.color_range_start);
|
||||
print_range_(msg, 0, msg.color_range_start);
|
||||
// in color range
|
||||
_print_ccode(colors_[msg.level]);
|
||||
_print_range(msg, msg.color_range_start, msg.color_range_end);
|
||||
_print_ccode(reset);
|
||||
print_ccode_(colors_[msg.level]);
|
||||
print_range_(msg, msg.color_range_start, msg.color_range_end);
|
||||
print_ccode_(reset);
|
||||
// after color range
|
||||
_print_range(msg, msg.color_range_end, msg.formatted.size());
|
||||
print_range_(msg, msg.color_range_end, msg.formatted.size());
|
||||
}
|
||||
else // no color
|
||||
{
|
||||
_print_range(msg, 0, msg.formatted.size());
|
||||
print_range_(msg, 0, msg.formatted.size());
|
||||
}
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
void flush() SPDLOG_FINAL override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
private:
|
||||
void _print_ccode(const std::string &color_code)
|
||||
void print_ccode_(const std::string &color_code)
|
||||
{
|
||||
fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_);
|
||||
}
|
||||
void _print_range(const details::log_msg &msg, size_t start, size_t end)
|
||||
void print_range_(const details::log_msg &msg, size_t start, size_t end)
|
||||
{
|
||||
fwrite(msg.formatted.data() + start, sizeof(char), end - start, target_file_);
|
||||
}
|
||||
|
||||
FILE *target_file_;
|
||||
mutex_t &_mutex;
|
||||
mutex_t &mutex_;
|
||||
|
||||
bool should_do_colors_;
|
||||
std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
//
|
||||
// base sink templated over a mutex (either dummy or real)
|
||||
// concrete implementation should only override the _sink_it method.
|
||||
// concrete implementation should only override the sink_it_ method.
|
||||
// all locking is taken care of here so no locking needed by the implementers..
|
||||
//
|
||||
|
||||
@@ -28,20 +28,21 @@ public:
|
||||
|
||||
void log(const details::log_msg &msg) SPDLOG_FINAL override
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_mutex);
|
||||
_sink_it(msg);
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
sink_it_(msg);
|
||||
|
||||
}
|
||||
|
||||
void flush() SPDLOG_FINAL override
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_mutex);
|
||||
_flush();
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _sink_it(const details::log_msg &msg) = 0;
|
||||
virtual void _flush() = 0;
|
||||
Mutex _mutex;
|
||||
virtual void sink_it_(const details::log_msg &msg) = 0;
|
||||
virtual void flush_() = 0;
|
||||
Mutex mutex_;
|
||||
};
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@@ -63,42 +63,42 @@ class daily_file_sink SPDLOG_FINAL : public base_sink<Mutex>
|
||||
public:
|
||||
// create daily file sink which rotates on given time
|
||||
daily_file_sink(filename_t base_filename, int rotation_hour, int rotation_minute)
|
||||
: _base_filename(std::move(base_filename))
|
||||
, _rotation_h(rotation_hour)
|
||||
, _rotation_m(rotation_minute)
|
||||
: base_filename_(std::move(base_filename))
|
||||
, rotation_h_(rotation_hour)
|
||||
, rotation_m_(rotation_minute)
|
||||
{
|
||||
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
|
||||
{
|
||||
throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
|
||||
}
|
||||
_rotation_tp = _next_rotation_tp();
|
||||
_file_helper.open(FileNameCalc::calc_filename(_base_filename));
|
||||
rotation_tp_ = next_rotation_tp_();
|
||||
file_helper_.open(FileNameCalc::calc_filename(base_filename_));
|
||||
}
|
||||
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
if (std::chrono::system_clock::now() >= _rotation_tp)
|
||||
if (std::chrono::system_clock::now() >= rotation_tp_)
|
||||
{
|
||||
_file_helper.open(FileNameCalc::calc_filename(_base_filename));
|
||||
_rotation_tp = _next_rotation_tp();
|
||||
file_helper_.open(FileNameCalc::calc_filename(base_filename_));
|
||||
rotation_tp_ = next_rotation_tp_();
|
||||
}
|
||||
_file_helper.write(msg);
|
||||
file_helper_.write(msg);
|
||||
}
|
||||
|
||||
void _flush() override
|
||||
void flush_() override
|
||||
{
|
||||
_file_helper.flush();
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::system_clock::time_point _next_rotation_tp()
|
||||
std::chrono::system_clock::time_point next_rotation_tp_()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
time_t tnow = std::chrono::system_clock::to_time_t(now);
|
||||
tm date = spdlog::details::os::localtime(tnow);
|
||||
date.tm_hour = _rotation_h;
|
||||
date.tm_min = _rotation_m;
|
||||
date.tm_hour = rotation_h_;
|
||||
date.tm_min = rotation_m_;
|
||||
date.tm_sec = 0;
|
||||
auto rotation_time = std::chrono::system_clock::from_time_t(std::mktime(&date));
|
||||
if (rotation_time > now)
|
||||
@@ -108,11 +108,11 @@ private:
|
||||
return {rotation_time + std::chrono::hours(24)};
|
||||
}
|
||||
|
||||
filename_t _base_filename;
|
||||
int _rotation_h;
|
||||
int _rotation_m;
|
||||
std::chrono::system_clock::time_point _rotation_tp;
|
||||
details::file_helper _file_helper;
|
||||
filename_t base_filename_;
|
||||
int rotation_h_;
|
||||
int rotation_m_;
|
||||
std::chrono::system_clock::time_point rotation_tp_;
|
||||
details::file_helper file_helper_;
|
||||
};
|
||||
|
||||
using daily_file_sink_mt = daily_file_sink<std::mutex>;
|
||||
|
@@ -23,18 +23,18 @@ class dist_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
explicit dist_sink()
|
||||
: _sinks()
|
||||
: sinks_()
|
||||
{
|
||||
}
|
||||
dist_sink(const dist_sink &) = delete;
|
||||
dist_sink &operator=(const dist_sink &) = delete;
|
||||
|
||||
protected:
|
||||
std::vector<std::shared_ptr<sink>> _sinks;
|
||||
std::vector<std::shared_ptr<sink>> sinks_;
|
||||
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
for (auto &sink : _sinks)
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
if (sink->should_log(msg.level))
|
||||
{
|
||||
@@ -43,23 +43,23 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
void _flush() override
|
||||
void flush_() override
|
||||
{
|
||||
for (auto &sink : _sinks)
|
||||
for (auto &sink : sinks_)
|
||||
sink->flush();
|
||||
}
|
||||
|
||||
public:
|
||||
void add_sink(std::shared_ptr<sink> sink)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||
_sinks.push_back(sink);
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
sinks_.push_back(sink);
|
||||
}
|
||||
|
||||
void remove_sink(std::shared_ptr<sink> sink)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
|
||||
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end());
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end());
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -27,12 +27,12 @@ public:
|
||||
explicit msvc_sink() {}
|
||||
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
OutputDebugStringA(msg.formatted.c_str());
|
||||
}
|
||||
|
||||
void _flush() override {}
|
||||
void flush_() override {}
|
||||
};
|
||||
|
||||
using msvc_sink_mt = msvc_sink<std::mutex>;
|
||||
|
@@ -17,9 +17,9 @@ template<class Mutex>
|
||||
class null_sink : public base_sink<Mutex>
|
||||
{
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &) override {}
|
||||
void sink_it_(const details::log_msg &) override {}
|
||||
|
||||
void _flush() override {}
|
||||
void flush_() override {}
|
||||
};
|
||||
|
||||
using null_sink_mt = null_sink<details::null_mutex>;
|
||||
|
@@ -18,28 +18,28 @@ class ostream_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
explicit ostream_sink(std::ostream &os, bool force_flush = false)
|
||||
: _ostream(os)
|
||||
, _force_flush(force_flush)
|
||||
: ostream_(os)
|
||||
, force_flush_(force_flush)
|
||||
{
|
||||
}
|
||||
ostream_sink(const ostream_sink &) = delete;
|
||||
ostream_sink &operator=(const ostream_sink &) = delete;
|
||||
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
_ostream.write(msg.formatted.data(), msg.formatted.size());
|
||||
if (_force_flush)
|
||||
_ostream.flush();
|
||||
ostream_.write(msg.formatted.data(), msg.formatted.size());
|
||||
if (force_flush_)
|
||||
ostream_.flush();
|
||||
}
|
||||
|
||||
void _flush() override
|
||||
void flush_() override
|
||||
{
|
||||
_ostream.flush();
|
||||
ostream_.flush();
|
||||
}
|
||||
|
||||
std::ostream &_ostream;
|
||||
bool _force_flush;
|
||||
std::ostream &ostream_;
|
||||
bool force_flush_;
|
||||
};
|
||||
|
||||
using ostream_sink_mt = ostream_sink<std::mutex>;
|
||||
|
@@ -28,12 +28,12 @@ class rotating_file_sink SPDLOG_FINAL : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files)
|
||||
: _base_filename(std::move(base_filename))
|
||||
, _max_size(max_size)
|
||||
, _max_files(max_files)
|
||||
: base_filename_(std::move(base_filename))
|
||||
, max_size_(max_size)
|
||||
, max_files_(max_files)
|
||||
{
|
||||
_file_helper.open(calc_filename(_base_filename, 0));
|
||||
_current_size = _file_helper.size(); // expensive. called only once
|
||||
file_helper_.open(calc_filename(base_filename_, 0));
|
||||
current_size_ = file_helper_.size(); // expensive. called only once
|
||||
}
|
||||
|
||||
// calc filename according to index and file extension if exists.
|
||||
@@ -55,20 +55,20 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
_current_size += msg.formatted.size();
|
||||
if (_current_size > _max_size)
|
||||
current_size_ += msg.formatted.size();
|
||||
if (current_size_ > max_size_)
|
||||
{
|
||||
_rotate();
|
||||
_current_size = msg.formatted.size();
|
||||
rotate_();
|
||||
current_size_ = msg.formatted.size();
|
||||
}
|
||||
_file_helper.write(msg);
|
||||
file_helper_.write(msg);
|
||||
}
|
||||
|
||||
void _flush() override
|
||||
void flush_() override
|
||||
{
|
||||
_file_helper.flush();
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -77,14 +77,14 @@ private:
|
||||
// log.1.txt -> log.2.txt
|
||||
// log.2.txt -> log.3.txt
|
||||
// log.3.txt -> delete
|
||||
void _rotate()
|
||||
void rotate_()
|
||||
{
|
||||
using details::os::filename_to_str;
|
||||
_file_helper.close();
|
||||
for (auto i = _max_files; i > 0; --i)
|
||||
file_helper_.close();
|
||||
for (auto i = max_files_; i > 0; --i)
|
||||
{
|
||||
filename_t src = calc_filename(_base_filename, i - 1);
|
||||
filename_t target = calc_filename(_base_filename, i);
|
||||
filename_t src = calc_filename(base_filename_, i - 1);
|
||||
filename_t target = calc_filename(base_filename_, i);
|
||||
|
||||
if (details::file_helper::file_exists(target))
|
||||
{
|
||||
@@ -98,14 +98,14 @@ private:
|
||||
throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
|
||||
}
|
||||
}
|
||||
_file_helper.reopen(true);
|
||||
file_helper_.reopen(true);
|
||||
}
|
||||
|
||||
filename_t _base_filename;
|
||||
std::size_t _max_size;
|
||||
std::size_t _max_files;
|
||||
std::size_t _current_size;
|
||||
details::file_helper _file_helper;
|
||||
filename_t base_filename_;
|
||||
std::size_t max_size_;
|
||||
std::size_t max_files_;
|
||||
std::size_t current_size_;
|
||||
details::file_helper file_helper_;
|
||||
};
|
||||
|
||||
using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
|
||||
|
@@ -22,34 +22,34 @@ class simple_file_sink SPDLOG_FINAL : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
explicit simple_file_sink(const filename_t &filename, bool truncate = false)
|
||||
: _force_flush(false)
|
||||
: force_flush_(false)
|
||||
{
|
||||
_file_helper.open(filename, truncate);
|
||||
file_helper_.open(filename, truncate);
|
||||
}
|
||||
|
||||
void set_force_flush(bool force_flush)
|
||||
{
|
||||
_force_flush = force_flush;
|
||||
force_flush_ = force_flush;
|
||||
}
|
||||
|
||||
protected:
|
||||
void _sink_it(const details::log_msg &msg) override
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
_file_helper.write(msg);
|
||||
if (_force_flush)
|
||||
file_helper_.write(msg);
|
||||
if (force_flush_)
|
||||
{
|
||||
_file_helper.flush();
|
||||
file_helper_.flush();
|
||||
}
|
||||
}
|
||||
|
||||
void _flush() override
|
||||
void flush_() override
|
||||
{
|
||||
_file_helper.flush();
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
||||
private:
|
||||
details::file_helper _file_helper;
|
||||
bool _force_flush;
|
||||
details::file_helper file_helper_;
|
||||
bool force_flush_;
|
||||
};
|
||||
|
||||
using simple_file_sink_mt = simple_file_sink<std::mutex>;
|
||||
|
@@ -22,22 +22,22 @@ public:
|
||||
level::level_enum level() const;
|
||||
|
||||
private:
|
||||
level_t _level{level::trace};
|
||||
level_t level_{level::trace};
|
||||
};
|
||||
|
||||
inline bool sink::should_log(level::level_enum msg_level) const
|
||||
{
|
||||
return msg_level >= _level.load(std::memory_order_relaxed);
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
inline void sink::set_level(level::level_enum log_level)
|
||||
{
|
||||
_level.store(log_level);
|
||||
level_.store(log_level);
|
||||
}
|
||||
|
||||
inline level::level_enum sink::level() const
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed));
|
||||
return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
} // namespace sinks
|
||||
|
@@ -23,8 +23,8 @@ class stdout_sink : public sink
|
||||
public:
|
||||
using mutex_t = typename ConsoleMutexTrait::mutex_t;
|
||||
stdout_sink()
|
||||
: _mutex(ConsoleMutexTrait::console_mutex())
|
||||
, _file(StdoutTrait::stream())
|
||||
: mutex_(ConsoleMutexTrait::console_mutex())
|
||||
, file_(StdoutTrait::stream())
|
||||
{
|
||||
}
|
||||
~stdout_sink() = default;
|
||||
@@ -34,20 +34,20 @@ public:
|
||||
|
||||
void log(const details::log_msg &msg) override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), _file);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), file_);
|
||||
fflush(StdoutTrait::stream());
|
||||
}
|
||||
|
||||
void flush() override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(StdoutTrait::stream());
|
||||
}
|
||||
|
||||
private:
|
||||
mutex_t &_mutex;
|
||||
FILE *_file;
|
||||
mutex_t &mutex_;
|
||||
FILE *file_;
|
||||
};
|
||||
|
||||
using stdout_sink_mt = stdout_sink<details::console_stdout_trait, details::console_mutex_trait>;
|
||||
|
@@ -26,18 +26,18 @@ class syslog_sink : public sink
|
||||
public:
|
||||
//
|
||||
syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER)
|
||||
: _ident(ident)
|
||||
: ident_(ident)
|
||||
{
|
||||
_priorities[static_cast<size_t>(level::trace)] = LOG_DEBUG;
|
||||
_priorities[static_cast<size_t>(level::debug)] = LOG_DEBUG;
|
||||
_priorities[static_cast<size_t>(level::info)] = LOG_INFO;
|
||||
_priorities[static_cast<size_t>(level::warn)] = LOG_WARNING;
|
||||
_priorities[static_cast<size_t>(level::err)] = LOG_ERR;
|
||||
_priorities[static_cast<size_t>(level::critical)] = LOG_CRIT;
|
||||
_priorities[static_cast<size_t>(level::off)] = LOG_INFO;
|
||||
priorities_[static_cast<size_t>(level::trace)] = LOG_DEBUG;
|
||||
priorities_[static_cast<size_t>(level::debug)] = LOG_DEBUG;
|
||||
priorities_[static_cast<size_t>(level::info)] = LOG_INFO;
|
||||
priorities_[static_cast<size_t>(level::warn)] = LOG_WARNING;
|
||||
priorities_[static_cast<size_t>(level::err)] = LOG_ERR;
|
||||
priorities_[static_cast<size_t>(level::critical)] = LOG_CRIT;
|
||||
priorities_[static_cast<size_t>(level::off)] = LOG_INFO;
|
||||
|
||||
// set ident to be program name if empty
|
||||
::openlog(_ident.empty() ? nullptr : _ident.c_str(), syslog_option, syslog_facility);
|
||||
::openlog(ident_.empty() ? nullptr : ident_.c_str(), syslog_option, syslog_facility);
|
||||
}
|
||||
|
||||
~syslog_sink() override
|
||||
@@ -56,16 +56,16 @@ public:
|
||||
void flush() override {}
|
||||
|
||||
private:
|
||||
std::array<int, 7> _priorities;
|
||||
std::array<int, 7> priorities_;
|
||||
// must store the ident because the man says openlog might use the pointer as is and not a string copy
|
||||
const std::string _ident;
|
||||
const std::string ident_;
|
||||
|
||||
//
|
||||
// Simply maps spdlog's log level to syslog priority level.
|
||||
//
|
||||
int syslog_prio_from_level(const details::log_msg &msg) const
|
||||
{
|
||||
return _priorities[static_cast<size_t>(msg.level)];
|
||||
return priorities_[static_cast<size_t>(msg.level)];
|
||||
}
|
||||
};
|
||||
} // namespace sinks
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
wincolor_sink()
|
||||
: out_handle_(HandleTrait::handle())
|
||||
, _mutex(ConsoleMutexTrait::console_mutex())
|
||||
, mutex_(ConsoleMutexTrait::console_mutex())
|
||||
{
|
||||
colors_[level::trace] = WHITE;
|
||||
colors_[level::debug] = CYAN;
|
||||
@@ -56,29 +56,29 @@ public:
|
||||
// change the color for the given level
|
||||
void set_color(level::level_enum level, WORD color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_[level] = color;
|
||||
}
|
||||
|
||||
void log(const details::log_msg &msg) SPDLOG_FINAL override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(_mutex);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
|
||||
if (msg.color_range_end > msg.color_range_start)
|
||||
{
|
||||
// before color range
|
||||
_print_range(msg, 0, msg.color_range_start);
|
||||
print_range_(msg, 0, msg.color_range_start);
|
||||
|
||||
// in color range
|
||||
auto orig_attribs = set_console_attribs(colors_[msg.level]);
|
||||
_print_range(msg, msg.color_range_start, msg.color_range_end);
|
||||
print_range_(msg, msg.color_range_start, msg.color_range_end);
|
||||
::SetConsoleTextAttribute(out_handle_, orig_attribs); // reset to orig colors
|
||||
// after color range
|
||||
_print_range(msg, msg.color_range_end, msg.formatted.size());
|
||||
print_range_(msg, msg.color_range_end, msg.formatted.size());
|
||||
}
|
||||
else // print without colors if color range is invalid
|
||||
{
|
||||
_print_range(msg, 0, msg.formatted.size());
|
||||
print_range_(msg, 0, msg.formatted.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +103,14 @@ private:
|
||||
}
|
||||
|
||||
// print a range of formatted message to console
|
||||
void _print_range(const details::log_msg &msg, size_t start, size_t end)
|
||||
void print_range_(const details::log_msg &msg, size_t start, size_t end)
|
||||
{
|
||||
auto size = static_cast<DWORD>(end - start);
|
||||
::WriteConsoleA(out_handle_, msg.formatted.data() + start, size, nullptr, nullptr);
|
||||
}
|
||||
|
||||
HANDLE out_handle_;
|
||||
mutex_t &_mutex;
|
||||
mutex_t &mutex_;
|
||||
std::unordered_map<level::level_enum, WORD, level::level_hasher> colors_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user