From d20f058a2fce46cb1ddd1eb8abcf93c8963a3ffe Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Wed, 1 Nov 2023 01:42:24 +0000 Subject: [PATCH] move get_root_logger function definition to the header file --- CHANGELOG.md | 12 ++++++++---- quill/include/quill/Quill.h | 21 ++++++++++++++++----- quill/src/Quill.cpp | 8 -------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3655d43b..4b11e220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,16 +59,20 @@ - Resolved a bug in `RotatingFileHandler` associated with logfiles located outside the working directory, specifically when used with open_mode `a`. ([#340](https://github.com/odygrd/quill/pull/340)) -- Added a `name()` method to the Logger class which provides the logger name. ([#345](https://github.com/odygrd/quill/pull/345)) +- Added a `name()` method to the Logger class which provides the logger + name. ([#345](https://github.com/odygrd/quill/pull/345)) - Fixed library and include paths in the pkg-config configuration. ([#352](https://github.com/odygrd/quill/pull/352)) -- Introduced support for logging character arrays. You can now log character arrays, even when they don't contain a null-terminating character. +- Move `get_root_logger()` definition from cpp to the header file ([#348](https://github.com/odygrd/quill/issues/348)) + +- Introduced support for logging character arrays. You can now log character arrays, even when they don't contain a + null-terminating character. Additionally, character arrays with null characters in the middle are supported, and the logger will capture the content until the null character is encountered. ([#353](https://github.com/odygrd/quill/pull/353)) For example - + ```c++ union { @@ -89,7 +93,7 @@ Previous: 2.21 million msgs/sec average, total time elapsed: 1809 ms for 4000000 log messages. New: 2.24 million msgs/sec average, total time elapsed: 1787 ms for 4000000 log messages. - + ## v3.3.1 - Fixed `RotatingFileHandler` to prevent accidental removal of non-log files when using open mode `w` diff --git a/quill/include/quill/Quill.h b/quill/include/quill/Quill.h index 108fedd2..dda69e58 100644 --- a/quill/include/quill/Quill.h +++ b/quill/include/quill/Quill.h @@ -17,10 +17,11 @@ #include "quill/handlers/FileHandler.h" // for FilenameAppend, Filena... #include "quill/handlers/JsonFileHandler.h" // for JsonFileHandler #include "quill/handlers/RotatingFileHandler.h" // for RotatingFileHandler -#include // for hours, minutes, nanose... -#include // for size_t -#include // for uint16_t -#include // for initializer_list +#include +#include // for hours, minutes, nanose... +#include // for size_t +#include // for uint16_t +#include // for initializer_list #include #include #include // for optional @@ -39,6 +40,7 @@ constexpr uint32_t Version{VersionMajor * 10000 + VersionMinor * 100 + VersionPa /** forward declarations **/ class Handler; class Logger; +extern Logger* _g_root_logger; /** * Pre-allocates the thread-local data needed for the current thread. @@ -230,7 +232,16 @@ QUILL_NODISCARD Logger* get_logger(char const* logger_name = nullptr); * @warning This should be used only after calling quill::start(); if you need the root logger earlier then call get_logger() instead * @return pointer to the root logger */ -QUILL_NODISCARD Logger* get_root_logger() noexcept; +template +QUILL_NODISCARD Logger* get_root_logger() noexcept +{ + if constexpr (WithCheck) + { + assert(_g_root_logger && + "_g_root_logger is nullptr, this function must be called after quill::start()"); + } + return _g_root_logger; +} /** * Returns all existing loggers and the pointers to them diff --git a/quill/src/Quill.cpp b/quill/src/Quill.cpp index 4e1840ed..a87889b7 100644 --- a/quill/src/Quill.cpp +++ b/quill/src/Quill.cpp @@ -101,14 +101,6 @@ Logger* get_logger(char const* logger_name /* = nullptr */) return detail::LogManagerSingleton::instance().log_manager().logger_collection().get_logger(logger_name); } -/***/ -Logger* get_root_logger() noexcept -{ - assert(_g_root_logger && - "_g_root_logger is nullptr, this function must be called after quill::start()"); - return _g_root_logger; -} - /***/ std::unordered_map get_all_loggers() {