From 5ee14906c593120fc3ea6439cf6562a44c592a3e Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 30 Dec 2016 12:16:09 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 167 +++++++++++++++++++++++++++--------------------------- 1 file changed, 83 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 784373c8..d6bb81b0 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,9 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/include/spdlog) to your build tree and use a C++11 compiler ## Platforms - * Linux (gcc 4.8.1+, clang 3.5+) - * Windows (visual studio 2013+, cygwin/mingw with g++ 4.9.1+) + * Linux, FreeBSD, Solaris + * Windows (vc 2013+, cygwin/mingw with g++ 4.9.1+) * Mac OSX (clang 3.5+) - * Solaris (gcc 5.2.0+) * Android ##Features @@ -70,87 +69,87 @@ void user_defined_example(); void err_handler_example(); namespace spd = spdlog; -int main(int, char*[]) -{ - try - { - // Console logger with color - auto console = spd::stdout_color_mt("console"); - console->info("Welcome to spdlog!"); - console->error("Some error message with arg{}..", 1); - - // 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); - console->info("Support for floats {:03.2f}", 1.23456); - console->info("Positional args are {1} {0}..", "too", "supported"); - console->info("{:<30}", "left aligned"); - - - spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"); - - // Create basic file logger (not rotated) - auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic.txt"); - my_logger->info("Some log message"); - - // Create a file rotating logger with 5mb size max and 3 rotated files - auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/mylogfile", 1048576 * 5, 3); - for (int i = 0; i < 10; ++i) - rotating_logger->info("{} * {} equals {:>10}", i, i, i*i); - - // 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); - // trigger flush if the log severity is error or higher - daily_logger->flush_on(spd::level::err); - daily_logger->info(123.44); - - // Customize msg format for all messages - spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); - rotating_logger->info("This is another message with custom format"); - - - // Runtime log levels - spd::set_level(spd::level::info); //Set global log level to info - console->debug("This message shold not be displayed!"); - console->set_level(spd::level::debug); // Set specific logger's log level - console->debug("This message shold be displayed.."); - - // Compile time log levels - // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON - SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23); - SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23); - - // Asynchronous logging is very fast.. - // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous.. - async_example(); - - // syslog example. linux/osx only - syslog_example(); - - // android example. compile with NDK - android_example(); - - // Log user-defined types example - user_defined_example(); - - // Change default log error handler - err_handler_example(); - - // Apply a function on all registered loggers - spd::apply_all([&](std::shared_ptr l) - { - l->info("End of example."); - }); - - // Release and close all loggers - spdlog::drop_all(); - } - // Exceptions will only be thrown upon failed logger or sink construction (not during logging) - catch (const spd::spdlog_ex& ex) - { - std::cout << "Log init failed: " << ex.what() << std::endl; - return 1; - } +int main(int, char*[]) +{ + try + { + // Console logger with color + auto console = spd::stdout_color_mt("console"); + console->info("Welcome to spdlog!"); + console->error("Some error message with arg{}..", 1); + + // 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); + console->info("Support for floats {:03.2f}", 1.23456); + console->info("Positional args are {1} {0}..", "too", "supported"); + console->info("{:<30}", "left aligned"); + + + spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"); + + // Create basic file logger (not rotated) + auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic.txt"); + my_logger->info("Some log message"); + + // Create a file rotating logger with 5mb size max and 3 rotated files + auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/mylogfile", 1048576 * 5, 3); + for (int i = 0; i < 10; ++i) + rotating_logger->info("{} * {} equals {:>10}", i, i, i*i); + + // 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); + // trigger flush if the log severity is error or higher + daily_logger->flush_on(spd::level::err); + daily_logger->info(123.44); + + // Customize msg format for all messages + spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); + rotating_logger->info("This is another message with custom format"); + + + // Runtime log levels + spd::set_level(spd::level::info); //Set global log level to info + console->debug("This message shold not be displayed!"); + console->set_level(spd::level::debug); // Set specific logger's log level + console->debug("This message shold be displayed.."); + + // Compile time log levels + // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON + SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23); + SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23); + + // Asynchronous logging is very fast.. + // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous.. + async_example(); + + // syslog example. linux/osx only + syslog_example(); + + // android example. compile with NDK + android_example(); + + // Log user-defined types example + user_defined_example(); + + // Change default log error handler + err_handler_example(); + + // Apply a function on all registered loggers + spd::apply_all([&](std::shared_ptr l) + { + l->info("End of example."); + }); + + // Release and close all loggers + spdlog::drop_all(); + } + // Exceptions will only be thrown upon failed logger or sink construction (not during logging) + catch (const spd::spdlog_ex& ex) + { + std::cout << "Log init failed: " << ex.what() << std::endl; + return 1; + } } void async_example() From 58853d9c95aa8d16b100b30148118b72e3dad5e2 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 30 Dec 2016 12:16:44 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6bb81b0..182a6b07 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/inclu ## Platforms * Linux, FreeBSD, Solaris - * Windows (vc 2013+, cygwin/mingw with g++ 4.9.1+) + * Windows (vc 2013+, cygwin/mingw) * Mac OSX (clang 3.5+) * Android From 0a3a3f0ee2d9b55a1c968e26fe2115aff985e92a Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 31 Dec 2016 17:54:37 +0200 Subject: [PATCH 3/7] Updated comment on thread safety --- include/spdlog/logger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index ca0b4b2d..a2deb51d 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -5,7 +5,7 @@ #pragma once -// Thread safe logger +// Thread safe logger (except for set_pattern(..), set_formatter(..) and set_error_handler()) // Has name, log level, vector of std::shared sink pointers and formatter // Upon each log write the logger: // 1. Checks if its log level is enough to log the message From 38456118d0ff406d1cb9cecbdf91fa0b4bd27b82 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 31 Dec 2016 22:38:00 +0200 Subject: [PATCH 4/7] Update null_sink.h --- include/spdlog/sinks/null_sink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index 68bd9c94..1d427aa2 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -27,7 +27,7 @@ protected: }; typedef null_sink null_sink_st; -typedef null_sink null_sink_mt; +typedef null_sink null_sink_mt; } } From e7ec922c0a118b6001e1334408adbf81fc1f2b9b Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 6 Jan 2017 12:32:25 +0200 Subject: [PATCH 5/7] Update async_log_helper.h removed empty lines --- include/spdlog/details/async_log_helper.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 7b537361..deb8dcc6 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -229,8 +229,6 @@ inline spdlog::details::async_log_helper::~async_log_helper() inline void spdlog::details::async_log_helper::log(const details::log_msg& msg) { push_msg(async_msg(msg)); - - } inline void spdlog::details::async_log_helper::push_msg(details::async_log_helper::async_msg&& new_msg) @@ -246,7 +244,6 @@ inline void spdlog::details::async_log_helper::push_msg(details::async_log_helpe } while (!_q.enqueue(std::move(new_msg))); } - } // optionally wait for the queue be empty and request flush from the sinks @@ -281,10 +278,8 @@ inline void spdlog::details::async_log_helper::worker_loop() // return true if this thread should still be active (while no terminate msg was received) inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_point& last_pop, log_clock::time_point& last_flush) { - async_msg incoming_async_msg; - if (_q.dequeue(incoming_async_msg)) { last_pop = details::os::now(); @@ -361,7 +356,6 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_ if (time_since_op <= microseconds(100)) return std::this_thread::yield(); - // sleep for 20 ms upto 200 ms if (time_since_op <= milliseconds(200)) return sleep_for(milliseconds(20)); @@ -378,13 +372,7 @@ inline void spdlog::details::async_log_helper::wait_empty_q() { sleep_or_yield(details::os::now(), last_op); } - } - - - - - From 2ec188041f9cdff9cb098bb9893f2685d609d6c4 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 6 Jan 2017 12:39:12 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 182a6b07..bca645c2 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/inclu * Daily log files. * Console logging (colors supported). * syslog. + * Windows debugger (```OutputDebugString(..)```) * Easily extendable with custom log targets (just implement a single function in the [sink](include/spdlog/sinks/sink.h) interface). * Severity based filtering - threshold levels can be modified in runtime as well as in compile time. From 50c181ea4baac473ad3c48c3d3aebb05b3f06d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Tacza=C5=82a?= Date: Wed, 11 Jan 2017 09:28:28 +0100 Subject: [PATCH 7/7] Add prefix for BUILD_TESTING cmake option This is helpful when using spdlog as a dependency (git submodule) when a master project is not interested in spdlog tests. Using "BUILD_TESTING" name may create a confusion. Extra: BUILD_EXAMPLE variable already have a prefix. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3976befc..61c45b5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ endif() add_library(spdlog INTERFACE) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) +option(SPDLOG_BUILD_TESTING "Build spdlog tests" ON) target_include_directories( spdlog @@ -27,12 +28,11 @@ target_include_directories( set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include") -include(CTest) if(SPDLOG_BUILD_EXAMPLES) add_subdirectory(example) endif() -if(BUILD_TESTING) +if(SPDLOG_BUILD_TESTING) add_subdirectory(tests) endif()