Skip to content

Commit

Permalink
move get_root_logger function definition to the header file
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Nov 1, 2023
1 parent 20a93dd commit d20f058
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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`
Expand Down
21 changes: 16 additions & 5 deletions quill/include/quill/Quill.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chrono> // for hours, minutes, nanose...
#include <cstddef> // for size_t
#include <cstdint> // for uint16_t
#include <initializer_list> // for initializer_list
#include <cassert>
#include <chrono> // for hours, minutes, nanose...
#include <cstddef> // for size_t
#include <cstdint> // for uint16_t
#include <initializer_list> // for initializer_list
#include <limits>
#include <memory>
#include <optional> // for optional
Expand All @@ -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.
Expand Down Expand Up @@ -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 <bool WithCheck = true>
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
Expand Down
8 changes: 0 additions & 8 deletions quill/src/Quill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, Logger*> get_all_loggers()
{
Expand Down

0 comments on commit d20f058

Please sign in to comment.