From 94deae042cfa0cd9b09d3fd750465287cc848fe9 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 28 Jan 2015 13:19:37 +0200 Subject: [PATCH] Better support for operator<< --- include/spdlog/details/line_logger.h | 57 ++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/include/spdlog/details/line_logger.h b/include/spdlog/details/line_logger.h index 3343a164..05db2633 100644 --- a/include/spdlog/details/line_logger.h +++ b/include/spdlog/details/line_logger.h @@ -80,6 +80,16 @@ public: } } + // + // Support for format string with variadic args + // + + + void write(const char* what) + { + if (_enabled) + _log_msg.raw << what; + } template void write(const char* fmt, const Args&... args) @@ -96,80 +106,96 @@ public: } } - void write(const char* what) + + // + // Support for operator<< + // + line_logger& operator<<(const char* what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(const std::string& what) + line_logger& operator<<(const std::string& what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(int what) + line_logger& operator<<(int what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(unsigned int what) + line_logger& operator<<(unsigned int what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(long what) + line_logger& operator<<(long what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(unsigned long what) + line_logger& operator<<(unsigned long what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(long long what) + line_logger& operator<<(long long what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(unsigned long long what) + line_logger& operator<<(unsigned long long what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(double what) + line_logger& operator<<(double what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(long double what) + line_logger& operator<<(long double what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(float what) + line_logger& operator<<(float what) { if (_enabled) _log_msg.raw << what; + return *this; } - void write(char what) + line_logger& operator<<(char what) { if (_enabled) _log_msg.raw << what; + return *this; } - - + + //Support user types which implements operator<< template line_logger& operator<<(const T& what) { @@ -178,14 +204,13 @@ public: return *this; } - + void disable() { _enabled = false; } - private: logger* _callback_logger; log_msg _log_msg;