本文整理匯總了Java中org.apache.log4j.spi.LoggerRepository類的典型用法代碼示例。如果您正苦於以下問題:Java LoggerRepository類的具體用法?Java LoggerRepository怎麽用?Java LoggerRepository使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LoggerRepository類屬於org.apache.log4j.spi包,在下文中一共展示了LoggerRepository類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
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);
}
示例2: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
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);
}
示例3: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
* 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);
}
示例4: parseErrorHandler
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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);
}
}
}
示例5: getRenderedMessage
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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;
}
示例6: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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);
}
示例7: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
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);
}
示例8: configureRootCategory
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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);
}
}
}
示例9: getLoggers
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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[] {});
}
示例10: captureState
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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);
}
}
}
示例11: doConfigure
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
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);
}
示例12: flushAllLogs
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
* 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
}
示例13: getLoggingEvents
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
@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])));
}
示例14: getLoggingMessages
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
@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])));
}
示例15: registerLog4jMBeans
import org.apache.log4j.spi.LoggerRepository; //導入依賴的package包/類
/**
* 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());
}
}