public String getLevel() { return getLevel(LogServiceInternal.ROOT_LOGGER).get(LogServiceInternal.ROOT_LOGGER); }
public void setLevel(String level) { setLevel(LogServiceInternal.ROOT_LOGGER, level); }
@Override public PaxLoggingEvent getLastException(String logger) { PaxLoggingEvent throwableEvent = null; Iterable<PaxLoggingEvent> le = getEvents(); for (PaxLoggingEvent event : le) { // if this is an exception, and the log is the same as the requested log, // then save this exception and continue iterating from oldest to newest if ((event.getThrowableStrRep() != null) &&(logger != null) &&(checkIfFromRequestedLog(event, logger))) { throwableEvent = event; // Do not break, as we iterate from the oldest to the newest event } else if ((event.getThrowableStrRep() != null)&&(logger == null)) { // now check if there has been no log passed in, and if this is an exception // then save this exception and continue iterating from oldest to newest throwableEvent = event; } } return throwableEvent; }
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); } }
public Map<String, String> getLevel(String logger) { Configuration cfg; try { cfg = configAdmin.getConfiguration(CONFIGURATION_PID, null); } catch (IOException e) { throw new RuntimeException("Error retrieving Log information from config admin", e); } if (logger == null) { logger = LogServiceInternal.ROOT_LOGGER; } return getDelegate(cfg.getProperties()).getLevel(logger); }
protected void doStart() throws Exception { ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class); if (configurationAdmin == null) { return; } int size = getInt("size", 500); String pattern = getString("pattern", "%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n"); String errorColor = getString("errorColor", "31"); String warnColor = getString("warnColor", "35"); String infoColor = getString("infoColor", "36"); String debugColor = getString("debugColor", "39"); String traceColor = getString("traceColor", "39"); LogEventFormatterImpl formatter = new LogEventFormatterImpl(); formatter.setPattern(pattern); formatter.setColor(PaxLogger.LEVEL_ERROR, errorColor); formatter.setColor(PaxLogger.LEVEL_WARNING, warnColor); formatter.setColor(PaxLogger.LEVEL_INFO, infoColor); formatter.setColor(PaxLogger.LEVEL_DEBUG, debugColor); formatter.setColor(PaxLogger.LEVEL_TRACE, traceColor); register(LogEventFormatter.class, formatter); LogServiceImpl logService = new LogServiceImpl(configurationAdmin, size); Hashtable<String, Object> props = new Hashtable<>(); props.put("org.ops4j.pax.logging.appender.name", "VmLogAppender"); register(PaxAppender.class, logService, props); register(LogService.class, logService); LogMBeanImpl securityMBean = new LogMBeanImpl(logService); registerMBean(securityMBean, "type=log"); }