/** * {@inheritDoc} */ protected void onStop() { if (socket != null) { CloseUtil.closeQuietly(socket); } }
private static ClassLoader getServiceLoaderClassLoader() { return testServiceLoaderClassLoader == null ? Loader.getClassLoaderOfClass(EnvUtil.class) : testServiceLoaderClassLoader; }
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; }
private void configureLoggerContextByURL(LoggerContext context, URL url) { try { JoranConfigurator configurator = new JoranConfigurator(); context.reset(); configurator.setContext(context); configurator.doConfigure(url); } catch (JoranException e) { } StatusPrinter.printInCaseOfErrorsOrWarnings(context); }
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()); }
private URL urlByResourceName(StatusManager sm, String resourceName) { sm.add(new InfoStatus("Searching for [" + resourceName + "]", this)); URL url = Loader.getResource(resourceName, Loader.getTCL()); if (url != null) { return url; } return Loader.getResourceBySelfClassLoader(resourceName); }
/** * Search for value of DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY in the web-app first, then as a system property and * as an environment variable last. * * @param ctx * @return True if value of DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY is available and set to "true", false otherwise. */ boolean isDisabledByConfiguration(ServletContext ctx) { String disableAttributeStr = null; Object disableAttribute = ctx.getInitParameter(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); if (disableAttribute instanceof String) { disableAttributeStr = (String) disableAttribute; } if (OptionHelper.isEmpty(disableAttributeStr)) { disableAttributeStr = OptionHelper.getSystemProperty(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } if (OptionHelper.isEmpty(disableAttributeStr)) { disableAttributeStr = OptionHelper.getEnv(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } if (OptionHelper.isEmpty(disableAttributeStr)) return false; return disableAttributeStr.equalsIgnoreCase("true"); }
private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) { String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY); if (logbackConfigFile != null) { URL result = null; try { result = new URL(logbackConfigFile); return result; } catch (MalformedURLException e) { // so, resource is not a URL: // attempt to get the resource from the class path result = Loader.getResource(logbackConfigFile, classLoader); if (result != null) { return result; } File f = new File(logbackConfigFile); if (f.exists() && f.isFile()) { try { result = f.toURI().toURL(); return result; } catch (MalformedURLException e1) { } } } finally { if (updateStatus) { statusOnResourceSearch(logbackConfigFile, classLoader, result); } } } return null; }
protected TriggeringPolicy buildTriggeringPolicy() { SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy(); triggeringPolicy.setContext(loggerContext); triggeringPolicy.setMaxFileSize(FileSize.valueOf(maxLogFileSize)); triggeringPolicy.start(); return triggeringPolicy; }
private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) { URL url = Loader.getResource(filename, myClassLoader); if (updateStatus) { statusOnResourceSearch(filename, myClassLoader, url); } return url; }
public String convert(ILoggingEvent le) { long timestamp = le.getTimeStamp(); return cachingDateFormatter.format(timestamp); } }
/** * Instantiate the context selector class designated by the user. The selector * must have a constructor taking a LoggerContext instance as an argument. * * @param defaultLoggerContext * @param contextSelectorStr * @return an instance of the designated context selector class * @throws ClassNotFoundException * @throws SecurityException * @throws NoSuchMethodException * @throws IllegalArgumentException * @throws InstantiationException * @throws IllegalAccessException * @throws InvocationTargetException */ static ContextSelector dynamicalContextSelector(LoggerContext defaultLoggerContext, String contextSelectorStr) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr); Constructor cons = contextSelectorClass.getConstructor(new Class[] { LoggerContext.class }); return (ContextSelector) cons.newInstance(defaultLoggerContext); }
public URL findURLOfDefaultConfigurationFile(boolean updateStatus) { ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this); URL url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus); if (url != null) { return url; } url = getResource(TEST_AUTOCONFIG_FILE, myClassLoader, updateStatus); if (url != null) { return url; } url = getResource(GROOVY_AUTOCONFIG_FILE, myClassLoader, updateStatus); if (url != null) { return url; } return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus); }
@Override public void start() { String[] keyInfo = extractDefaultReplacement(getFirstOption()); key = keyInfo[0]; if (keyInfo[1] != null) { defaultValue = keyInfo[1]; } super.start(); }
protected void configureWith(URL resource) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext((LoggerContext) loggerFactory); ((LoggerContext) loggerFactory).reset(); // the statusManager keeps a copy of all logback status messages even after reset, so we clear that ((LoggerContext) loggerFactory).getStatusManager().clear(); try { configurator.doConfigure(resource); } catch (JoranException ignore) { } StatusPrinter.printInCaseOfErrorsOrWarnings((Context) loggerFactory); }
public static void rollingPolicyForAppender(RollingFileAppender rollingFileAppender, String maxFileSize, String totalSizeCap, int maxHistory) { SizeAndTimeBasedRollingPolicy rollingPolicy = new SizeAndTimeBasedRollingPolicy(); rollingPolicy.setContext(LOGGER_CONTEXT); rollingPolicy.setMaxHistory(maxHistory); rollingPolicy.setMaxFileSize(FileSize.valueOf(maxFileSize)); rollingPolicy.setTotalSizeCap(FileSize.valueOf(totalSizeCap)); rollingPolicy.setFileNamePattern(rollingFileAppender.rawFileProperty() + ".%d{yyyy-MM-dd}.%i.gz"); rollingPolicy.setParent(rollingFileAppender); rollingFileAppender.setRollingPolicy(rollingPolicy); rollingPolicy.start(); }
@Override public void start() { key = getFirstOption(); if (OptionHelper.isEmpty(key)) { addWarn("Missing key for the request parameter"); } else { super.start(); } }
static public boolean isGroovyAvailable() { ClassLoader classLoader = Loader.getClassLoaderOfClass(EnvUtil.class); try { Class<?> bindingClass = classLoader.loadClass("groovy.lang.Binding"); return (bindingClass != null); } catch (ClassNotFoundException e) { return false; } }
/** * {@inheritDoc} */ public void close() { if (socket == null) return; CloseUtil.closeQuietly(socket); }