Renamed file to pattern_forammter.h and fixed utc support
This commit is contained in:
parent
cbc4db8649
commit
c9331594bb
@ -46,9 +46,9 @@ inline void spdlog::logger::set_formatter(const Args &... args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void spdlog::logger::set_pattern(const std::string &pattern, pattern_time_type pattern_time)
|
inline void spdlog::logger::set_pattern(const std::string &pattern, pattern_time_type time_type)
|
||||||
{
|
{
|
||||||
set_formatter<spdlog::pattern_formatter>(pattern, pattern_time);
|
set_formatter<spdlog::pattern_formatter>(pattern, time_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
@ -525,10 +525,10 @@ private:
|
|||||||
class pattern_formatter SPDLOG_FINAL : public formatter
|
class pattern_formatter SPDLOG_FINAL : public formatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit pattern_formatter(const std::string &pattern, pattern_time_type pattern_time = pattern_time_type::local,
|
explicit pattern_formatter(const std::string &pattern, pattern_time_type time_type = pattern_time_type::local,
|
||||||
std::string eol = spdlog::details::os::default_eol)
|
std::string eol = spdlog::details::os::default_eol)
|
||||||
: eol_(std::move(eol))
|
: eol_(std::move(eol))
|
||||||
, pattern_time_(pattern_time)
|
, pattern_time_type_(time_type)
|
||||||
, last_log_secs_(0)
|
, last_log_secs_(0)
|
||||||
{
|
{
|
||||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||||
@ -557,14 +557,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string eol_;
|
const std::string eol_;
|
||||||
const pattern_time_type pattern_time_;
|
pattern_time_type pattern_time_type_;
|
||||||
std::tm cached_tm_;
|
std::tm cached_tm_;
|
||||||
std::chrono::seconds last_log_secs_;
|
std::chrono::seconds last_log_secs_;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||||
|
|
||||||
std::tm get_time_(const details::log_msg &msg)
|
std::tm get_time_(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
if (pattern_time_ == pattern_time_type::local)
|
if (pattern_time_type_ == pattern_time_type::local)
|
||||||
{
|
{
|
||||||
return details::os::localtime(log_clock::to_time_t(msg.time));
|
return details::os::localtime(log_clock::to_time_t(msg.time));
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
// create default formatter if not exists
|
// create default formatter if not exists
|
||||||
|
|
||||||
new_logger->set_pattern(formatter_pattern_);
|
new_logger->set_formatter<pattern_formatter>(formatter_pattern_, pattern_time_type_);
|
||||||
|
|
||||||
if (err_handler_)
|
if (err_handler_)
|
||||||
{
|
{
|
||||||
@ -81,13 +81,14 @@ public:
|
|||||||
return tp_;
|
return tp_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_pattern(const std::string &pattern)
|
void set_pattern(const std::string &pattern, pattern_time_type time_type)
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(mutex_);
|
std::lock_guard<Mutex> lock(mutex_);
|
||||||
formatter_pattern_ = pattern;
|
formatter_pattern_ = pattern;
|
||||||
|
pattern_time_type_ = time_type;
|
||||||
for (auto &l : loggers_)
|
for (auto &l : loggers_)
|
||||||
{
|
{
|
||||||
l.second->set_pattern(pattern);
|
l.second->set_pattern(pattern, time_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +175,7 @@ private:
|
|||||||
Mutex tp_mutex_;
|
Mutex tp_mutex_;
|
||||||
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
|
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
|
||||||
std::string formatter_pattern_ = "%+";
|
std::string formatter_pattern_ = "%+";
|
||||||
|
pattern_time_type pattern_time_type_ = pattern_time_type::local;
|
||||||
level::level_enum level_ = level::info;
|
level::level_enum level_ = level::info;
|
||||||
level::level_enum flush_level_ = level::off;
|
level::level_enum flush_level_ = level::off;
|
||||||
log_err_handler err_handler_;
|
log_err_handler err_handler_;
|
||||||
|
@ -117,7 +117,7 @@ public:
|
|||||||
|
|
||||||
// create a pattern formatter all the sinks in this logger.
|
// create a pattern formatter all the sinks in this logger.
|
||||||
// each sink gets itw own private copy of a formatter object.
|
// each sink gets itw own private copy of a formatter object.
|
||||||
void set_pattern(const std::string &pattern, pattern_time_type pattern_time = pattern_time_type::local);
|
void set_pattern(const std::string &pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||||
|
|
||||||
// create a FormatterT formatter for each sink in this logger.
|
// create a FormatterT formatter for each sink in this logger.
|
||||||
// each sink gets its own private copy of a formatter object.
|
// each sink gets its own private copy of a formatter object.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "spdlog/details/log_msg.h"
|
#include "spdlog/details/log_msg.h"
|
||||||
#include "spdlog/details/pattern_formatter_impl.h"
|
#include "spdlog/details/pattern_formatter.h"
|
||||||
#include "spdlog/formatter.h"
|
#include "spdlog/formatter.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
|
@ -57,9 +57,9 @@ inline std::shared_ptr<logger> get(const std::string &name)
|
|||||||
// Set global formatting
|
// Set global formatting
|
||||||
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
||||||
//
|
//
|
||||||
inline void set_pattern(const std::string &format_string)
|
inline void set_pattern(const std::string &format_string, pattern_time_type time_type = pattern_time_type::local)
|
||||||
{
|
{
|
||||||
details::registry::instance().set_pattern(format_string);
|
details::registry::instance().set_pattern(format_string, time_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user