small cleanup

This commit is contained in:
gabi 2014-12-08 00:09:54 +02:00
parent 65a1e5690c
commit d0dcc13f7c
2 changed files with 18 additions and 25 deletions

View File

@ -69,25 +69,27 @@ public:
}
}
template<typename T>
void write(const T& what)
{
if (_enabled)
{
_log_msg.raw << what;
}
}
template <typename... Args>
void write(const std::string& fmt, const Args&... args)
{
_log_msg.raw.write(fmt, args...);
if (!_enabled)
return;
try
{
_log_msg.raw.write(fmt, args...);
}
catch (const fmt::FormatError& e)
{
throw spdlog_ex(fmt::format("formatting error while processing format string '{}': {}", fmt, e.what()));
}
}
template<typename T>
line_logger& operator<<(const T& what)
{
write(what);
if (_enabled)
_log_msg.raw << what;
return *this;
}

View File

@ -71,18 +71,7 @@ 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);
if (msg_enabled)
{
try
{
l.write(fmt, args...);
}
catch(const fmt::FormatError& e)
{
throw spdlog_ex(fmt::format("formatting error while processing format string '{}': {}", fmt, e.what()));
}
}
l.write(fmt, args...);
return l;
}
@ -151,7 +140,6 @@ inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt
// //API to support logger.info() << ".." calls
//
inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl)
{
bool msg_enabled = should_log(lvl);
@ -213,7 +201,8 @@ inline spdlog::details::line_logger spdlog::logger::emerg()
//
// name and level
//
inline const std::string& spdlog::logger::name() const
{
return _name;
@ -239,7 +228,9 @@ inline void spdlog::logger::stop()
_stop();
}
/* protected virtual */
//
// protected virtual called at end of each user log call (if enabled) by the line_logger
//
inline void spdlog::logger::_log_msg(details::log_msg& msg)
{
_formatter->format(msg);