From fe01be493a8bb5e038a192a85a18b830f94f2c06 Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Sat, 23 Apr 2022 20:59:44 +0100 Subject: [PATCH] Add template keyword to the log macro. Add option to to append date and time to the file. --- CHANGELOG.md | 4 +++- quill/include/quill/LogLevel.h | 1 + quill/include/quill/Quill.h | 3 ++- quill/include/quill/detail/LogMacros.h | 17 ++++++++++------- quill/include/quill/handlers/FileHandler.h | 1 + quill/src/handlers/FileHandler.cpp | 5 +++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ca5a719..07a90a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,11 +20,13 @@ - [v1.1.0](#v1.1.0) - [v1.0.0](#v1.0.0) -## v1.7.1 (in progress) +## v1.7.1 **Improvements/Fixes** - Fix support for wide characters on Windows ([#168](https://github.com/odygrd/quill/issues/168)) +- Fix compilation error when `Quill::Logger*` is stored as a class member in templated classes +- Add `FilenameAppend::DateTime` as an option when creating a file handler ## v1.7.0 diff --git a/quill/include/quill/LogLevel.h b/quill/include/quill/LogLevel.h index 07fbe7d2..55b40855 100644 --- a/quill/include/quill/LogLevel.h +++ b/quill/include/quill/LogLevel.h @@ -37,6 +37,7 @@ QUILL_NODISCARD char const* to_string(LogLevel log_level); /** * Converts a string to a LogLevel enum value * @param log_level the log level string to convert + * "tracel3", "tracel2", "tracel1", "debug", "info", "warning", "error", "backtrace", "none" * @return the corresponding LogLevel enum value */ QUILL_NODISCARD LogLevel from_string(std::string log_level); diff --git a/quill/include/quill/Quill.h b/quill/include/quill/Quill.h index 8a89e7b3..b472ec21 100644 --- a/quill/include/quill/Quill.h +++ b/quill/include/quill/Quill.h @@ -115,7 +115,8 @@ QUILL_NODISCARD QUILL_ATTRIBUTE_COLD Handler* create_handler(filename_t const& h * Creates or returns an existing handler to a file. * If the file is already opened the existing handler for this file is returned instead * @param filename the name of the file - * @param append_to_filename additional info to append to the name of the file. FilenameAppend::None or FilenameAppend::Date + * @param append_to_filename additional info to append to the name of the file. + * FilenameAppend::None, FilenameAppend::Date, FilenameAppend::DateTime * @param mode Used only when the file is opened for the first time. Otherwise the value is ignored * If no value is specified during the file creation "a" is used as default. * @return A handler to a file diff --git a/quill/include/quill/detail/LogMacros.h b/quill/include/quill/detail/LogMacros.h index 9d856fe3..045eb7d8 100644 --- a/quill/include/quill/detail/LogMacros.h +++ b/quill/include/quill/detail/LogMacros.h @@ -30,7 +30,7 @@ // Main Log Macros #if defined(QUILL_NOFN_MACROS) -// clang-format off + // clang-format off #define QUILL_LOGGER_CALL_NOFN(likelyhood, logger, log_statement_level, fmt, ...) \ do { \ struct { \ @@ -39,11 +39,12 @@ "n/a", fmt, log_statement_level}; } \ } anonymous_log_record_info; \ \ - if (likelyhood(logger->should_log())) \ + if (likelyhood(logger->template should_log())) \ { \ constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \ constexpr bool is_backtrace_log_record {false}; \ - logger->log \ + logger->template log \ (FMT_STRING(fmt), ##__VA_ARGS__); \ } \ } while (0) @@ -60,11 +61,12 @@ function_name, fmt, log_statement_level}; } \ } anonymous_log_record_info; \ \ - if (likelyhood(logger->should_log())) \ + if (likelyhood(logger->template should_log())) \ { \ constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \ constexpr bool is_backtrace_log_record {false}; \ - logger->log \ + logger->template log \ (FMT_STRING(fmt), ##__VA_ARGS__); \ } \ } while (0) @@ -78,11 +80,12 @@ function_name, fmt, quill::LogLevel::Backtrace}; } \ } anonymous_log_record_info; \ \ - if (QUILL_LIKELY(logger->should_log())) \ + if (QUILL_LIKELY(logger->template should_log())) \ { \ constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \ constexpr bool is_backtrace_log_record {true}; \ - logger->log \ + logger->template log \ (FMT_STRING(fmt), ##__VA_ARGS__); \ } \ } while (0) diff --git a/quill/include/quill/handlers/FileHandler.h b/quill/include/quill/handlers/FileHandler.h index f042b503..4cd60e1c 100644 --- a/quill/include/quill/handlers/FileHandler.h +++ b/quill/include/quill/handlers/FileHandler.h @@ -14,6 +14,7 @@ namespace quill enum class FilenameAppend { + DateTime, Date, None }; diff --git a/quill/src/handlers/FileHandler.cpp b/quill/src/handlers/FileHandler.cpp index 09191e0c..bd69f6a9 100644 --- a/quill/src/handlers/FileHandler.cpp +++ b/quill/src/handlers/FileHandler.cpp @@ -16,6 +16,11 @@ FileHandler::FileHandler(filename_t const& filename, std::string const& mode, Fi { _current_filename = detail::file_utilities::append_date_to_filename(_filename); } + else if (append_to_filename == FilenameAppend::DateTime) + { + _current_filename = + detail::file_utilities::append_date_to_filename(_filename, std::chrono::system_clock::now(), true); + } // _file is the base file* _file = detail::file_utilities::open(_current_filename, mode);