From 5650f10babe09dd076361047e114b596fdbe15da Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 3 Jul 2016 03:43:55 +0300 Subject: [PATCH] DEPRECATED: operator<< API --- README.md | 15 ++------------ bench/spdlog-async.cpp | 2 +- bench/spdlog-bench-mt.cpp | 2 +- bench/spdlog-bench.cpp | 2 +- example/example.cpp | 16 +-------------- include/spdlog/common.h | 8 ++++++++ include/spdlog/details/line_logger_fwd.h | 26 ++++++++++++------------ include/spdlog/details/logger_impl.h | 2 +- tests/format.cpp | 17 ++-------------- tests/tests.vcxproj | 4 ++-- 10 files changed, 32 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 571727e8..a5a1aff1 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,7 @@ int main(int, char* []) // console logger (multithreaded and with color) auto console = spd::stdout_logger_mt("console", true); console->info("Welcome to spdlog!") ; - console->info("An info message example {}..", 1); - console->info() << "Streams are supported too " << 1; + console->info("An info message example {}..", 1); //Formatting examples console->info("Easy padding in numbers like {:08d}", 12); @@ -129,7 +128,7 @@ int main(int, char* []) size_t q_size = 8192; //queue size must be power of 2 spdlog::set_async_mode(q_size); auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt"); - async_file->info() << "This is async log.." << "Should be very fast!"; + async_file->info("This is async log..Should be very fast!"); // // syslog example. linux only.. @@ -148,16 +147,6 @@ int main(int, char* []) } -// Example of user defined class with operator<< -class some_class {}; -std::ostream& operator<<(std::ostream& os, const some_class& c) { return os << "some_class"; } - -void custom_class_example() -{ - some_class c; - spdlog::get("console")->info("custom class with operator<<: {}..", c); - spdlog::get("console")->info() << "custom class with operator<<: " << c << ".."; -} ``` ## Documentation diff --git a/bench/spdlog-async.cpp b/bench/spdlog-async.cpp index 0e2c118c..f788e4df 100644 --- a/bench/spdlog-async.cpp +++ b/bench/spdlog-async.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) { int counter = ++msg_counter; if (counter > howmany) break; - logger->info() << "spdlog message #" << counter << ": This is some text for your pleasure"; + logger->info("spdlog message #{}: This is some text for your pleasure", counter); } })); } diff --git a/bench/spdlog-bench-mt.cpp b/bench/spdlog-bench-mt.cpp index 0492306d..28f87807 100644 --- a/bench/spdlog-bench-mt.cpp +++ b/bench/spdlog-bench-mt.cpp @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) { int counter = ++msg_counter; if (counter > howmany) break; - logger->info() << "spdlog message #" << counter << ": This is some text for your pleasure"; + logger->info("spdlog message #{}: This is some text for your pleasure", counter); } })); } diff --git a/bench/spdlog-bench.cpp b/bench/spdlog-bench.cpp index 700a82bb..4ac95f6a 100644 --- a/bench/spdlog-bench.cpp +++ b/bench/spdlog-bench.cpp @@ -15,6 +15,6 @@ int main(int, char* []) logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); for(int i = 0 ; i < howmany; ++i) - logger->info() << "spdlog message #" << i << ": This is some text for your pleasure"; + logger->info("spdlog message #{} : This is some text for your pleasure", i); return 0; } diff --git a/example/example.cpp b/example/example.cpp index e3d22dbb..d0838433 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -23,7 +23,6 @@ int main(int, char*[]) auto console = spd::stdout_logger_mt("console", true); console->info("Welcome to spdlog!"); console->info("An info message example {}..", 1); - console->info() << "Streams are supported too " << 1; // Formatting examples console->info("Easy padding in numbers like {:08d}", 12); @@ -55,6 +54,7 @@ int main(int, char*[]) // Create a daily logger - a new file is created every day on 2:30am auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30); + daily_logger->info(123.44); // Customize msg format for all messages spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); @@ -107,17 +107,3 @@ void syslog_example() } -// Example of user defined class with operator<< -class some_class {}; -std::ostream& operator<<(std::ostream& os, const some_class&) -{ - return os << "some_class"; -} - -void custom_class_example() -{ - some_class c; - spdlog::get("console")->info("custom class with operator<<: {}..", c); - spdlog::get("console")->info() << "custom class with operator<<: " << c << ".."; -} - diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1e446555..992b3008 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -27,6 +27,14 @@ #define SPDLOG_CONSTEXPR constexpr #endif +#if defined(__GNUC__) || defined(__clang__) +#define DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#else +#pragma message("DEPRECATED") +#define DEPRECATED +#endif namespace spdlog { diff --git a/include/spdlog/details/line_logger_fwd.h b/include/spdlog/details/line_logger_fwd.h index a8bc58ff..eabc6eff 100644 --- a/include/spdlog/details/line_logger_fwd.h +++ b/include/spdlog/details/line_logger_fwd.h @@ -49,21 +49,21 @@ public: // // 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); + DEPRECATED line_logger& operator<<(const char* what); + DEPRECATED line_logger& operator<<(const std::string& what); + DEPRECATED line_logger& operator<<(int what); + DEPRECATED line_logger& operator<<(unsigned int what); + DEPRECATED line_logger& operator<<(long what); + DEPRECATED line_logger& operator<<(unsigned long what); + DEPRECATED line_logger& operator<<(long long what); + DEPRECATED line_logger& operator<<(unsigned long long what); + DEPRECATED line_logger& operator<<(double what); + DEPRECATED line_logger& operator<<(long double what); + DEPRECATED line_logger& operator<<(float what); + DEPRECATED line_logger& operator<<(char what); //Support user types which implements operator<< template - line_logger& operator<<(const T& what); + DEPRECATED line_logger& operator<<(const T& what); void disable(); bool is_enabled() const; diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 9f2f13d7..3eef7fec 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -74,7 +74,7 @@ inline spdlog::details::line_logger spdlog::logger::_log_if_enabled(level::level { bool msg_enabled = should_log(lvl); details::line_logger l(this, lvl, msg_enabled); - l << msg; + l.write("{}", msg); return l; } diff --git a/tests/format.cpp b/tests/format.cpp index af8ee63b..6c7f8d9b 100644 --- a/tests/format.cpp +++ b/tests/format.cpp @@ -11,7 +11,7 @@ std::string log_info(const T& what, spdlog::level::level_enum logger_level = spd spdlog::logger oss_logger("oss", oss_sink); oss_logger.set_level(logger_level); oss_logger.set_pattern("%v"); - oss_logger.info() << what; + oss_logger.info(what); return oss.str().substr(0, oss.str().length() - spdlog::details::os::eol_size); } @@ -21,19 +21,6 @@ std::string log_info(const T& what, spdlog::level::level_enum logger_level = spd -//User defined class with operator<< -struct some_logged_class -{ - some_logged_class(const std::string val) :value(val) {}; - std::string value; -}; -std::ostream& operator<<(std::ostream& os, const some_logged_class& c) -{ - return os << c.value; -} - - - TEST_CASE("basic_logging ", "[basic_logging]") { //const char @@ -49,7 +36,7 @@ TEST_CASE("basic_logging ", "[basic_logging]") REQUIRE(log_info(5.6) == "5.6"); //User defined class - REQUIRE(log_info(some_logged_class("some_val")) == "some_val"); + //REQUIRE(log_info(some_logged_class("some_val")) == "some_val"); } diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj index f05c1628..2e72e181 100644 --- a/tests/tests.vcxproj +++ b/tests/tests.vcxproj @@ -26,7 +26,7 @@ Application true - v140 + v120 MultiByte @@ -38,7 +38,7 @@ Application false - v140 + v120 true MultiByte