public void updateLoggerConfiguration()

in src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java [924:1025]


    public void updateLoggerConfiguration(
            @NotNull final String pid, @Nullable final Dictionary<?, ?> configuration, final boolean performRefresh)
            throws ConfigurationException {

        if (configuration != null) {
            String pattern = converter
                    .convert(configuration.get(LogConstants.LOG_PATTERN))
                    .defaultValue(LogConstants.LOG_PATTERN_DEFAULT)
                    .to(String.class);
            String level = converter
                    .convert(configuration.get(LogConstants.LOG_LEVEL))
                    .defaultValue(LogConstants.LOG_LEVEL_DEFAULT)
                    .to(String.class);
            final Level logLevel;
            final boolean resetToDefault;
            if (LogConstants.LOG_LEVEL_RESET_TO_DEFAULT.equalsIgnoreCase(level)) {
                resetToDefault = true;
                logLevel = null;
            } else {
                logLevel = Level.toLevel(level, null);
                if (logLevel == null) {
                    throw new ConfigurationException(LogConstants.LOG_LEVEL, "Not a valid value");
                }
                resetToDefault = false;
            }

            String fileName = converter
                    .convert(configuration.get(LogConstants.LOG_FILE))
                    .defaultValue(null)
                    .to(String.class);
            // Map empty fileName to console logger
            // null fileName is for scenario where intention is just to change the log level
            if (fileName != null && fileName.trim().isEmpty()) {
                fileName = LogConstants.FILE_NAME_CONSOLE;
            }

            // FileName being just null means that we want to change the
            // LogLevel
            if (fileName != null && !LogConstants.FILE_NAME_CONSOLE.equals(fileName)) {
                fileName = getAbsoluteFilePath(fileName);
            }

            @SuppressWarnings("unchecked")
            Set<String> categories = converter
                    .convert(configuration.get(LogConstants.LOG_LOGGERS))
                    .to(Set.class);
            // verify categories
            if (categories.isEmpty()) {
                throw new ConfigurationException(
                        LogConstants.LOG_LOGGERS, "Missing categories in configuration " + pid);
            }

            boolean additiv = converter
                    .convert(configuration.get(LogConstants.LOG_ADDITIV))
                    // If an appender is explicitly defined then set additive to false
                    // to be compatible with earlier Sling Logging behavior
                    .defaultValue(false)
                    .to(Boolean.TYPE);

            // verify no other configuration has any of the categories
            for (final String cat : categories) {
                final LogConfig cfg = configByCategory.get(cat);
                if (cfg != null && !pid.equals(cfg.getConfigPid())) {
                    throw new ConfigurationException(
                            LogConstants.LOG_LOGGERS,
                            String.format("Category %s already defined by configuration %s", cat, cfg.getConfigPid()));
                }
            }

            // create or modify existing configuration object
            final LogConfig newConfig =
                    new LogConfig(this, pattern, categories, logLevel, fileName, additiv, pid, resetToDefault);
            if (packagingDataEnabled) {
                newConfig.setPostProcessor(new OSGiAwareExceptionHandling(getPackageInfoCollector()));
            }
            LogConfig oldConfig = configByPid.get(pid);
            if (oldConfig != null) {
                configByCategory.keySet().removeAll(oldConfig.getCategories());
            }

            // relink categories
            for (String cat : categories) {
                configByCategory.put(cat, newConfig);
            }

            configByPid.put(pid, newConfig);
        } else {
            // configuration deleted if null

            // remove configuration from pid list
            LogConfig config = configByPid.remove(pid);

            if (config != null) {
                // remove all configured categories
                configByCategory.keySet().removeAll(config.getCategories());
            }
        }

        if (performRefresh) {
            configChanged();
        }
    }