Skip to content

Commit

Permalink
fix: do not check categories without named handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
rquinio1A committed Jan 20, 2025
1 parent cc10bd9 commit 6f08f07
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public void close() throws SecurityException {

namedHandlers.putAll(additionalNamedHandlersMap);

setUpCategoryLoggers(buildConfig, categoryDefaultMinLevels, categories, logContext, errorManager, namedHandlers);
setUpCategoryLoggers(buildConfig, categoryDefaultMinLevels, categories, logContext, errorManager, namedHandlers,
true);
}

for (RuntimeValue<Optional<Handler>> additionalHandler : additionalHandlers) {
Expand Down Expand Up @@ -344,7 +345,7 @@ public static void initializeBuildTimeLogging(
emptyList(), emptyList(), emptyList(), emptyList(), errorManager, logCleanupFilter,
emptyMap(), launchMode, dummy, false);

setUpCategoryLoggers(buildConfig, categoryDefaultMinLevels, categories, logContext, errorManager, namedHandlers);
setUpCategoryLoggers(buildConfig, categoryDefaultMinLevels, categories, logContext, errorManager, namedHandlers, false);

addNamedHandlersToRootHandlers(config.handlers(), namedHandlers, handlers, errorManager);
InitialConfigurator.DELAYED_HANDLER.setAutoFlush(false);
Expand Down Expand Up @@ -482,7 +483,8 @@ public void run() {
private static void addNamedHandlersToCategory(
CategoryConfig categoryConfig, Map<String, Handler> namedHandlers,
Logger categoryLogger,
ErrorManager errorManager) {
ErrorManager errorManager,
boolean checkHandlerLinks) {
for (String categoryNamedHandler : categoryConfig.handlers().get()) {
Handler handler = namedHandlers.get(categoryNamedHandler);
if (handler != null) {
Expand All @@ -493,7 +495,7 @@ public void run() {
categoryLogger.removeHandler(handler);
}
});
} else {
} else if (checkHandlerLinks) {
errorManager.error(String.format("Handler with name '%s' is linked to a category but not configured.",
categoryNamedHandler), null, ErrorManager.GENERIC_FAILURE);
}
Expand All @@ -506,7 +508,8 @@ private static void setUpCategoryLoggers(
final Map<String, CategoryConfig> categories,
final LogContext logContext,
final ErrorManager errorManager,
final Map<String, Handler> namedHandlers) {
final Map<String, Handler> namedHandlers,
final boolean checkHandlerLinks) {

for (Entry<String, CategoryConfig> entry : categories.entrySet()) {
String categoryName = entry.getKey();
Expand All @@ -532,7 +535,7 @@ private static void setUpCategoryLoggers(
}
categoryLogger.setUseParentHandlers(categoryConfig.useParentHandlers());
if (categoryConfig.handlers().isPresent()) {
addNamedHandlersToCategory(categoryConfig, namedHandlers, categoryLogger, errorManager);
addNamedHandlersToCategory(categoryConfig, namedHandlers, categoryLogger, errorManager, checkHandlerLinks);
}
}
}
Expand Down

0 comments on commit 6f08f07

Please sign in to comment.