diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index a68b60ed..c60763a0 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -15,12 +15,11 @@ // 3. will throw spdlog_ex upon log exceptions // Upong destruction, logs all remaining messages in the queue before destructing.. +#include +#include + #include #include -#include "common.h" -#include "logger.h" -#include "spdlog.h" - namespace spdlog { @@ -69,4 +68,5 @@ private: } -#include "./details/async_logger_impl.h" +#include + diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 3179d31f..90a6b95c 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -14,17 +14,18 @@ #pragma once +#include +#include +#include +#include +#include +#include +#include + #include #include #include - -#include "../common.h" -#include "../sinks/sink.h" -#include "./mpmc_bounded_q.h" -#include "./log_msg.h" -#include "./format.h" -#include "./os.h" - +#include namespace spdlog { diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index 83ec41b0..e2a9239b 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -8,7 +8,8 @@ // Async Logger implementation // Use an async_sink (queue per logger) to perform the logging in a worker thread -#include "./async_log_helper.h" +#include +#include template diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 0a544ca1..62323c4d 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -10,13 +10,12 @@ // Can be set to auto flush on every line // Throw spdlog_ex exception on errors +#include +#include + #include #include #include -#include "os.h" -#include "log_msg.h" - - namespace spdlog { diff --git a/include/spdlog/details/line_logger.h b/include/spdlog/details/line_logger.h deleted file mode 100644 index 0d8a535e..00000000 --- a/include/spdlog/details/line_logger.h +++ /dev/null @@ -1,201 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// -#pragma once -#include -#include "../common.h" -#include "../logger.h" - -// Line logger class - aggregates operator<< calls to fast ostream -// and logs upon destruction - -namespace spdlog -{ -namespace details -{ -class line_logger -{ -public: - line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled): - _callback_logger(callback_logger), - _log_msg(msg_level), - _enabled(enabled) - {} - - // No copy intended. Only move - line_logger(const line_logger& other) = delete; - line_logger& operator=(const line_logger&) = delete; - line_logger& operator=(line_logger&&) = delete; - - - line_logger(line_logger&& other) : - _callback_logger(other._callback_logger), - _log_msg(std::move(other._log_msg)), - _enabled(other._enabled) - { - other.disable(); - } - - //Log the log message using the callback logger - ~line_logger() - { - if (_enabled) - { -#ifndef SPDLOG_NO_NAME - _log_msg.logger_name = _callback_logger->name(); -#endif -#ifndef SPDLOG_NO_DATETIME - _log_msg.time = os::now(); -#endif - -#ifndef SPDLOG_NO_THREAD_ID - _log_msg.thread_id = os::thread_id(); -#endif - _callback_logger->_log_msg(_log_msg); - } - } - - // - // 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) - { - 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())); - } - } - - - // - // Support for operator<< - // - line_logger& operator<<(const char* what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(const std::string& what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(int what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(unsigned int what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - - line_logger& operator<<(long what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(unsigned long what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(long long what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(unsigned long long what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(double what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(long double what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - line_logger& operator<<(float what) - { - if (_enabled) - _log_msg.raw << what; - return *this; - } - - 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) - { - if (_enabled) - _log_msg.raw.write("{}", what); - return *this; - } - - - void disable() - { - _enabled = false; - } - - bool is_enabled() const - { - return _enabled; - } - - -private: - logger* _callback_logger; - log_msg _log_msg; - bool _enabled; -}; -} //Namespace details -} // Namespace spdlog diff --git a/include/spdlog/details/line_logger_fwd.h b/include/spdlog/details/line_logger_fwd.h new file mode 100644 index 00000000..a8bc58ff --- /dev/null +++ b/include/spdlog/details/line_logger_fwd.h @@ -0,0 +1,78 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// +#pragma once + +#include +#include + +#include + +// Line logger class - aggregates operator<< calls to fast ostream +// and logs upon destruction + +namespace spdlog +{ + +// Forward declaration +class logger; + +namespace details +{ +class line_logger +{ +public: + line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled); + + // No copy intended. Only move + line_logger(const line_logger& other) = delete; + line_logger& operator=(const line_logger&) = delete; + line_logger& operator=(line_logger&&) = delete; + + + line_logger(line_logger&& other); + + //Log the log message using the callback logger + ~line_logger(); + + // + // Support for format string with variadic args + // + + + void write(const char* what); + + template + void write(const char* fmt, const Args&... args); + + // + // Support for operator<< + // + line_logger& operator<<(const char* what); + line_logger& operator<<(const std::string& what); + line_logger& operator<<(int what); + line_logger& operator<<(unsigned int what); + line_logger& operator<<(long what); + line_logger& operator<<(unsigned long what); + line_logger& operator<<(long long what); + line_logger& operator<<(unsigned long long what); + line_logger& operator<<(double what); + line_logger& operator<<(long double what); + line_logger& operator<<(float what); + line_logger& operator<<(char what); + //Support user types which implements operator<< + template + line_logger& operator<<(const T& what); + + void disable(); + bool is_enabled() const; + +private: + logger* _callback_logger; + log_msg _log_msg; + bool _enabled; +}; +} //Namespace details +} // Namespace spdlog + diff --git a/include/spdlog/details/line_logger_impl.h b/include/spdlog/details/line_logger_impl.h new file mode 100644 index 00000000..88f88b5b --- /dev/null +++ b/include/spdlog/details/line_logger_impl.h @@ -0,0 +1,182 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// +#pragma once +#include + +#include +#include +#include + +// Line logger class - aggregates operator<< calls to fast ostream +// and logs upon destruction + +inline spdlog::details::line_logger::line_logger(logger* callback_logger, level::level_enum msg_level, bool enabled): + _callback_logger(callback_logger), + _log_msg(msg_level), + _enabled(enabled) +{} + +inline spdlog::details::line_logger::line_logger(line_logger&& other) : + _callback_logger(other._callback_logger), + _log_msg(std::move(other._log_msg)), + _enabled(other._enabled) +{ + other.disable(); +} + +//Log the log message using the callback logger +inline spdlog::details::line_logger::~line_logger() +{ + if (_enabled) + { +#ifndef SPDLOG_NO_NAME + _log_msg.logger_name = _callback_logger->name(); +#endif +#ifndef SPDLOG_NO_DATETIME + _log_msg.time = os::now(); +#endif + +#ifndef SPDLOG_NO_THREAD_ID + _log_msg.thread_id = os::thread_id(); +#endif + _callback_logger->_log_msg(_log_msg); + } +} + +// +// Support for format string with variadic args +// + + +inline void spdlog::details::line_logger::write(const char* what) +{ + if (_enabled) + _log_msg.raw << what; +} + +template +inline void spdlog::details::line_logger::write(const char* fmt, const Args&... 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())); + } +} + + +// +// Support for operator<< +// +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const char* what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const std::string& what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(int what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned int what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned long what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long long what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(unsigned long long what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(double what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(long double what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(float what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(char what) +{ + if (_enabled) + _log_msg.raw << what; + return *this; +} + +//Support user types which implements operator<< +template +inline spdlog::details::line_logger& spdlog::details::line_logger::operator<<(const T& what) +{ + if (_enabled) + _log_msg.raw.write("{}", what); + return *this; +} + + +inline void spdlog::details::line_logger::disable() +{ + _enabled = false; +} + +inline bool spdlog::details::line_logger::is_enabled() const +{ + return _enabled; +} + diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index bae2fb2a..b0f00f29 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -5,9 +5,10 @@ #pragma once +#include +#include + #include -#include "../common.h" -#include "./format.h" namespace spdlog { diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 7f0171e6..f6292f37 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -5,7 +5,7 @@ #pragma once -#include "./line_logger.h" +#include // create logger with given name, sinks and the default pattern formatter // all other ctors will call this one @@ -296,4 +296,4 @@ inline void spdlog::logger::flush() { for (auto& sink : _sinks) sink->flush(); -} \ No newline at end of file +} diff --git a/include/spdlog/details/mpmc_bounded_q.h b/include/spdlog/details/mpmc_bounded_q.h index 26bda5fa..3115e706 100644 --- a/include/spdlog/details/mpmc_bounded_q.h +++ b/include/spdlog/details/mpmc_bounded_q.h @@ -43,8 +43,9 @@ Distributed under the MIT License (http://opensource.org/licenses/MIT) #pragma once +#include + #include -#include "../common.h" namespace spdlog { diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 30e2f6d9..d8328c39 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -4,9 +4,11 @@ // #pragma once -#include -#include -#include +#include + +#include +#include +#include #ifdef _WIN32 # ifndef WIN32_LEAN_AND_MEAN @@ -26,8 +28,6 @@ #include #endif -#include "../common.h" - namespace spdlog { namespace details diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index 92ccc376..8738324c 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -5,16 +5,16 @@ #pragma once +#include +#include +#include + #include #include #include #include #include - - -#include "../formatter.h" -#include "./log_msg.h" -#include "./os.h" +#include namespace spdlog { diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index a26db799..c5171ec5 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -10,16 +10,16 @@ // If user requests a non existing logger, nullptr will be returned // This class is thread safe +#include +#include +#include +#include + #include #include #include #include -#include "./null_mutex.h" -#include "../logger.h" -#include "../async_logger.h" -#include "../common.h" - namespace spdlog { namespace details diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index c8cc2168..8bc1894c 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -8,10 +8,11 @@ // // Global registry functions // -#include "registry.h" -#include "../sinks/file_sinks.h" -#include "../sinks/stdout_sinks.h" -#include "../sinks/syslog_sink.h" +#include +#include +#include +#include +#include inline void spdlog::register_logger(std::shared_ptr logger) { diff --git a/include/spdlog/formatter.h b/include/spdlog/formatter.h index cf0af012..5a5bad2d 100644 --- a/include/spdlog/formatter.h +++ b/include/spdlog/formatter.h @@ -5,7 +5,10 @@ #pragma once -#include "details/log_msg.h" +#include + +#include + namespace spdlog { namespace details @@ -36,5 +39,5 @@ private: }; } -#include "details/pattern_formatter_impl.h" +#include diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index a756ea3a..76770096 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -12,19 +12,16 @@ // 2. Format the message using the formatter function // 3. Pass the formatted message to its sinks to performa the actual logging -#include -#include -#include "sinks/base_sink.h" -#include "common.h" +#include +#include +#include + +#include +#include namespace spdlog { -namespace details -{ -class line_logger; -} - class logger { public: @@ -110,4 +107,6 @@ protected: }; } -#include "./details/logger_impl.h" +#include +#include + diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index d872c1ba..c6cbc272 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -7,12 +7,13 @@ #if defined(__ANDROID__) -#include -#include "base_sink.h" -#include "../details/null_mutex.h" +#include +#include #include +#include + namespace spdlog { namespace sinks diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index e5874823..1fb8ed9b 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -10,14 +10,14 @@ // all locking is taken care of here so no locking needed by the implementors.. // -#include -#include -#include -#include "./sink.h" -#include "../formatter.h" -#include "../common.h" -#include "../details/log_msg.h" +#include +#include +#include +#include +#include +#include +#include namespace spdlog { diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index dec24e39..1f3884b1 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -5,16 +5,16 @@ #pragma once +#include +#include +#include +#include + #include #include #include #include -#include "../details/log_msg.h" -#include "../details/null_mutex.h" -#include "./base_sink.h" -#include "./sink.h" - namespace spdlog { namespace sinks diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 136f63e2..c6f9a2df 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -5,11 +5,12 @@ #pragma once +#include +#include +#include +#include + #include -#include "base_sink.h" -#include "../details/null_mutex.h" -#include "../details/file_helper.h" -#include "../details/format.h" namespace spdlog { diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index ea32df48..68bd9c94 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -4,10 +4,11 @@ // #pragma once -#include -#include "./base_sink.h" -#include "../details/null_mutex.h" +#include +#include + +#include namespace spdlog { diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 318643c9..f9337f6b 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -5,13 +5,13 @@ #pragma once +#include +#include + #include #include #include -#include "../details/null_mutex.h" -#include "./base_sink.h" - namespace spdlog { namespace sinks diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 09f1021c..39dc771a 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -6,7 +6,7 @@ #pragma once -#include "../details/log_msg.h" +#include namespace spdlog { diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index fd09b76a..ddb32b64 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -5,10 +5,11 @@ #pragma once +#include +#include + #include #include -#include "./ostream_sink.h" -#include "../details/null_mutex.h" namespace spdlog { diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index ed1e2c40..5d7ccf87 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -7,14 +7,14 @@ #if defined(__linux__) || defined(__APPLE__) +#include +#include +#include + #include #include #include -#include "./sink.h" -#include "../common.h" -#include "../details/log_msg.h" - namespace spdlog { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 0748cd8f..dda736ff 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -8,9 +8,9 @@ #pragma once -#include "tweakme.h" -#include "common.h" -#include "logger.h" +#include +#include +#include namespace spdlog { @@ -132,4 +132,4 @@ void drop_all(); } -#include "details/spdlog_impl.h" +#include