Skip to content

Commit

Permalink
Improve logger helper
Browse files Browse the repository at this point in the history
So that we need a factory that checks the spdlog registry in its
own dll before creating a new logger. Or, if no factory is set we
check the KDUtils registry.

Call sites should not worry about checkign via spdlog::get()
themselves as this helper and any installed factory should now
do it instead.

This will ensure the same registry is checked as is used when
creating each logger.

Change-Id: I24399e7ca778ddd310d6074300e70143ca3d2d9f
Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/134715
Reviewed-by: Paul Lemire <[email protected]>
  • Loading branch information
seanharmer committed Dec 5, 2023
1 parent cff3112 commit d5a792d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/KDUtils/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ std::shared_ptr<spdlog::logger> Logger::logger(const std::string &name)
{
std::shared_ptr<spdlog::logger> logger;
if (ms_loggerFactory) {
// Use the factory set by the application which should check
// its own spdlog registry first before creating a new logger.
logger = ms_loggerFactory(name);
} else {
// No factory set, use the spdlog registry from KDUtils
logger = spdlog::get(name);
if (!logger) {
#if defined(ANDROID)
logger = spdlog::android_logger_mt(name, name);
logger = spdlog::android_logger_mt(name, name);
#else
logger = spdlog::stdout_color_mt(name);
logger = spdlog::stdout_color_mt(name);
#endif
}
}
return logger;
}
Expand Down

0 comments on commit d5a792d

Please sign in to comment.