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()); }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addNewInstanceToContext(Context context) { OnConsoleStatusListener onConsoleStatusListener = new OnConsoleStatusListener(); onConsoleStatusListener.setContext(context); onConsoleStatusListener.start(); context.getStatusManager().add(onConsoleStatusListener); }
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 { OnConsoleStatusListener.addNewInstanceToContext(context); } processScanAttrib(ic, attributes); ContextUtil contextUtil = new ContextUtil(context); contextUtil.addHostNameAsProperty(); if(EnvUtil.isGroovyAvailable()) { LoggerContext lc = (LoggerContext) context; contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
@Test public void duplicateInstallationsOfOnConsoleListener() { OnConsoleStatusListener sl0 = new OnConsoleStatusListener(); sl0.start(); OnConsoleStatusListener sl1 = new OnConsoleStatusListener(); sl1.start(); assertTrue(bsm.add(sl0)); { List<StatusListener> listeners = bsm.getCopyOfStatusListenerList(); assertEquals(1, listeners.size()); } assertFalse(bsm.add(sl1)); { List<StatusListener> listeners = bsm.getCopyOfStatusListenerList(); assertEquals(1, listeners.size()); } }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addOnConsoleListenerInstance(Context context, OnConsoleStatusListener onConsoleStatusListener) { onConsoleStatusListener.setContext(context); boolean effectivelyAdded = context.getStatusManager().add(onConsoleStatusListener); if (effectivelyAdded) { onConsoleStatusListener.start(); } }
@Test public void addOnConsoleListenerInstanceShouldNotStartSecondListener() { OnConsoleStatusListener ocl0 = new OnConsoleStatusListener(); OnConsoleStatusListener ocl1 = new OnConsoleStatusListener(); StatusListenerConfigHelper.addOnConsoleListenerInstance(context, ocl0); { List<StatusListener> listeners = sm.getCopyOfStatusListenerList(); assertEquals(1, listeners.size()); assertTrue(ocl0.isStarted()); } // second listener should not have been started StatusListenerConfigHelper.addOnConsoleListenerInstance(context, ocl1); { List<StatusListener> listeners = sm.getCopyOfStatusListenerList(); assertEquals(1, listeners.size()); assertFalse(ocl1.isStarted()); } }
@Before public void before() { contextAware.setContext(context); csl.setContext(context); bsm.clear(); }
public void addStatusEvent(Status status) { if (!isStarted) return; print(status); }
@Before public void addHandler() throws Exception { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); final String xml = Resources.toString(KafkaAppenderTest.class.getResource("/logback-kafka.xml"), Charsets.UTF_8) .replaceAll("\\$KAFKA\\$", kafka.getBroker().getKafkaBrokerConnect()); final OnConsoleStatusListener listener = new OnConsoleStatusListener(); listener.start(); context.getStatusManager().add(listener); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); configurator.doConfigure(new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8))); context.start(); }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addOnConsoleListenerInstance(Context context, OnConsoleStatusListener onConsoleStatusListener) { onConsoleStatusListener.setContext(context); boolean effectivelyAdded = context.getStatusManager().add(onConsoleStatusListener); if (effectivelyAdded) { onConsoleStatusListener.start(); } } }
public void addStatusEvent(Status status) { if (!isStarted) return; print(status); }
private static void addStatusListener(LoggerContext loggerContext, String listenerClass) { StatusListener listener = null; if (ContextInitializer.SYSOUT.equalsIgnoreCase(listenerClass)) { listener = new OnConsoleStatusListener(); } else { listener = createListenerPerClassName(loggerContext, listenerClass); } initListener(loggerContext, listener); }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addNewInstanceToContext(Context context) { OnConsoleStatusListener onConsoleStatusListener = new OnConsoleStatusListener(); onConsoleStatusListener.setContext(context); onConsoleStatusListener.start(); context.getStatusManager().add(onConsoleStatusListener); }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addOnConsoleListenerInstance(Context context, OnConsoleStatusListener onConsoleStatusListener) { onConsoleStatusListener.setContext(context); boolean effectivelyAdded = context.getStatusManager().add(onConsoleStatusListener); if (effectivelyAdded) { onConsoleStatusListener.start(); } } }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LBCLASSIC-225 (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 = System.getProperty(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 { OnConsoleStatusListener.addNewInstanceToContext(context); } processScanAttrib(ic, attributes); new ContextUtil(context).addHostNameAsProperty(); // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
/** * Print status messages retrospectively */ private void retrospectivePrint() { long now = System.currentTimeMillis(); StatusManager sm = context.getStatusManager(); List<Status> statusList = sm.getCopyOfStatusList(); for (Status status : statusList) { long timestamp = status.getDate(); if (now - timestamp < retrospective) { print(status); } } }
private static void addStatusListener(Context context, String listenerClassName) { StatusListener listener = null; if (CoreConstants.SYSOUT.equalsIgnoreCase(listenerClassName)) { listener = new OnConsoleStatusListener(); } else { listener = createListenerPerClassName(context, listenerClassName); } initAndAddListener(context, listener); }
/** * This utility method adds a new OnConsoleStatusListener to the context passed as parameter. * * @param context * @since 1.0.1 */ static public void addNewInstanceToContext(Context context) { OnConsoleStatusListener onConsoleStatusListener = new OnConsoleStatusListener(); onConsoleStatusListener.setContext(context); onConsoleStatusListener.start(); context.getStatusManager().add(onConsoleStatusListener); } }
/** * This utility method adds a new OnConsoleStatusListener to the context * passed as parameter. * * @param context * @since 1.0.1 */ static public void addOnConsoleListenerInstance(Context context, OnConsoleStatusListener onConsoleStatusListener) { onConsoleStatusListener.setContext(context); boolean effectivelyAdded = context.getStatusManager().add(onConsoleStatusListener); if (effectivelyAdded) { onConsoleStatusListener.start(); } } }
/** * Print status messages retrospectively */ private void retrospectivePrint() { long now = System.currentTimeMillis(); StatusManager sm = context.getStatusManager(); List<Status> statusList = sm.getCopyOfStatusList(); for (Status status : statusList) { long timestamp = status.getDate(); if (now - timestamp < retrospective) { print(status); } } }