Java Code Examples for org.apache.log4j.helpers.OptionConverter#findAndSubst()
The following examples show how to use
org.apache.log4j.helpers.OptionConverter#findAndSubst() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
void configureRootCategory(Properties props, LoggerRepository hierarchy) { String effectiveFrefix = ROOT_LOGGER_PREFIX; String value = OptionConverter.findAndSubst(ROOT_LOGGER_PREFIX, props); if(value == null) { value = OptionConverter.findAndSubst(ROOT_CATEGORY_PREFIX, props); effectiveFrefix = ROOT_CATEGORY_PREFIX; } if(value == null) LogLog.debug("Could not find root logger information. Is this OK?"); else { Logger root = hierarchy.getRootLogger(); synchronized(root) { parseCategory(props, root, effectiveFrefix, INTERNAL_ROOT_NAME, value); } } }
Example 2
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 6 votes |
private void configureRoot(Properties props) { String effectiveFrefix = ROOT_LOGGER_PREFIX; String value = OptionConverter.findAndSubst(ROOT_LOGGER_PREFIX, props); if (value == null) { value = OptionConverter.findAndSubst(ROOT_CATEGORY_PREFIX, props); effectiveFrefix = ROOT_CATEGORY_PREFIX; } if (value == null) { LOGGER.debug("Could not find root logger information. Is this OK?"); } else { LoggerConfig root = getRootLogger(); parseLogger(props, root, effectiveFrefix, INTERNAL_ROOT_NAME, value); } }
Example 3
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public Appender parseAppender(Properties props, String appenderName) { Appender appender = registry.get(appenderName); if ((appender != null)) { LOGGER.debug("Appender \"" + appenderName + "\" was already parsed."); return appender; } // Appender was not previously initialized. final String prefix = APPENDER_PREFIX + appenderName; final String layoutPrefix = prefix + ".layout"; final String filterPrefix = APPENDER_PREFIX + appenderName + ".filter."; String className = OptionConverter.findAndSubst(prefix, props); appender = manager.parseAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props, this); if (appender == null) { appender = buildAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props); } else { registry.put(appenderName, appender); if (appender instanceof AppenderWrapper) { addAppender(((AppenderWrapper) appender).getAppender()); } else { addAppender(new AppenderAdapter(appender).getAdapter()); } } return appender; }
Example 4
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Read configuration options from <code>properties</code>. See {@link #doConfigure(String, LoggerRepository)} for the expected format. */ public void doConfigure(Properties properties, LoggerRepository hierarchy) { String value = properties.getProperty(LogLog.DEBUG_KEY); if(value == null) { value = properties.getProperty("log4j.configDebug"); if(value != null) LogLog.warn("[log4j.configDebug] is deprecated. Use [log4j.debug] instead."); } if(value != null) { LogLog.setInternalDebugging(OptionConverter.toBoolean(value, true)); } // // if log4j.reset=true then // reset hierarchy String reset = properties.getProperty(RESET_KEY); if (reset != null && OptionConverter.toBoolean(reset, false)) { hierarchy.resetConfiguration(); } String thresholdStr = OptionConverter.findAndSubst(THRESHOLD_PREFIX, properties); if(thresholdStr != null) { hierarchy.setThreshold(OptionConverter.toLevel(thresholdStr, (Level) Level.ALL)); LogLog.debug("Hierarchy threshold set to ["+hierarchy.getThreshold()+"]."); } configureRootCategory(properties, hierarchy); configureLoggerFactory(properties); parseCatsAndRenderers(properties, hierarchy); LogLog.debug("Finished configuring."); // We don't want to hold references to appenders preventing their // garbage collection. registry.clear(); }
Example 5
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Check the provided <code>Properties</code> object for a {@link org.apache.log4j.spi.LoggerFactory LoggerFactory} entry specified by {@link #LOGGER_FACTORY_KEY}. If such an entry exists, an attempt is made to create an instance using the default constructor. This instance is used for subsequent Category creations within this configurator. @see #parseCatsAndRenderers */ protected void configureLoggerFactory(Properties props) { String factoryClassName = OptionConverter.findAndSubst(LOGGER_FACTORY_KEY, props); if(factoryClassName != null) { LogLog.debug("Setting category factory to ["+factoryClassName+"]."); loggerFactory = (LoggerFactory) OptionConverter.instantiateByClassName(factoryClassName, LoggerFactory.class, loggerFactory); PropertySetter.setProperties(loggerFactory, props, FACTORY_PREFIX + "."); } }
Example 6
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Parse non-root elements, such non-root categories and renderers. */ protected void parseCatsAndRenderers(Properties props, LoggerRepository hierarchy) { Enumeration enumeration = props.propertyNames(); while(enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); if(key.startsWith(CATEGORY_PREFIX) || key.startsWith(LOGGER_PREFIX)) { String loggerName = null; if(key.startsWith(CATEGORY_PREFIX)) { loggerName = key.substring(CATEGORY_PREFIX.length()); } else if(key.startsWith(LOGGER_PREFIX)) { loggerName = key.substring(LOGGER_PREFIX.length()); } String value = OptionConverter.findAndSubst(key, props); Logger logger = hierarchy.getLogger(loggerName, loggerFactory); synchronized(logger) { parseCategory(props, logger, key, loggerName, value); parseAdditivityForLogger(props, logger, loggerName); } } else if(key.startsWith(RENDERER_PREFIX)) { String renderedClass = key.substring(RENDERER_PREFIX.length()); String renderingClass = OptionConverter.findAndSubst(key, props); if(hierarchy instanceof RendererSupport) { RendererMap.addRenderer((RendererSupport) hierarchy, renderedClass, renderingClass); } } } }
Example 7
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Parse the additivity option for a non-root category. */ void parseAdditivityForLogger(Properties props, Logger cat, String loggerName) { String value = OptionConverter.findAndSubst(ADDITIVITY_PREFIX + loggerName, props); LogLog.debug("Handling "+ADDITIVITY_PREFIX + loggerName+"=["+value+"]"); // touch additivity only if necessary if((value != null) && (!value.equals(""))) { boolean additivity = OptionConverter.toBoolean(value, true); LogLog.debug("Setting additivity for \""+loggerName+"\" to "+ additivity); cat.setAdditivity(additivity); } }
Example 8
Source File: PropertySetter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Set the properites for the object that match the <code>prefix</code> passed as parameter. */ public void setProperties(Properties properties, String prefix) { int len = prefix.length(); for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); // handle only properties that start with the desired frefix. if (key.startsWith(prefix)) { // ignore key if it contains dots after the prefix if (key.indexOf('.', len + 1) > 0) { //System.err.println("----------Ignoring---["+key // +"], prefix=["+prefix+"]."); continue; } String value = OptionConverter.findAndSubst(key, properties); key = key.substring(len); if ("layout".equals(key) && obj instanceof Appender) { continue; } setProperty(key, value); } } activate(); }
Example 9
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Parse the additivity option for a non-root category. */ private boolean getAdditivityForLogger(Properties props, String loggerName) { boolean additivity = true; String key = ADDITIVITY_PREFIX + loggerName; String value = OptionConverter.findAndSubst(key, props); LOGGER.debug("Handling {}=[{}]", key, value); // touch additivity only if necessary if ((value != null) && (!value.equals(""))) { additivity = OptionConverter.toBoolean(value, true); } return additivity; }
Example 10
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private Appender buildAppender(final String appenderName, final String className, final String prefix, final String layoutPrefix, final String filterPrefix, final Properties props) { Appender appender = newInstanceOf(className, "Appender"); if (appender == null) { return null; } appender.setName(appenderName); appender.setLayout(parseLayout(layoutPrefix, appenderName, props)); final String errorHandlerPrefix = prefix + ".errorhandler"; String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props); if (errorHandlerClass != null) { ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender); if (eh != null) { appender.setErrorHandler(eh); } } parseAppenderFilters(props, filterPrefix, appenderName); String[] keys = new String[] { layoutPrefix, }; addProperties(appender, keys, props, prefix); if (appender instanceof AppenderWrapper) { addAppender(((AppenderWrapper) appender).getAppender()); } else { addAppender(new AppenderAdapter(appender).getAdapter()); } registry.put(appenderName, appender); return appender; }
Example 11
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public Layout parseLayout(String layoutPrefix, String appenderName, Properties props) { String layoutClass = OptionConverter.findAndSubst(layoutPrefix, props); if (layoutClass == null) { return null; } Layout layout = manager.parseLayout(layoutClass, layoutPrefix, props, this); if (layout == null) { layout = buildLayout(layoutPrefix, layoutClass, appenderName, props); } return layout; }
Example 12
Source File: PropertiesConfiguration.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public Filter parseAppenderFilters(Properties props, String filterPrefix, String appenderName) { // extract filters and filter options from props into a hashtable mapping // the property name defining the filter class to a list of pre-parsed // name-value pairs associated to that filter int fIdx = filterPrefix.length(); SortedMap<String, List<NameValue>> filters = new TreeMap<>(); Enumeration e = props.keys(); String name = ""; while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (key.startsWith(filterPrefix)) { int dotIdx = key.indexOf('.', fIdx); String filterKey = key; if (dotIdx != -1) { filterKey = key.substring(0, dotIdx); name = key.substring(dotIdx + 1); } List<NameValue> filterOpts = filters.computeIfAbsent(filterKey, k -> new ArrayList<>()); if (dotIdx != -1) { String value = OptionConverter.findAndSubst(key, props); filterOpts.add(new NameValue(name, value)); } } } Filter head = null; Filter next = null; for (Map.Entry<String, List<NameValue>> entry : filters.entrySet()) { String clazz = props.getProperty(entry.getKey()); Filter filter = null; if (clazz != null) { filter = manager.parseFilter(clazz, filterPrefix, props, this); if (filter == null) { LOGGER.debug("Filter key: [{}] class: [{}] props: {}", entry.getKey(), clazz, entry.getValue()); filter = buildFilter(clazz, appenderName, entry.getValue()); } } if (filter != null) { if (head != null) { head = filter; next = filter; } else { next.setNext(filter); next = filter; } } } return head; }