diff --git a/example/example.cpp b/example/example.cpp index f0f5db4a..f8edaf79 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -1,4 +1,4 @@ -// +// // Copyright(c) 2015 Gabi Melman. // Distributed under the MIT License (http://opensource.org/licenses/MIT) // @@ -11,6 +11,10 @@ #define SPDLOG_DEBUG_ON + +#include "spdlog/sinks/color_sinks.h" +#include "spdlog/async.h" + #include "spdlog/spdlog.h" #include @@ -25,13 +29,28 @@ void err_handler_example(); namespace spd = spdlog; int main(int, char *[]) { + try { - // Console logger with color - auto console = spdlog::console("console"); + + // Console logger with color + spd::init_thread_pool(8192, 3); + auto console = spdlog::stdout_color_mt("console1"); + auto console2 = spdlog::stderr_logger_mt("console2"); + //auto console3 = spdlog::stdout_color_mt("console3"); + for (int i = 0; i < 10000; i++) + { + console->info("CONSOLE1"); + console2->warn("CONSOLE2"); + } + spdlog::drop_all(); + return 0; + + console->info("Welcome to spdlog!"); + console->info("Welcome to spdlog!"); console->error("Some error message with arg: {}", 1); - + err_handler_example(); // Formatting examples console->warn("Easy padding in numbers like {:08d}", 12); console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); @@ -59,7 +78,8 @@ int main(int, char *[]) daily_logger->info(123.44); // Customize msg format for all messages - spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v"); + //spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v"); //crash + console->info("This an info message with custom format"); console->error("This an error message with custom format"); @@ -88,7 +108,7 @@ int main(int, char *[]) user_defined_example(); // Change default log error handler - err_handler_example(); + err_handler_example(); // Apply a function on all registered loggers spd::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); @@ -162,6 +182,7 @@ void user_defined_example() void err_handler_example() { // can be set globaly or per logger(logger->set_error_handler(..)) - spdlog::set_error_handler([](const std::string &msg) { std::cerr << "my err handler: " << msg << std::endl; }); - spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3); + spdlog::set_error_handler([](const std::string &msg) { spd::get("console")->error("*******my err handler: {}", msg); }); + spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3); + //spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3); } diff --git a/example/example.vcxproj b/example/example.vcxproj index 63db2b5d..e0c1335d 100644 --- a/example/example.vcxproj +++ b/example/example.vcxproj @@ -27,6 +27,7 @@ + diff --git a/include/spdlog/details/traits.h b/include/spdlog/details/traits.h index 75fa3987..0b7df424 100644 --- a/include/spdlog/details/traits.h +++ b/include/spdlog/details/traits.h @@ -4,6 +4,7 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) // +#include "stdio.h" namespace spdlog { namespace details { struct console_stdout_trait diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 9c53e90e..bdb41f65 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -13,7 +13,8 @@ // 3. Pass the formatted message to its sinks to performa the actual logging #include "common.h" -#include "sinks/base_sink.h" +#include "sinks/sink.h" +#include "formatter.h" #include #include diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index e377c7c0..8bda8cdf 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -5,10 +5,12 @@ #pragma once +#include "sink.h" #include "../common.h" #include "../details/null_mutex.h" #include "../details/traits.h" + #include #include #include