Commit 9df2bd25 authored by gabime's avatar gabime

Changed some functions to accept strings instead of ref to strings for better semantics

parent b238bf95
...@@ -23,14 +23,14 @@ inline spdlog::logger::logger(std::string logger_name, const It &begin, const It ...@@ -23,14 +23,14 @@ inline spdlog::logger::logger(std::string logger_name, const It &begin, const It
} }
// ctor with sinks as init list // ctor with sinks as init list
inline spdlog::logger::logger(const std::string &logger_name, sinks_init_list sinks_list) inline spdlog::logger::logger(std::string logger_name, sinks_init_list sinks_list)
: logger(logger_name, sinks_list.begin(), sinks_list.end()) : logger(std::move(logger_name), sinks_list.begin(), sinks_list.end())
{ {
} }
// ctor with single sink // ctor with single sink
inline spdlog::logger::logger(const std::string &logger_name, spdlog::sink_ptr single_sink) inline spdlog::logger::logger(std::string logger_name, spdlog::sink_ptr single_sink)
: logger(logger_name, {std::move(single_sink)}) : logger(std::move(logger_name), {std::move(single_sink)})
{ {
} }
...@@ -46,9 +46,9 @@ inline void spdlog::logger::set_formatter(const Args &... args) ...@@ -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> template<typename... Args>
......
...@@ -539,14 +539,14 @@ private: ...@@ -539,14 +539,14 @@ 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 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) std::string eol = spdlog::details::os::default_eol)
: eol_(std::move(eol)) : eol_(std::move(eol))
, pattern_time_type_(time_type) , 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_));
compile_pattern_(pattern); compile_pattern_(std::move(pattern));
} }
pattern_formatter(const pattern_formatter &) = delete; pattern_formatter(const pattern_formatter &) = delete;
......
...@@ -28,8 +28,8 @@ namespace spdlog { ...@@ -28,8 +28,8 @@ namespace spdlog {
class logger class logger
{ {
public: public:
logger(const std::string &name, sink_ptr single_sink); logger(std::string name, sink_ptr single_sink);
logger(const std::string &name, sinks_init_list sinks); logger(std::string name, sinks_init_list sinks);
template<typename It> template<typename It>
logger(std::string name, const It &begin, const It &end); logger(std::string name, const It &begin, const It &end);
...@@ -114,7 +114,7 @@ public: ...@@ -114,7 +114,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 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. // 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.
......
...@@ -23,10 +23,10 @@ struct synchronous_factory ...@@ -23,10 +23,10 @@ struct synchronous_factory
{ {
template<typename Sink, typename... SinkArgs> 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 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); details::registry::instance().register_and_init(new_logger);
return new_logger; return new_logger;
} }
...@@ -39,9 +39,9 @@ using default_factory = synchronous_factory; ...@@ -39,9 +39,9 @@ using default_factory = synchronous_factory;
// Example: // Example:
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59); // spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
template<typename Sink, typename... SinkArgs> 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) ...@@ -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, 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);
} }
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment