public void end(InterpretationContext ec, String name) { addInfo("End of configuration."); ec.popObject(); } }
rs.addRule(new ElementSelector("configuration"), new ConfigurationAction()); rs.addRule(new ElementSelector("configuration/contextName"), new ContextNameAction()); rs.addRule(new ElementSelector("configuration/contextListener"), new LoggerContextListenerAction()); rs.addRule(new ElementSelector("configuration/insertFromJNDI"), new InsertFromJNDIAction()); rs.addRule(new ElementSelector("configuration/evaluator"), new EvaluatorAction()); rs.addRule(new ElementSelector("configuration/logger"), new LoggerAction()); rs.addRule(new ElementSelector("configuration/logger/level"), new LevelAction()); rs.addRule(new ElementSelector("configuration/root"), new RootLoggerAction()); rs.addRule(new ElementSelector("configuration/root/level"), new LevelAction()); rs.addRule(new ElementSelector("configuration/logger/appender-ref"), new AppenderRefAction<ILoggingEvent>()); rs.addRule(new ElementSelector("configuration/root/appender-ref"), new AppenderRefAction<ILoggingEvent>()); rs.addRule(new ElementSelector("configuration/jmxConfigurator"), new JMXConfiguratorAction()); rs.addRule(new ElementSelector("configuration/consolePlugin"), new ConsolePluginAction()); rs.addRule(new ElementSelector("configuration/receiver"), new ReceiverAction());
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LOGBACK-527 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } processScanAttrib(ic, attributes); LoggerContext lc = (LoggerContext) context; boolean packagingData = OptionHelper.toBoolean(ic.subst(attributes.getValue(PACKAGING_DATA_ATTR)), LoggerContext.DEFAULT_PACKAGING_DATA); lc.setPackagingDataEnabled(packagingData); if (EnvUtil.isGroovyAvailable()) { ContextUtil contextUtil = new ContextUtil(context); contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
String aroundLine = getLineColStr(ec); String errorMsg = "No 'name' attribute in element " + name + ", around " + aroundLine; addError(errorMsg); return; addInfo("Setting level of logger [" + loggerName + "] to null, i.e. INHERITED"); logger.setLevel(null); } else { Level level = Level.toLevel(levelStr); addInfo("Setting level of logger [" + loggerName + "] to " + level); logger.setLevel(level); if (!OptionHelper.isEmpty(additivityStr)) { boolean additive = OptionHelper.toBoolean(additivityStr, true); addInfo("Setting additivity of logger [" + loggerName + "] to " + additive); logger.setAdditive(additive);
String lineColStr = getLineColStr(ec); addError("[" + ENV_ENTRY_NAME_ATTR + "] missing, around " + lineColStr); errorCount++; String lineColStr = getLineColStr(ec); addError("[" + AS_ATTR + "] missing, around " + lineColStr); errorCount++; envEntryValue = JNDIUtil.lookup(ctx, envEntryName); if (OptionHelper.isEmpty(envEntryValue)) { addError("[" + envEntryName + "] has null or empty value"); } else { addInfo("Setting variable [" + asKey + "] to [" + envEntryValue + "] in [" + scope + "] scope"); ActionUtil.setProperty(ec, asKey, envEntryValue, scope); addError("Failed to lookup JNDI env-entry [" + envEntryName + "]");
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for receiver. Near [" + name + "] line " + getLineNumber(ic)); inError = true; return; } try { addInfo("About to instantiate receiver of type [" + className + "]"); receiver = (ReceiverBase) OptionHelper.instantiateByClassName(className, ReceiverBase.class, context); receiver.setContext(context); ic.pushObject(receiver); } catch (Exception ex) { inError = true; addError("Could not create a receiver of type [" + className + "].", ex); throw new ActionException(ex); } }
public void body(InterpretationContext ec, String body) { String finalBody = ec.subst(body); addInfo("Setting logger context name as [" + finalBody + "]"); try { context.setName(finalBody); } catch (IllegalStateException e) { addError("Failed to rename context [" + context.getName() + "] as [" + finalBody + "]", e); } }
public void begin(InterpretationContext ec, String name, Attributes attributes) { Object o = ec.peekObject(); if (!(o instanceof Logger)) { inError = true; addError("For element <level>, could not find a logger at the top of execution stack."); return; } Logger l = (Logger) o; String loggerName = l.getName(); String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR)); // addInfo("Encapsulating logger name is [" + loggerName // + "], level value is [" + levelStr + "]."); if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) { l.setLevel(null); } else { l.setLevel(Level.toLevel(levelStr, Level.DEBUG)); } addInfo(loggerName + " level set to " + l.getLevel()); }
void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); if (mainURL == null) { addWarn("Due to missing top level configuration file, reconfiguration on change (configuration file scanning) cannot be done."); return; } ReconfigureOnChangeTask rocTask = new ReconfigureOnChangeTask(); rocTask.setContext(context); context.putObject(CoreConstants.RECONFIGURE_ON_CHANGE_TASK, rocTask); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); Duration duration = getDuration(scanAttrib, scanPeriodAttrib); if (duration == null) { return; } addInfo("Will scan for changes in [" + mainURL + "] "); // Given that included files are encountered at a later phase, the complete list of files // to scan can only be determined when the configuration is loaded in full. // However, scan can be active if mainURL is set. Otherwise, when changes are detected // the top level config file cannot be accessed. addInfo("Setting ReconfigureOnChangeTask scanning period to " + duration); ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(rocTask, duration.getMilliseconds(), duration.getMilliseconds(), TimeUnit.MILLISECONDS); context.addScheduledFuture(scheduledFuture); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <loggerContextListener> element"); inError = true; return; } try { lcl = (LoggerContextListener) OptionHelper.instantiateByClassName(className, LoggerContextListener.class, context); if (lcl instanceof ContextAware) { ((ContextAware) lcl).setContext(context); } ec.pushObject(lcl); addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); } catch (Exception oops) { inError = true; addError("Could not create LoggerContextListener of type " + className + "].", oops); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { if (inError) { return; } Object o = ec.peekObject(); if (o != lcl) { addWarn("The object on the top the of the stack is not the LoggerContextListener pushed earlier."); } else { if (lcl instanceof LifeCycle) { ((LifeCycle) lcl).start(); addInfo("Starting LoggerContextListener"); } ((LoggerContext) context).addListener(lcl); ec.popObject(); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String portStr = attributes.getValue(PORT_ATTR); Integer port = null; if (portStr == null) { port = DEFAULT_PORT; } else { try { port = Integer.valueOf(portStr); } catch (NumberFormatException ex) { addError("Port " + portStr + " in ConsolePlugin config is not a correct number"); } } LoggerContext lc = (LoggerContext) ec.getContext(); SocketAppender appender = new SocketAppender(); appender.setContext(lc); appender.setIncludeCallerData(true); appender.setRemoteHost("localhost"); appender.setPort(port.intValue()); appender.start(); Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME); root.addAppender(appender); addInfo("Sending LoggingEvents to the plugin using port " + port); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { addInfo("begin"); addError("Failed construct ObjectName for [" + objectNameAsStr + "]"); return; mbs.registerMBean(jmxConfigurator, objectName); } catch (Exception e) { addError("Failed to create mbean", e);
public void begin(InterpretationContext ec, String name, Attributes attributes) { inError = false; LoggerContext loggerContext = (LoggerContext) this.context; root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); String levelStr = ec.subst(attributes.getValue(ActionConst.LEVEL_ATTRIBUTE)); if (!OptionHelper.isEmpty(levelStr)) { Level level = Level.toLevel(levelStr); addInfo("Setting level of ROOT logger to " + level); root.setLevel(level); } ec.pushObject(root); }
private Duration getDuration(String scanAttrib, String scanPeriodAttrib) { Duration duration = null; if (!OptionHelper.isEmpty(scanPeriodAttrib)) { try { duration = Duration.valueOf(scanPeriodAttrib); } catch (NumberFormatException nfe) { addError("Error while converting [" + scanAttrib + "] to long", nfe); } } return duration; }
@Override public void end(InterpretationContext ic, String name) throws ActionException { if (inError) return; ic.getContext().register(receiver); receiver.start(); Object o = ic.peekObject(); if (o != receiver) { addWarn("The object at the of the stack is not the remote " + "pushed earlier."); } else { ic.popObject(); } }
public void end(InterpretationContext ec, String name) { addInfo("End of configuration."); ec.popObject(); } }