Commit 4637cf35 authored by gabi's avatar gabi

Improved perf by using const char* instead of std::string& when accepting format strings

parent 77886e76
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
template <typename... Args> template <typename... Args>
void write(const std::string& fmt, const Args&... args) void write(const char* fmt, const Args&... args)
{ {
if (!_enabled) if (!_enabled)
return; return;
......
...@@ -67,7 +67,7 @@ inline void spdlog::logger::set_pattern(const std::string& pattern) ...@@ -67,7 +67,7 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
// cppformat API of the form logger.info("hello {} {}", "world", 1); // cppformat API of the form logger.info("hello {} {}", "world", 1);
// //
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, const char* fmt, const Args&... args)
{ {
bool msg_enabled = should_log(lvl); bool msg_enabled = should_log(lvl);
details::line_logger l(this, lvl, msg_enabled); details::line_logger l(this, lvl, msg_enabled);
...@@ -76,61 +76,61 @@ inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, ...@@ -76,61 +76,61 @@ inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl,
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::log(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::log(const char* fmt, const Args&... args)
{ {
return _log(level::ALWAYS, fmt, args...); return _log(level::ALWAYS, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::trace(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::trace(const char* fmt, const Args&... args)
{ {
return _log(level::TRACE, fmt, args...); return _log(level::TRACE, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::debug(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::debug(const char* fmt, const Args&... args)
{ {
return _log(level::DEBUG, fmt, args...); return _log(level::DEBUG, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::info(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::info(const char* fmt, const Args&... args)
{ {
return _log(level::INFO, fmt, args...); return _log(level::INFO, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::notice(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::notice(const char* fmt, const Args&... args)
{ {
return _log(level::NOTICE, fmt, args...); return _log(level::NOTICE, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::warn(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::warn(const char* fmt, const Args&... args)
{ {
return _log(level::WARN, fmt, args...); return _log(level::WARN, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::error(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::error(const char* fmt, const Args&... args)
{ {
return _log(level::ERR, fmt, args...); return _log(level::ERR, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::critical(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::critical(const char* fmt, const Args&... args)
{ {
return _log(level::CRITICAL, fmt, args...); return _log(level::CRITICAL, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::alert(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::alert(const char* fmt, const Args&... args)
{ {
return _log(level::ALERT, fmt, args...); return _log(level::ALERT, fmt, args...);
} }
template <typename... Args> template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt, const Args&... args) inline spdlog::details::line_logger spdlog::logger::emerg(const char* fmt, const Args&... args)
{ {
return _log(level::EMERG, fmt, args...); return _log(level::EMERG, fmt, args...);
} }
......
...@@ -65,16 +65,16 @@ public: ...@@ -65,16 +65,16 @@ public:
//Stop logging //Stop logging
void stop(); void stop();
template <typename... Args> details::line_logger log(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger log(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger trace(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger trace(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger debug(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger debug(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger info(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger info(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger notice(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger notice(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger warn(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger warn(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger error(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger error(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger critical(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger critical(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger alert(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger alert(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger emerg(const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger emerg(const char* fmt, const Args&... args);
//API to support logger.info() << ".." calls //API to support logger.info() << ".." calls
...@@ -100,7 +100,7 @@ protected: ...@@ -100,7 +100,7 @@ protected:
virtual void _set_formatter(formatter_ptr); virtual void _set_formatter(formatter_ptr);
virtual void _stop(); virtual void _stop();
details::line_logger _log(level::level_enum lvl); details::line_logger _log(level::level_enum lvl);
template <typename... Args> details::line_logger _log(level::level_enum lvl, const std::string& fmt, const Args&... args); template <typename... Args> details::line_logger _log(level::level_enum lvl, const char* fmt, const Args&... args);
friend details::line_logger; friend details::line_logger;
......
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