mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 02:21:34 +08:00
Replaced details::make_unique with std::make_unique
This commit is contained in:
parent
866744e40e
commit
19d4e60561
@ -323,7 +323,7 @@ public:
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override
|
||||
{
|
||||
return spdlog::details::make_unique<my_formatter_flag>();
|
||||
return spdlog::std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
void bench_formatter(benchmark::State &state, std::string pattern)
|
||||
{
|
||||
auto formatter = spdlog::details::make_unique<spdlog::pattern_formatter>(pattern);
|
||||
auto formatter = spdlog::std::make_unique<spdlog::pattern_formatter>(pattern);
|
||||
spdlog::memory_buf_t dest;
|
||||
std::string logger_name = "logger-name";
|
||||
const char *text = "Hello. This is some message with length of 80 ";
|
||||
|
@ -338,15 +338,13 @@ public:
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override
|
||||
{
|
||||
return spdlog::details::make_unique<my_formatter_flag>();
|
||||
return std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
};
|
||||
|
||||
void custom_flags_example()
|
||||
{
|
||||
|
||||
using spdlog::details::make_unique; // for pre c++14
|
||||
auto formatter = make_unique<spdlog::pattern_formatter>();
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>();
|
||||
formatter->add_flag<my_formatter_flag>('*').set_pattern("[%n] [%*] [%^%l%$] %v");
|
||||
// set the new formatter using spdlog::set_formatter(formatter) or logger->set_formatter(formatter)
|
||||
// spdlog::set_formatter(std::move(formatter));
|
||||
|
@ -330,29 +330,15 @@ constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, A
|
||||
|
||||
// make_unique support for pre c++14
|
||||
|
||||
#if __cplusplus >= 201402L // C++14 and beyond
|
||||
using std::enable_if_t;
|
||||
using std::make_unique;
|
||||
#else
|
||||
template<bool B, class T = void>
|
||||
using enable_if_t = typename std::enable_if<B, T>::type;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args &&...args)
|
||||
{
|
||||
static_assert(!std::is_array<T>::value, "arrays not supported");
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
#endif
|
||||
|
||||
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
||||
template<typename T, typename U, enable_if_t<!std::is_same<T, U>::value, int> = 0>
|
||||
template<typename T, typename U, std::enable_if_t<!std::is_same<T, U>::value, int> = 0>
|
||||
constexpr T conditional_static_cast(U value)
|
||||
{
|
||||
return static_cast<T>(value);
|
||||
}
|
||||
|
||||
template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0>
|
||||
template<typename T, typename U, std::enable_if_t<std::is_same<T, U>::value, int> = 0>
|
||||
constexpr T conditional_static_cast(U value)
|
||||
{
|
||||
return value;
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||
auto clbk = [this]() { this->flush_all(); };
|
||||
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
|
||||
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
|
||||
}
|
||||
|
||||
void set_error_handler(err_handler handler);
|
||||
|
@ -96,7 +96,7 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f)
|
||||
|
||||
SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
auto new_formatter = details::make_unique<pattern_formatter>(std::move(pattern), time_type);
|
||||
auto new_formatter = std::make_unique<pattern_formatter>(std::move(pattern), time_type);
|
||||
set_formatter(std::move(new_formatter));
|
||||
}
|
||||
|
||||
|
@ -1041,7 +1041,7 @@ SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type,
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{}));
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(details::padding_info{}));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
@ -1051,7 +1051,7 @@ SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
{
|
||||
cloned_custom_formatters[it.first] = it.second->clone();
|
||||
}
|
||||
auto cloned = details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
|
||||
auto cloned = std::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
|
||||
cloned->need_localtime(need_localtime_);
|
||||
#if defined(__GNUC__) && __GNUC__ < 5
|
||||
return std::move(cloned);
|
||||
@ -1118,198 +1118,198 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
|
||||
switch (flag)
|
||||
{
|
||||
case ('+'): // default formatter
|
||||
formatters_.push_back(details::make_unique<details::full_formatter>(padding));
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case 'n': // logger name
|
||||
formatters_.push_back(details::make_unique<details::name_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::name_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case 'l': // level
|
||||
formatters_.push_back(details::make_unique<details::level_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::level_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case 'L': // short level
|
||||
formatters_.push_back(details::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('t'): // thread id
|
||||
formatters_.push_back(details::make_unique<details::t_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::t_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('v'): // the message text
|
||||
formatters_.push_back(details::make_unique<details::v_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::v_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('a'): // weekday
|
||||
formatters_.push_back(details::make_unique<details::a_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::a_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('A'): // short weekday
|
||||
formatters_.push_back(details::make_unique<details::A_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::A_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('b'):
|
||||
case ('h'): // month
|
||||
formatters_.push_back(details::make_unique<details::b_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::b_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('B'): // short month
|
||||
formatters_.push_back(details::make_unique<details::B_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::B_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('c'): // datetime
|
||||
formatters_.push_back(details::make_unique<details::c_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::c_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('C'): // year 2 digits
|
||||
formatters_.push_back(details::make_unique<details::C_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::C_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('Y'): // year 4 digits
|
||||
formatters_.push_back(details::make_unique<details::Y_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::Y_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('D'):
|
||||
case ('x'): // datetime MM/DD/YY
|
||||
formatters_.push_back(details::make_unique<details::D_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::D_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('m'): // month 1-12
|
||||
formatters_.push_back(details::make_unique<details::m_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::m_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('d'): // day of month 1-31
|
||||
formatters_.push_back(details::make_unique<details::d_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::d_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('H'): // hours 24
|
||||
formatters_.push_back(details::make_unique<details::H_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::H_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('I'): // hours 12
|
||||
formatters_.push_back(details::make_unique<details::I_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::I_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('M'): // minutes
|
||||
formatters_.push_back(details::make_unique<details::M_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::M_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('S'): // seconds
|
||||
formatters_.push_back(details::make_unique<details::S_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::S_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('e'): // milliseconds
|
||||
formatters_.push_back(details::make_unique<details::e_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::e_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('f'): // microseconds
|
||||
formatters_.push_back(details::make_unique<details::f_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::f_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('F'): // nanoseconds
|
||||
formatters_.push_back(details::make_unique<details::F_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::F_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('E'): // seconds since epoch
|
||||
formatters_.push_back(details::make_unique<details::E_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::E_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('p'): // am/pm
|
||||
formatters_.push_back(details::make_unique<details::p_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::p_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('r'): // 12 hour clock 02:55:02 pm
|
||||
formatters_.push_back(details::make_unique<details::r_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::r_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('R'): // 24-hour HH:MM time
|
||||
formatters_.push_back(details::make_unique<details::R_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::R_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('T'):
|
||||
case ('X'): // ISO 8601 time format (HH:MM:SS)
|
||||
formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::T_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('z'): // timezone
|
||||
formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::z_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('P'): // pid
|
||||
formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::pid_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('^'): // color range start
|
||||
formatters_.push_back(details::make_unique<details::color_start_formatter>(padding));
|
||||
formatters_.push_back(std::make_unique<details::color_start_formatter>(padding));
|
||||
break;
|
||||
|
||||
case ('$'): // color range end
|
||||
formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding));
|
||||
formatters_.push_back(std::make_unique<details::color_stop_formatter>(padding));
|
||||
break;
|
||||
|
||||
case ('@'): // source location (filename:filenumber)
|
||||
formatters_.push_back(details::make_unique<details::source_location_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::source_location_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('s'): // short source filename - without directory name
|
||||
formatters_.push_back(details::make_unique<details::short_filename_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::short_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('g'): // full source filename
|
||||
formatters_.push_back(details::make_unique<details::source_filename_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::source_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('#'): // source line number
|
||||
formatters_.push_back(details::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('!'): // source funcname
|
||||
formatters_.push_back(details::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('%'): // % char
|
||||
formatters_.push_back(details::make_unique<details::ch_formatter>('%'));
|
||||
formatters_.push_back(std::make_unique<details::ch_formatter>('%'));
|
||||
break;
|
||||
|
||||
case ('u'): // elapsed time since last log message in nanos
|
||||
formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(padding));
|
||||
break;
|
||||
|
||||
case ('i'): // elapsed time since last log message in micros
|
||||
formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(padding));
|
||||
break;
|
||||
|
||||
case ('o'): // elapsed time since last log message in millis
|
||||
formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(padding));
|
||||
break;
|
||||
|
||||
case ('O'): // elapsed time since last log message in seconds
|
||||
formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
|
||||
break;
|
||||
|
||||
default: // Unknown flag appears as is
|
||||
auto unknown_flag = details::make_unique<details::aggregate_formatter>();
|
||||
auto unknown_flag = std::make_unique<details::aggregate_formatter>();
|
||||
|
||||
if (!padding.truncate_)
|
||||
{
|
||||
@ -1323,7 +1323,7 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
|
||||
else
|
||||
{
|
||||
padding.truncate_ = false;
|
||||
formatters_.push_back(details::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
@ -1423,7 +1423,7 @@ SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &patter
|
||||
{
|
||||
if (!user_chars)
|
||||
{
|
||||
user_chars = details::make_unique<details::aggregate_formatter>();
|
||||
user_chars = std::make_unique<details::aggregate_formatter>();
|
||||
}
|
||||
user_chars->add_ch(*it);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
template<typename T, typename... Args>
|
||||
pattern_formatter &add_flag(char flag, Args &&...args)
|
||||
{
|
||||
custom_handlers_[flag] = details::make_unique<T>(std::forward<Args>(args)...);
|
||||
custom_handlers_[flag] = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
void set_pattern(std::string pattern);
|
||||
|
@ -17,7 +17,7 @@ template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, color_mode mode)
|
||||
: target_file_(target_file)
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
, formatter_(details::make_unique<spdlog::pattern_formatter>())
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
|
||||
{
|
||||
set_color_mode(mode);
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink()
|
||||
: formatter_{details::make_unique<spdlog::pattern_formatter>()}
|
||||
: formatter_{std::make_unique<spdlog::pattern_formatter>()}
|
||||
{}
|
||||
|
||||
template<typename Mutex>
|
||||
@ -53,7 +53,7 @@ void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_pt
|
||||
template<typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
||||
{
|
||||
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
|
@ -76,7 +76,7 @@ protected:
|
||||
|
||||
void set_pattern_(const std::string &pattern) override
|
||||
{
|
||||
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
||||
void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) override
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
client_ = spdlog::details::make_unique<mongocxx::client>(mongocxx::uri{uri});
|
||||
client_ = spdlog::std::make_unique<mongocxx::client>(mongocxx::uri{uri});
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
: mutex_(ConsoleMutex::mutex())
|
||||
, file_(file)
|
||||
, formatter_(details::make_unique<spdlog::pattern_formatter>())
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// get windows handle from the FILE* object
|
||||
|
@ -19,7 +19,7 @@ template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color_mode mode)
|
||||
: out_handle_(out_handle)
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
, formatter_(details::make_unique<spdlog::pattern_formatter>())
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
{
|
||||
|
||||
set_color_mode_impl(mode);
|
||||
|
@ -354,7 +354,7 @@ public:
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override
|
||||
{
|
||||
return spdlog::details::make_unique<custom_test_flag>(some_txt);
|
||||
return std::make_unique<custom_test_flag>(some_txt);
|
||||
}
|
||||
};
|
||||
// test clone with custom flag formatters
|
||||
|
Loading…
Reference in New Issue
Block a user