@Override
    public void configure(MetricRegistry metricRegistry, String name) {
        LoggingUtil.hijackJDKLogging();

        final Logger root;
        CHANGE_LOGGER_CONTEXT_LOCK.lock();
        try {
            root = configureLoggers(name);
        } finally {
            CHANGE_LOGGER_CONTEXT_LOCK.unlock();
        }

        final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new ThresholdLevelFilterFactory();
        final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
        final LayoutFactory<ILoggingEvent> layoutFactory = new DropwizardLayoutFactory();

        for (AppenderFactory<ILoggingEvent> output : appenders) {
            root.addAppender(output.build(loggerContext, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
        }

        StatusPrinter.setPrintStream(configurationErrorsStream);
        try {
            StatusPrinter.printIfErrorsOccured(loggerContext);
        } finally {
            StatusPrinter.setPrintStream(System.out);
        }

        configureInstrumentation(root, metricRegistry);
    }
@Test
    void testConfigure(@TempDir Path tempDir) throws Exception {
        final StringSubstitutor substitutor = new StringSubstitutor(Map.of(
                "new_app", tempDir.resolve("example-new-app").toFile().getAbsolutePath(),
                "new_app_not_additive", tempDir.resolve("example-new-app-not-additive").toFile().getAbsolutePath(),
                "default", tempDir.resolve("example").toFile().getAbsolutePath()
        ));

        DefaultLoggingFactory config = null;
        try {
            config = factory.build(new SubstitutingSourceProvider(configurationSourceProvider, substitutor), "yaml/logging_advanced.yml");
            config.configure(new MetricRegistry(), "test-logger");

            LoggerFactory.getLogger("com.example.app").debug("Application debug log");
            LoggerFactory.getLogger("com.example.app").info("Application log");
            LoggerFactory.getLogger("com.example.newApp").debug("New application debug log");
            LoggerFactory.getLogger("com.example.newApp").info("New application info log");
            LoggerFactory.getLogger("com.example.legacyApp").debug("Legacy application debug log");
            LoggerFactory.getLogger("com.example.legacyApp").info("Legacy application info log");
            LoggerFactory.getLogger("com.example.notAdditive").debug("Not additive application debug log");
            LoggerFactory.getLogger("com.example.notAdditive").info("Not additive application info log");

            config.stop();
            config.reset();

            assertThat(Files.readAllLines(tempDir.resolve("example.log"))).containsOnly(
                    "INFO  com.example.app: Application log",
                    "DEBUG com.example.newApp: New application debug log",
                    "INFO  com.example.newApp: New application info log",
                    "DEBUG com.example.legacyApp: Legacy application debug log",
                    "INFO  com.example.legacyApp: Legacy application info log");

            assertThat(Files.readAllLines(tempDir.resolve("example-new-app.log"))).containsOnly(
                    "DEBUG com.example.newApp: New application debug log",
                    "INFO  com.example.newApp: New application info log");

            assertThat(Files.readAllLines(tempDir.resolve("example-new-app-not-additive.log"))).containsOnly(
                    "DEBUG com.example.notAdditive: Not additive application debug log",
                    "INFO  com.example.notAdditive: Not additive application info log");
        } finally {
            if (config != null) {
                config.reset();
            }
        }
    }