Search in sources :

Example 1 with Level

use of org.apache.karaf.log.core.Level in project karaf by apache.

the class LogServiceImpl method setLevel.

public void setLevel(String logger, String level) {
    // make sure both uppercase and lowercase levels are supported
    level = level.toUpperCase();
    // check if the level is valid
    Level lvl = Level.valueOf(level);
    // Default logger
    if (logger == null) {
        logger = LogServiceInternal.ROOT_LOGGER;
    }
    // Verify
    if (lvl == Level.DEFAULT && LogServiceInternal.ROOT_LOGGER.equals(logger)) {
        throw new IllegalStateException("Can not unset the ROOT logger");
    }
    // Get config
    Configuration cfg = getConfiguration();
    Dictionary<String, Object> props = cfg.getProperties();
    // Update
    getDelegate(props).setLevel(logger, level);
    // Save
    try {
        cfg.update(props);
    } catch (IOException e) {
        throw new RuntimeException("Error writing log config to config admin", e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) Level(org.apache.karaf.log.core.Level) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Level (org.apache.karaf.log.core.Level)1 Configuration (org.osgi.service.cm.Configuration)1