private void configureLogger()

in src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java [619:667]


    private void configureLogger(
            final String pid, final String logLevel, final String[] loggers, final String logFile, boolean additive)
            throws IOException, ConfigurationException {
        // try to get the configadmin service reference
        ServiceReference<ConfigurationAdmin> sr = this.bundleContext.getServiceReference(ConfigurationAdmin.class);
        if (sr != null) {
            ConfigurationAdmin configAdmin = null;
            try {
                if (logLevel == null) {
                    throw new ConfigurationException(LogConstants.LOG_LEVEL, "Log level has to be specified.");
                }
                if (loggers == null) {
                    throw new ConfigurationException(
                            LogConstants.LOG_LOGGERS, "Logger categories have to be specified.");
                }
                if (logFile == null) {
                    throw new ConfigurationException(LogConstants.LOG_FILE, "LogFile name has to be specified.");
                }
                // try to get the configadmin
                configAdmin = this.bundleContext.getService(sr);
                if (configAdmin != null) {
                    Configuration config;
                    if (pid == null || pid.length() == 0) {
                        config = configAdmin.createFactoryConfiguration(LogConstants.FACTORY_PID_CONFIGS);
                    } else {
                        config = configAdmin.getConfiguration(pid);
                    }
                    if (config != null) {
                        Dictionary<String, Object> dict = new Hashtable<>(); // NOSONAR
                        dict.put(LogConstants.LOG_LEVEL, logLevel.toLowerCase());
                        dict.put(LogConstants.LOG_LOGGERS, loggers);
                        dict.put(LogConstants.LOG_FILE, logFile);

                        if (additive) {
                            dict.put(LogConstants.LOG_ADDITIV, "true");
                        } else {
                            dict.put(LogConstants.LOG_ADDITIV, "false");
                        }
                        config.update(dict);
                    }
                }
            } finally {
                if (configAdmin != null) {
                    // release the configadmin reference
                    this.bundleContext.ungetService(sr);
                }
            }
        }
    }