mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Changed some functions to accept strings instead of ref to strings for better semantics
This commit is contained in:
parent
b238bf9512
commit
9df2bd256e
@ -23,14 +23,14 @@ inline spdlog::logger::logger(std::string logger_name, const It &begin, const It
|
||||
}
|
||||
|
||||
// ctor with sinks as init list
|
||||
inline spdlog::logger::logger(const std::string &logger_name, sinks_init_list sinks_list)
|
||||
: logger(logger_name, sinks_list.begin(), sinks_list.end())
|
||||
inline spdlog::logger::logger(std::string logger_name, sinks_init_list sinks_list)
|
||||
: logger(std::move(logger_name), sinks_list.begin(), sinks_list.end())
|
||||
{
|
||||
}
|
||||
|
||||
// ctor with single sink
|
||||
inline spdlog::logger::logger(const std::string &logger_name, spdlog::sink_ptr single_sink)
|
||||
: logger(logger_name, {std::move(single_sink)})
|
||||
inline spdlog::logger::logger(std::string logger_name, spdlog::sink_ptr single_sink)
|
||||
: logger(std::move(logger_name), {std::move(single_sink)})
|
||||
{
|
||||
}
|
||||
|
||||
@ -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 time_type)
|
||||
inline void spdlog::logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
set_formatter<spdlog::pattern_formatter>(pattern, time_type);
|
||||
set_formatter<spdlog::pattern_formatter>(std::move(pattern), time_type);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
|
@ -539,14 +539,14 @@ private:
|
||||
class pattern_formatter SPDLOG_FINAL : public formatter
|
||||
{
|
||||
public:
|
||||
explicit pattern_formatter(const std::string &pattern, pattern_time_type time_type = pattern_time_type::local,
|
||||
explicit pattern_formatter(std::string pattern, pattern_time_type time_type = pattern_time_type::local,
|
||||
std::string eol = spdlog::details::os::default_eol)
|
||||
: eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
compile_pattern_(pattern);
|
||||
compile_pattern_(std::move(pattern));
|
||||
}
|
||||
|
||||
pattern_formatter(const pattern_formatter &) = delete;
|
||||
|
@ -28,8 +28,8 @@ namespace spdlog {
|
||||
class logger
|
||||
{
|
||||
public:
|
||||
logger(const std::string &name, sink_ptr single_sink);
|
||||
logger(const std::string &name, sinks_init_list sinks);
|
||||
logger(std::string name, sink_ptr single_sink);
|
||||
logger(std::string name, sinks_init_list sinks);
|
||||
|
||||
template<typename It>
|
||||
logger(std::string name, const It &begin, const It &end);
|
||||
@ -114,7 +114,7 @@ public:
|
||||
|
||||
// create a pattern formatter all the sinks in this logger.
|
||||
// each sink gets itw own private copy of a formatter object.
|
||||
void set_pattern(const std::string &pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||
void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||
|
||||
// create a FormatterT formatter for each sink in this logger.
|
||||
// each sink gets its own private copy of a formatter object.
|
||||
|
@ -23,10 +23,10 @@ struct synchronous_factory
|
||||
{
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
|
||||
static std::shared_ptr<spdlog::logger> create(const std::string &logger_name, SinkArgs &&... args)
|
||||
static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args)
|
||||
{
|
||||
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
|
||||
auto new_logger = std::make_shared<logger>(logger_name, std::move(sink));
|
||||
auto new_logger = std::make_shared<logger>(std::move(logger_name), std::move(sink));
|
||||
details::registry::instance().register_and_init(new_logger);
|
||||
return new_logger;
|
||||
}
|
||||
@ -39,9 +39,9 @@ using default_factory = synchronous_factory;
|
||||
// Example:
|
||||
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create(const std::string &logger_name, SinkArgs &&... sink_args)
|
||||
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return default_factory::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
|
||||
return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
//
|
||||
@ -57,9 +57,9 @@ inline std::shared_ptr<logger> get(const std::string &name)
|
||||
// Set global formatting
|
||||
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
||||
//
|
||||
inline void set_pattern(const std::string &format_string, pattern_time_type time_type = pattern_time_type::local)
|
||||
inline void set_pattern(std::string format_string, pattern_time_type time_type = pattern_time_type::local)
|
||||
{
|
||||
details::registry::instance().set_pattern(format_string, time_type);
|
||||
details::registry::instance().set_pattern(std::move(format_string), time_type);
|
||||
}
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user