Fixed bug in DefaultLogger::set: (#5826)

assigning s_pNullLogger to the parameter "logger" is definitely wrong.
However, custom logger previously set from user must not be deleted.
The user itself must handle allocation / deallocation.
This commit is contained in:
chefrolle695
2024-10-17 21:14:14 +02:00
committed by GitHub
parent 2591d0e490
commit 4b9ac76815
2 changed files with 8 additions and 7 deletions

View File

@@ -221,13 +221,11 @@ void DefaultLogger::set(Logger *logger) {
#endif
if (nullptr == logger) {
logger = &s_pNullLogger;
m_pLogger = &s_pNullLogger;
}
if (nullptr != m_pLogger && !isNullLogger()) {
delete m_pLogger;
else {
m_pLogger = logger;
}
DefaultLogger::m_pLogger = logger;
}
// ----------------------------------------------------------------------------------

View File

@@ -103,6 +103,9 @@ public:
* your needs. If the provided message formatting is OK for you,
* it's much easier to use #create() and to attach your own custom
* output streams to it.
* Since set is intended to be used for custom loggers, the user is
* responsible for instantiation and destruction (new / delete).
* Before deletion of the custom logger, set(nullptr); must be called.
* @param logger Pass NULL to setup a default NullLogger*/
static void set(Logger *logger);
@@ -120,8 +123,8 @@ public:
static bool isNullLogger();
// ----------------------------------------------------------------------
/** @brief Kills the current singleton logger and replaces it with a
* #NullLogger instance. */
/** @brief Kills and deletes the current singleton logger and replaces
* it with a #NullLogger instance. */
static void kill();
// ----------------------------------------------------------------------