String evaluatorOrIgnoredStackTraceLine = (String) optionList.get(i); Context context = getContext(); Map<String, EventEvaluator<?>> evaluatorMap = (Map<String, EventEvaluator<?>>) context.getObject(CoreConstants.EVALUATOR_MAP); EventEvaluator<ILoggingEvent> ee = (EventEvaluator<ILoggingEvent>) evaluatorMap.get(evaluatorOrIgnoredStackTraceLine); if (ee != null) {
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 List<String> getStatuses() { List<String> list = new ArrayList<String>(); Iterator<Status> it = context.getStatusManager().getCopyOfStatusList().iterator(); while (it.hasNext()) { list.add(it.next().toString()); } return list; }
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); } }
public void addProperties(Properties props) { if (props == null) { return; } Iterator i = props.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); context.putProperty(key, props.getProperty(key)); } }
/** * Print context's status data with a timestamp higher than the threshold. * @param context */ public static void print(Context context, long threshold) { if (context == null) { throw new IllegalArgumentException("Context argument cannot be null"); } StatusManager sm = context.getStatusManager(); if (sm == null) { ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager"); } else { print(sm, threshold); } }
void detachReconfigurationToNewThread() { addInfo("Detected change in [" + configurationWatchList.getCopyOfFileWatchList() + "]"); context.getExecutorService().submit(new ReconfiguringThread()); }
/** * If a key is found in propertiesMap then return it. Otherwise, delegate to * the context. */ public String getProperty(String key) { String v = propertiesMap.get(key); if (v != null) { return v; } else { return context.getProperty(key); } }
if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) { addInfo("Using context birth as time reference."); timeReference = context.getBirthTime(); } else { timeReference = System.currentTimeMillis(); context.putProperty(keyStr, val);
@Override public String toString() { return this.getClass().getName() + "(" + context.getName() + ")"; } }
public static void setConfigurationWatchListResetFlag(Context context, boolean val) { context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST_RESET, new Boolean(val)); }
public void doConfigure(final List<SaxEvent> eventList) throws JoranException { buildInterpreter(); // disallow simultaneous configurations of the same context synchronized (context.getConfigurationLock()) { interpreter.getEventPlayer().play(eventList); } }
if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) { addInfo("Using context birth as time reference."); timeReference = context.getBirthTime(); } else { timeReference = System.currentTimeMillis();
private LoggerContext configureLogging(final String workerName, final String logDirectory) throws EngineException { final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory(); if (iLoggerFactory instanceof Context) { final Context context = (Context) iLoggerFactory; final LoggerContext result = (LoggerContext) iLoggerFactory; final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); context.putProperty("WORKER_NAME", workerName); context.putProperty("LOG_DIRECTORY", logDirectory); try { configurator.doConfigure(GrinderProcess.class.getResource("/logback-worker.xml")); } catch (final JoranException e) { throw new EngineException("Could not initialise logger", e); } return result; } else { m_terminalLogger.warn("Logback not found; grinder log configuration will be ignored.\n" + "Consider adding logback-classic to the start of the CLASSPATH."); return null; } }
/** * Print the contents of the context statuses, but only if they contain * errors. * * @param context */ public static void printIfErrorsOccured(Context context) { if (context == null) { throw new IllegalArgumentException("Context argument cannot be null"); } StatusManager sm = context.getStatusManager(); if (sm == null) { ps.println("WARN: Context named \"" + context.getName() + "\" has no status manager"); } else { StatusUtil statusUtil = new StatusUtil(context); if (statusUtil.getHighestLevel(0) == ErrorStatus.ERROR) { print(sm); } } }
/** * Instantiates an layout of the given class and sets its name. * */ public void begin(InterpretationContext ec, String name, Attributes attributes) { Integer i = (Integer) ec.getContext().getObject(KEY); if(i == null) { ec.getContext().putObject(KEY, 1); } else { ec.getContext().putObject(KEY, i+1); } }
/** * Starts the server. */ protected boolean shouldStart() { try { ServerSocket serverSocket = getServerSocketFactory().createServerSocket(getPort(), getBacklog(), getInetAddress()); ServerListener<RemoteAppenderClient> listener = createServerListener(serverSocket); runner = createServerRunner(listener, getContext().getExecutorService()); runner.setContext(getContext()); return true; } catch (Exception ex) { addError("server startup error: " + ex, ex); CloseUtil.closeQuietly(serverSocket); return false; } }
/** * If a key is found in propertiesMap then return it. Otherwise, delegate to * the context. */ public String getProperty(String key) { String v = propertiesMap.get(key); if (v != null) { return v; } else { return context.getProperty(key); } }
if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) { addInfo("Using context birth as time reference."); timeReference = context.getBirthTime(); } else { timeReference = System.currentTimeMillis(); context.putProperty(keyStr, val);