Commit 45628c8e authored by gabi's avatar gabi

logger main interface now is in the form logger.info(fmt, args)

parent eaa61ed4
......@@ -400,7 +400,8 @@ int fmt::internal::CharTraits<wchar_t>::format_float(
swprintf(buffer, size, format, width, precision, value);
}
const char fmt::internal::DIGITS[] =
template <typename T>
const char fmt::internal::BasicData<T>::DIGITS[] =
"0001020304050607080910111213141516171819"
"2021222324252627282930313233343536373839"
"4041424344454647484950515253545556575859"
......@@ -418,8 +419,13 @@ const char fmt::internal::DIGITS[] =
factor * 100000000, \
factor * 1000000000
const uint32_t fmt::internal::POWERS_OF_10_32[] = { 0, FMT_POWERS_OF_10(1) };
const uint64_t fmt::internal::POWERS_OF_10_64[] = {
template <typename T>
const uint32_t fmt::internal::BasicData<T>::POWERS_OF_10_32[] = {
0, FMT_POWERS_OF_10(1)
};
template <typename T>
const uint64_t fmt::internal::BasicData<T>::POWERS_OF_10_64[] = {
0,
FMT_POWERS_OF_10(1),
FMT_POWERS_OF_10(ULongLong(1000000000)),
......@@ -1163,4 +1169,4 @@ template int fmt::internal::CharTraits<wchar_t>::format_float(
#if _MSC_VER
# pragma warning(pop)
#endif
#endif
\ No newline at end of file
This diff is collapsed.
......@@ -79,6 +79,12 @@ public:
}
}
template <typename... Args>
void write(const std::string& fmt, const Args&... args)
{
_log_msg.raw.write(fmt, args...);
}
template<typename T>
line_logger& operator<<(const T& what)
{
......@@ -86,6 +92,7 @@ public:
return *this;
}
void disable()
{
_enabled = false;
......
......@@ -66,73 +66,73 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::log(level::level_enum lvl, 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);
if (msg_enabled)
_variadic_log(l, args...);
l.write(fmt, args...);
return l;
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::log(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::log(const std::string& fmt, const Args&... args)
{
return log(level::ALWAYS, args...);
return log(level::ALWAYS, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::trace(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::trace(const std::string& fmt, const Args&... args)
{
return log(level::TRACE, args...);
return log(level::TRACE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::debug(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::debug(const std::string& fmt, const Args&... args)
{
return log(level::DEBUG, args...);
return log(level::DEBUG, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::info(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::info(const std::string& fmt, const Args&... args)
{
return log(level::INFO, args...);
return log(level::INFO, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::notice(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::notice(const std::string& fmt, const Args&... args)
{
return log(level::NOTICE, args...);
return log(level::NOTICE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::warn(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::warn(const std::string& fmt, const Args&... args)
{
return log(level::WARN, args...);
return log(level::WARN, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::error(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::error(const std::string& fmt, const Args&... args)
{
return log(level::ERR, args...);
return log(level::ERR, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::critical(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::critical(const std::string& fmt, const Args&... args)
{
return log(level::CRITICAL, args...);
return log(level::CRITICAL, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::alert(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::alert(const std::string& fmt, const Args&... args)
{
return log(level::ALERT, args...);
return log(level::ALERT, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::emerg(const Args&... args)
inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt, const Args&... args)
{
return log(level::EMERG, args...);
return log(level::EMERG, fmt, args...);
}
inline const std::string& spdlog::logger::name() const
......@@ -182,24 +182,7 @@ inline void spdlog::logger::_stop()
set_level(level::OFF);
}
/* private functions */
inline void spdlog::logger::_variadic_log(spdlog::details::line_logger&) {}
template <typename Last>
inline void spdlog::logger::_variadic_log(spdlog::details::line_logger& l, const Last& last)
{
l.write(last);
}
template <typename First, typename... Rest>
inline void spdlog::logger::_variadic_log(spdlog::details::line_logger& l, const First& first, const Rest&... rest)
{
l.write(first);
l.write(' ');
_variadic_log(l, rest...);
}
......@@ -34,7 +34,6 @@
#include<vector>
#include<memory>
#include "sinks/base_sink.h"
#include "sinks/async_sink.h"
#include "common.h"
namespace spdlog
......@@ -66,17 +65,17 @@ public:
//Stop logging
void stop();
template <typename... Args> details::line_logger log(level::level_enum lvl, const Args&... args);
template <typename... Args> details::line_logger log(const Args&... args);
template <typename... Args> details::line_logger trace(const Args&... args);
template <typename... Args> details::line_logger debug(const Args&... args);
template <typename... Args> details::line_logger info(const Args&... args);
template <typename... Args> details::line_logger notice(const Args&... args);
template <typename... Args> details::line_logger warn(const Args&... args);
template <typename... Args> details::line_logger error(const Args&... args);
template <typename... Args> details::line_logger critical(const Args&... args);
template <typename... Args> details::line_logger alert(const Args&... args);
template <typename... Args> details::line_logger emerg(const Args&... args);
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);
template <typename... Args> details::line_logger info(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger notice(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger warn(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger error(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger critical(const std::string& fmt, const Args&... args);
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);
void set_pattern(const std::string&);
......@@ -96,13 +95,6 @@ protected:
formatter_ptr _formatter;
std::atomic_int _level;
private:
void _variadic_log(details::line_logger& l);
template <typename Last>
inline void _variadic_log(spdlog::details::line_logger& l, const Last& last);
template <typename First, typename... Rest>
void _variadic_log(details::line_logger&l, const First& first, const Rest&... rest);
};
}
......
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