Skip to content

Commit

Permalink
Merge pull request #32296 from geoand/#32291
Browse files Browse the repository at this point in the history
Properly include logging filters in named handlers
  • Loading branch information
geoand authored Apr 1, 2023
2 parents 499eaf1 + d76e3d3 commit c6d48bc
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ShutdownListener initializeLogging(LogConfig config, LogBuildTimeConfig b
final List<RuntimeValue<Optional<Formatter>>> possibleSyslogFormatters,
final RuntimeValue<Optional<Supplier<String>>> possibleBannerSupplier,
LaunchMode launchMode,
boolean validateFilters) {
boolean includeFilters) {

ShutdownNotifier shutdownNotifier = new ShutdownNotifier();
final Map<String, CategoryConfig> categories = config.categories;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void accept(String loggerName, CleanupFilterConfig config) {
if (config.console.enable) {
final Handler consoleHandler = configureConsoleHandler(config.console, consoleRuntimeConfig.getValue(),
errorManager, cleanupFiler, namedFilters, possibleConsoleFormatters, possibleBannerSupplier,
launchMode, validateFilters);
launchMode, includeFilters);
errorManager = consoleHandler.getErrorManager();
handlers.add(consoleHandler);
}
Expand All @@ -170,12 +170,12 @@ public void close() throws SecurityException {
if (config.file.enable) {
handlers.add(
configureFileHandler(config.file, errorManager, cleanupFiler, namedFilters, possibleFileFormatters,
validateFilters));
includeFilters));
}

if (config.syslog.enable) {
final Handler syslogHandler = configureSyslogHandler(config.syslog, errorManager, cleanupFiler,
namedFilters, possibleSyslogFormatters, validateFilters);
namedFilters, possibleSyslogFormatters, includeFilters);
if (syslogHandler != null) {
handlers.add(syslogHandler);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public void close() throws SecurityException {
? createNamedHandlers(config, consoleRuntimeConfig.getValue(), additionalNamedHandlers,
possibleConsoleFormatters, possibleFileFormatters, possibleSyslogFormatters,
errorManager, cleanupFiler, namedFilters, launchMode,
shutdownNotifier, false)
shutdownNotifier, includeFilters)
: Collections.emptyMap();
if (!categories.isEmpty()) {
Map<String, Handler> additionalNamedHandlersMap;
Expand Down Expand Up @@ -327,7 +327,7 @@ public static void initializeBuildTimeLogging(LogConfig config, LogBuildTimeConf

Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), errorManager, logCleanupFilter,
Collections.emptyMap(), launchMode, dummy, true);
Collections.emptyMap(), launchMode, dummy, false);

for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
final String categoryName = entry.getKey();
Expand Down Expand Up @@ -415,7 +415,7 @@ private static Map<String, Handler> createNamedHandlers(LogConfig config, Consol
List<RuntimeValue<Optional<Formatter>>> possibleSyslogFormatters,
ErrorManager errorManager, LogCleanupFilter cleanupFilter,
Map<String, Filter> namedFilters, LaunchMode launchMode,
ShutdownNotifier shutdownHandler, boolean validateFilters) {
ShutdownNotifier shutdownHandler, boolean includeFilters) {
Map<String, Handler> namedHandlers = new HashMap<>();
for (Entry<String, ConsoleConfig> consoleConfigEntry : config.consoleHandlers.entrySet()) {
ConsoleConfig namedConsoleConfig = consoleConfigEntry.getValue();
Expand All @@ -424,7 +424,7 @@ private static Map<String, Handler> createNamedHandlers(LogConfig config, Consol
}
final Handler consoleHandler = configureConsoleHandler(namedConsoleConfig, consoleRuntimeConfig,
errorManager, cleanupFilter, namedFilters, possibleConsoleFormatters, null, launchMode,
validateFilters);
includeFilters);
addToNamedHandlers(namedHandlers, consoleHandler, consoleConfigEntry.getKey());
}
for (Entry<String, FileConfig> fileConfigEntry : config.fileHandlers.entrySet()) {
Expand All @@ -433,7 +433,7 @@ private static Map<String, Handler> createNamedHandlers(LogConfig config, Consol
continue;
}
final Handler fileHandler = configureFileHandler(namedFileConfig, errorManager, cleanupFilter, namedFilters,
possibleFileFormatters, validateFilters);
possibleFileFormatters, includeFilters);
addToNamedHandlers(namedHandlers, fileHandler, fileConfigEntry.getKey());
}
for (Entry<String, SyslogConfig> sysLogConfigEntry : config.syslogHandlers.entrySet()) {
Expand All @@ -442,7 +442,7 @@ private static Map<String, Handler> createNamedHandlers(LogConfig config, Consol
continue;
}
final Handler syslogHandler = configureSyslogHandler(namedSyslogConfig, errorManager, cleanupFilter,
namedFilters, possibleSyslogFormatters, validateFilters);
namedFilters, possibleSyslogFormatters, includeFilters);
if (syslogHandler != null) {
addToNamedHandlers(namedHandlers, syslogHandler, sysLogConfigEntry.getKey());
}
Expand Down Expand Up @@ -536,7 +536,7 @@ private static Handler configureConsoleHandler(final ConsoleConfig config,
final List<RuntimeValue<Optional<Formatter>>> possibleFormatters,
final RuntimeValue<Optional<Supplier<String>>> possibleBannerSupplier,
LaunchMode launchMode,
boolean validateFilters) {
boolean includeFilters) {
Formatter formatter = null;
boolean formatterWarning = false;

Expand Down Expand Up @@ -577,7 +577,7 @@ private static Handler configureConsoleHandler(final ConsoleConfig config,
config.stderr ? ConsoleHandler.Target.SYSTEM_ERR : ConsoleHandler.Target.SYSTEM_OUT, formatter);
consoleHandler.setLevel(config.level);
consoleHandler.setErrorManager(defaultErrorManager);
applyFilter(validateFilters, defaultErrorManager, cleanupFilter, config.filter, namedFilters, consoleHandler);
applyFilter(includeFilters, defaultErrorManager, cleanupFilter, config.filter, namedFilters, consoleHandler);

Handler handler = config.async.enable ? createAsyncHandler(config.async, config.level, consoleHandler)
: consoleHandler;
Expand Down Expand Up @@ -617,7 +617,7 @@ public void close() throws SecurityException {
private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager,
final LogCleanupFilter cleanupFilter, Map<String, Filter> namedFilters,
final List<RuntimeValue<Optional<Formatter>>> possibleFileFormatters,
final boolean validateFilters) {
final boolean includeFilters) {
FileHandler handler;
FileConfig.RotationConfig rotationConfig = config.rotation;
if (rotationConfig.fileSuffix.isPresent()) {
Expand Down Expand Up @@ -666,7 +666,7 @@ private static Handler configureFileHandler(final FileConfig config, final Error
errorManager.error("Failed to set character encoding", e, ErrorManager.GENERIC_FAILURE);
}
}
applyFilter(validateFilters, errorManager, cleanupFilter, config.filter, namedFilters, handler);
applyFilter(includeFilters, errorManager, cleanupFilter, config.filter, namedFilters, handler);

if (formatterWarning) {
handler.getErrorManager().error("Multiple file formatters were activated", null, ErrorManager.GENERIC_FAILURE);
Expand All @@ -678,9 +678,9 @@ private static Handler configureFileHandler(final FileConfig config, final Error
return handler;
}

private static void applyFilter(boolean validateFilters, ErrorManager errorManager, LogCleanupFilter cleanupFilter,
private static void applyFilter(boolean includeFilters, ErrorManager errorManager, LogCleanupFilter cleanupFilter,
Optional<String> filterName, Map<String, Filter> namedFilters, Handler handler) {
if (filterName.isEmpty() || !validateFilters) {
if (filterName.isEmpty() || !includeFilters) {
handler.setFilter(cleanupFilter);
} else {
String name = filterName.get();
Expand All @@ -698,7 +698,7 @@ private static Handler configureSyslogHandler(final SyslogConfig config, final E
final LogCleanupFilter logCleanupFilter,
final Map<String, Filter> namedFilters,
final List<RuntimeValue<Optional<Formatter>>> possibleSyslogFormatters,
final boolean validateFilters) {
final boolean includeFilters) {
try {
final SyslogHandler handler = new SyslogHandler(config.endpoint.getHostString(), config.endpoint.getPort());
handler.setAppName(config.appName.orElse(getProcessName()));
Expand Down Expand Up @@ -729,7 +729,7 @@ private static Handler configureSyslogHandler(final SyslogConfig config, final E

handler.setErrorManager(errorManager);
handler.setFilter(logCleanupFilter);
applyFilter(validateFilters, errorManager, logCleanupFilter, config.filter, namedFilters, handler);
applyFilter(includeFilters, errorManager, logCleanupFilter, config.filter, namedFilters, handler);

if (formatterWarning) {
handler.getErrorManager().error("Multiple syslog formatters were activated", null,
Expand Down

0 comments on commit c6d48bc

Please sign in to comment.