/** Read configuration options from url <code>configURL</code>. */ public void doConfigure(java.net.URL configURL, LoggerRepository hierarchy) { Properties props = new Properties(); LogLog.debug("Reading configuration from URL " + configURL); InputStream istream = null; try { istream = configURL.openStream(); props.load(istream); } catch (Exception e) { LogLog.error("Could not read configuration file from URL [" + configURL + "].", e); LogLog.error("Ignoring configuration file [" + configURL +"]."); return; } finally { if (istream != null) { try { istream.close(); } catch(Exception ignore) { } } } doConfigure(props, hierarchy); }
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ public void doConfigure(final InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { InputSource inputSource = new InputSource(inputStream); inputSource.setSystemId("dummy://log4j.dtd"); return parser.parse(inputSource); } public String toString() { return "input stream [" + inputStream.toString() + "]"; } }; doConfigure(action, repository); }
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ public void doConfigure(final Reader reader, LoggerRepository repository) throws FactoryConfigurationError { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { InputSource inputSource = new InputSource(reader); inputSource.setSystemId("dummy://log4j.dtd"); return parser.parse(inputSource); } public String toString() { return "reader [" + reader.toString() + "]"; } }; doConfigure(action, repository); }
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ protected void doConfigure(final InputSource inputSource, LoggerRepository repository) throws FactoryConfigurationError { if (inputSource.getSystemId() == null) { inputSource.setSystemId("dummy://log4j.dtd"); } ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(inputSource); } public String toString() { return "input source [" + inputSource.toString() + "]"; } }; doConfigure(action, repository); }
/** * Read configuration options from url <code>configURL</code>. * * @since 1.2.17 */ public void doConfigure(InputStream inputStream, LoggerRepository hierarchy) { Properties props = new Properties(); try { props.load(inputStream); } catch (IOException e) { if (e instanceof InterruptedIOException) { Thread.currentThread().interrupt(); } LogLog.error("Could not read configuration file from InputStream [" + inputStream + "].", e); LogLog.error("Ignoring configuration InputStream [" + inputStream +"]."); return; } this.doConfigure(props, hierarchy); }
private void parseErrorHandler( final ErrorHandler eh, final String errorHandlerPrefix, final Properties props, final LoggerRepository hierarchy) { boolean rootRef = OptionConverter.toBoolean( OptionConverter.findAndSubst(errorHandlerPrefix + ROOT_REF, props), false); if (rootRef) { eh.setLogger(hierarchy.getRootLogger()); } String loggerName = OptionConverter.findAndSubst(errorHandlerPrefix + LOGGER_REF , props); if (loggerName != null) { Logger logger = (loggerFactory == null) ? hierarchy.getLogger(loggerName) : hierarchy.getLogger(loggerName, loggerFactory); eh.setLogger(logger); } String appenderName = OptionConverter.findAndSubst(errorHandlerPrefix + APPENDER_REF_TAG, props); if (appenderName != null) { Appender backup = parseAppender(props, appenderName); if (backup != null) { eh.setBackupAppender(backup); } } }
public String getRenderedMessage() { if(renderedMessage == null && message != null) { if(message instanceof String) renderedMessage = (String) message; else { LoggerRepository repository = logger.getLoggerRepository(); if(repository instanceof RendererSupport) { RendererSupport rs = (RendererSupport) repository; renderedMessage= rs.getRendererMap().findAndRender(message); } else { renderedMessage = message.toString(); } } } return renderedMessage; }
public void doConfigure(final URL url, LoggerRepository repository) { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { URLConnection uConn = url.openConnection(); uConn.setUseCaches(false); InputStream stream = uConn.getInputStream(); try { InputSource src = new InputSource(stream); src.setSystemId(url.toString()); return parser.parse(src); } finally { stream.close(); } } public String toString() { return "url [" + url.toString() + "]"; } }; doConfigure(action, repository); }
/** Read configuration options from url <code>configURL</code>. */ public void doConfigure(java.net.URL configURL, LoggerRepository hierarchy) { Properties props = new Properties(); LogLog.debug("Reading configuration from URL " + configURL); try { props.load(configURL.openStream()); } catch (java.io.IOException e) { LogLog.error("Could not read configuration file from URL [" + configURL + "].", e); LogLog.error("Ignoring configuration file [" + configURL +"]."); return; } doConfigure(props, hierarchy); }
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); } } }
public String[] getLoggers(String filter) { LoggerRepository r = LogManager.getLoggerRepository(); Enumeration<Logger> enumList = r.getCurrentLoggers(); Logger logger = null; List<String> resultList = new ArrayList<String>(); while (enumList.hasMoreElements()) { logger = (Logger) enumList.nextElement(); if (filter == null || (filter != null && logger.getName().contains(filter))) { resultList.add(logger.getName()); } } return (String[]) resultList.toArray(new String[] {}); }
private synchronized void captureState(LoggerRepository hierarchy) throws IllegalStateException { if (null == hierarchy) { throw new IllegalArgumentException("Null Hierarchy is not allowed."); } if (null != capturedHierarchy && capturedHierarchy != hierarchy) { throw new IllegalStateException("Log configurations is already holding a captured hierarchy."); } capturedHierarchy = hierarchy; threshold = hierarchy.getThreshold(); Enumeration e = hierarchy.getCurrentLoggers(); while (e.hasMoreElements()) { Logger l = (Logger)e.nextElement(); Level v = l.getLevel(); // No point in capturing or restoring NULL loggers. if (null != v) { capturedConfiguration.addConfiguration(l.getName(), v); } } }
public void doConfigure(Properties properties, LoggerRepository repository) { String logParams = System.getenv(TezConstants.TEZ_CONTAINER_LOG_PARAMS); if (logParams != null) { String []parts = logParams.split(TezConstants.TEZ_CONTAINER_LOG_PARAMS_SEPARATOR); for (String logParam : parts) { String [] logParamParts = logParam.split("="); if (logParamParts.length == 2) { String loggerName = "log4j.logger." + logParamParts[0]; String logLevel = logParamParts[1].toUpperCase(Locale.ENGLISH); properties.setProperty(loggerName, logLevel); } else { // Cannot use Log4J logging from here. System.out.println("TezLog4jConfigurator Ignoring invalid log parameter [" + logParam + "]"); continue; } } } super.doConfigure(properties, repository); }
/** * Flush the appenders for all of the active loggers */ public static void flushAllLogs() { LoggerRepository loggerRepo = LogManager.getLoggerRepository(); for (Logger logger : CollectionUtil.iterable(loggerRepo.getCurrentLoggers(), Logger.class)) { LoggerUtil.flushLogs(logger); } // FOR }
@SuppressWarnings("unchecked") public static Collection<LoggingEvent> getLoggingEvents(LoggerRepository repo) { Set<Logger> loggers = new HashSet<Logger>(); for (Object o : CollectionUtil.iterable(repo.getCurrentLoggers())) { Logger logger = (Logger)o; RingBufferAppender rba = getRingBufferAppender(logger); if (rba != null) { if (LOG.isDebugEnabled()) LOG.debug(logger.getName() + " => " + rba + " / " + rba.getLayout()); loggers.add(logger); } } // FOR if (loggers.isEmpty()) return (Collections.emptyList()); return (getLoggingEvents(loggers.toArray(new Logger[0]))); }
@SuppressWarnings("unchecked") public static Collection<String> getLoggingMessages(LoggerRepository repo) { Set<RingBufferAppender> appenders = new HashSet<RingBufferAppender>(); for (Object o : CollectionUtil.iterable(repo.getCurrentLoggers())) { Logger logger = (Logger)o; RingBufferAppender rba = getRingBufferAppender(logger); if (rba != null) { if (LOG.isDebugEnabled()) LOG.debug(logger.getName() + " => " + rba + " / " + rba.getLayout()); appenders.add(rba); } } // FOR if (appenders.isEmpty()) return (Collections.emptyList()); return (getLoggingMessages(appenders.toArray(new RingBufferAppender[0]))); }
/** * Register the log4j JMX mbeans. Set environment variable * "zookeeper.jmx.log4j.disable" to true to disable registration. * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html * @throws JMException if registration fails */ public static void registerLog4jMBeans() throws JMException { if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) { return; } MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer(); // Create and Register the top level Log4J MBean HierarchyDynamicMBean hdm = new HierarchyDynamicMBean(); ObjectName mbo = new ObjectName("log4j:hiearchy=default"); mbs.registerMBean(hdm, mbo); // Add the root logger to the Hierarchy MBean Logger rootLogger = Logger.getRootLogger(); hdm.addLoggerMBean(rootLogger.getName()); // Get each logger from the Log4J Repository and add it to // the Hierarchy MBean created above. LoggerRepository r = LogManager.getLoggerRepository(); Enumeration enumer = r.getCurrentLoggers(); Logger logger = null; while (enumer.hasMoreElements()) { logger = (Logger) enumer.nextElement(); hdm.addLoggerMBean(logger.getName()); } }
/** * Register the log4j JMX mbeans. Set environment variable * "zookeeper.jmx.log4j.disable" to true to disable registration. * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html * @throws JMException if registration fails */ public static void registerLog4jMBeans() throws JMException { if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) { return; } MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); // Create and Register the top level Log4J MBean HierarchyDynamicMBean hdm = new HierarchyDynamicMBean(); ObjectName mbo = new ObjectName("log4j:hiearchy=default"); mbs.registerMBean(hdm, mbo); // Add the root logger to the Hierarchy MBean Logger rootLogger = Logger.getRootLogger(); hdm.addLoggerMBean(rootLogger.getName()); // Get each logger from the Log4J Repository and add it to // the Hierarchy MBean created above. LoggerRepository r = LogManager.getLoggerRepository(); Enumeration enumer = r.getCurrentLoggers(); Logger logger = null; while (enumer.hasMoreElements()) { logger = (Logger) enumer.nextElement(); hdm.addLoggerMBean(logger.getName()); } }
/** * Register the log4j JMX mbeans. Set environment variable * "zookeeper.jmx.log4j.disable" to true to disable registration. * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html * @throws JMException if registration fails */ public static void registerLog4jMBeans() throws JMException { // 设置zookeeper.jmx.log4j.disable=true, 禁用注册Log4j的MBean if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) { return; } MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer(); // Create and Register the top level Log4J MBean HierarchyDynamicMBean hdm = new HierarchyDynamicMBean(); ObjectName mbo = new ObjectName("log4j:hiearchy=default"); mbs.registerMBean(hdm, mbo); // Add the root logger to the Hierarchy MBean Logger rootLogger = Logger.getRootLogger(); hdm.addLoggerMBean(rootLogger.getName()); // Get each logger from the Log4J Repository and add it to // the Hierarchy MBean created above. LoggerRepository r = LogManager.getLoggerRepository(); Enumeration enumer = r.getCurrentLoggers(); Logger logger = null; while (enumer.hasMoreElements()) { logger = (Logger) enumer.nextElement(); hdm.addLoggerMBean(logger.getName()); } }
/** 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(); }
/** 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); } } } }
public void doConfigure(final String filename, LoggerRepository repository) { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(new File(filename)); } public String toString() { return "file [" + filename + "]"; } }; doConfigure(action, repository); }
public void doConfigure(final URL url, LoggerRepository repository) { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(url.toString()); } public String toString() { return "url [" + url.toString() + "]"; } }; doConfigure(action, repository); }
/** Read configuration options from <code>properties</code>. See {@link #doConfigure(String, LoggerRepository)} for the expected format. */ public void doConfigure(Properties properties, LoggerRepository hierarchy) { repository = 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(); }