Commit 26cf0b38 authored by gabi's avatar gabi

support for API of the form logger.info() << ..

parent 58970bf1
......@@ -63,10 +63,11 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
_set_pattern(pattern);
}
//
// cppformat API of the form logger.info("hello {} {}", "world", 1);
//
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 std::string& fmt, const Args&... args)
{
bool msg_enabled = should_log(lvl);
details::line_logger l(this, lvl, msg_enabled);
......@@ -88,63 +89,131 @@ inline spdlog::details::line_logger spdlog::logger::log(level::level_enum lvl, c
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::log(const std::string& fmt, const Args&... args)
{
return log(level::ALWAYS, fmt, args...);
return _log(level::ALWAYS, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::trace(const std::string& fmt, const Args&... args)
{
return log(level::TRACE, fmt, args...);
return _log(level::TRACE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::debug(const std::string& fmt, const Args&... args)
{
return log(level::DEBUG, fmt, args...);
return _log(level::DEBUG, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::info(const std::string& fmt, const Args&... args)
{
return log(level::INFO, fmt, args...);
return _log(level::INFO, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::notice(const std::string& fmt, const Args&... args)
{
return log(level::NOTICE, fmt, args...);
return _log(level::NOTICE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::warn(const std::string& fmt, const Args&... args)
{
return log(level::WARN, fmt, args...);
return _log(level::WARN, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::error(const std::string& fmt, const Args&... args)
{
return log(level::ERR, fmt, args...);
return _log(level::ERR, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::critical(const std::string& fmt, const Args&... args)
{
return log(level::CRITICAL, fmt, args...);
return _log(level::CRITICAL, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::alert(const std::string& fmt, const Args&... args)
{
return log(level::ALERT, fmt, args...);
return _log(level::ALERT, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt, const Args&... args)
{
return log(level::EMERG, fmt, args...);
return _log(level::EMERG, fmt, args...);
}
//
// //API to support logger.info() << ".." calls
//
inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl)
{
bool msg_enabled = should_log(lvl);
details::line_logger l(this, lvl, msg_enabled);
return l;
}
inline spdlog::details::line_logger spdlog::logger::log()
{
return _log(level::ALWAYS);
}
inline spdlog::details::line_logger spdlog::logger::trace()
{
return _log(level::TRACE);
}
inline spdlog::details::line_logger spdlog::logger::debug()
{
return _log(level::DEBUG);
}
inline spdlog::details::line_logger spdlog::logger::info()
{
return _log(level::INFO);
}
inline spdlog::details::line_logger spdlog::logger::notice()
{
return _log(level::NOTICE);
}
inline spdlog::details::line_logger spdlog::logger::warn()
{
return _log(level::WARN);
}
inline spdlog::details::line_logger spdlog::logger::error()
{
return _log(level::ERR);
}
inline spdlog::details::line_logger spdlog::logger::critical()
{
return _log(level::CRITICAL);
}
inline spdlog::details::line_logger spdlog::logger::alert()
{
return _log(level::ALERT);
}
inline spdlog::details::line_logger spdlog::logger::emerg()
{
return _log(level::EMERG);
}
//
inline const std::string& spdlog::logger::name() const
{
return _name;
......
......@@ -65,7 +65,6 @@ public:
//Stop logging
void stop();
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(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger trace(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger debug(const std::string& fmt, const Args&... args);
......@@ -77,16 +76,31 @@ public:
template <typename... Args> details::line_logger alert(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger emerg(const std::string& fmt, const Args&... args);
//API to support logger.info() << ".." calls
details::line_logger log();
details::line_logger trace();
details::line_logger debug();
details::line_logger info();
details::line_logger notice();
details::line_logger warn();
details::line_logger error();
details::line_logger critical();
details::line_logger alert();
details::line_logger emerg();
void set_pattern(const std::string&);
void set_formatter(formatter_ptr);
protected:
virtual void _log_msg(details::log_msg& msg);
virtual void _log_msg(details::log_msg&);
virtual void _set_pattern(const std::string&);
virtual void _set_formatter(formatter_ptr);
virtual void _stop();
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);
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