本文整理匯總了Java中org.apache.geode.internal.logging.LogService.getAppenderContext方法的典型用法代碼示例。如果您正苦於以下問題:Java LogService.getAppenderContext方法的具體用法?Java LogService.getAppenderContext怎麽用?Java LogService.getAppenderContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.geode.internal.logging.LogService
的用法示例。
在下文中一共展示了LogService.getAppenderContext方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAppenderToConfigHandling
import org.apache.geode.internal.logging.LogService; //導入方法依賴的package包/類
/**
* Verifies that the appender is correctly added and removed from the Log4j configuration and that
* when the configuration is changed the appender is still there.
*/
@Test
public final void testAppenderToConfigHandling() throws IOException {
LogService.setBaseLogLevel(Level.TRACE);
final AppenderContext rootContext = LogService.getAppenderContext();
// Find out home many appenders exist before we get started
final int startingSize = rootContext.getLoggerConfig().getAppenders().size();
// System.out.println("Appenders " +
// context.getLoggerConfig().getAppenders().values().toString());
// Create the appender and verify it's part of the configuration
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
new PureLogWriter(InternalLogWriter.FINE_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
contexts[0] = rootContext; // root context
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
this.appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize + 1,
rootContext.getLoggerConfig().getAppenders().size());
assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
// Modify the config and verify that the appender still exists
assertEquals(Level.TRACE, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
LogService.setBaseLogLevel(Level.DEBUG);
assertEquals(Level.DEBUG, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
assertTrue(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
// Destroy the appender and verify that it was removed from log4j
this.appender.destroy();
assertEquals(rootContext.getLoggerConfig().getAppenders().values().toString(), startingSize,
rootContext.getLoggerConfig().getAppenders().size());
assertFalse(rootContext.getLoggerConfig().getAppenders().containsKey(this.appender.getName()));
}
示例2: testLogOutput
import org.apache.geode.internal.logging.LogService; //導入方法依賴的package包/類
/**
* Verifies that writing to a Log4j logger will end up in the LogWriter's output.
*/
@Test
public final void testLogOutput() throws IOException {
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
contexts[0] = LogService.getAppenderContext(); // root context
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
this.appender =
LogWriterAppender.create(contexts, LogService.MAIN_LOGGER_NAME, logWriter, null);
final Logger logger = LogService.getLogger();
// set the level to TRACE
Configurator.setLevel(LogService.BASE_LOGGER_NAME, Level.TRACE);
Configurator.setLevel(LogService.MAIN_LOGGER_NAME, Level.TRACE);
assertEquals(Level.TRACE, logger.getLevel());
logger.trace("TRACE MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*TRACE MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.debug("DEBUG MESSAGE");
assertTrue(Pattern.compile(".*\\[fine .*DEBUG MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.info("INFO MESSAGE");
assertTrue(Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.warn("ExpectedStrings: WARNING MESSAGE");
assertTrue(Pattern.compile(".*\\[warning .*WARNING MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.error("ExpectedStrings: ERROR MESSAGE");
assertTrue(Pattern.compile(".*\\[error .*ERROR MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
final Logger lowerLevelLogger =
LogService.getLogger(LogService.BASE_LOGGER_NAME + ".subpackage");
lowerLevelLogger.fatal("ExpectedStrings: FATAL MESSAGE");
assertTrue(Pattern.compile(".*\\[severe .*FATAL MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
this.appender.destroy();
assertFalse(Configurator.getLoggerConfig(LogService.BASE_LOGGER_NAME).getAppenders()
.containsKey(this.appender.getName()));
}
示例3: testLogWriterLevels
import org.apache.geode.internal.logging.LogService; //導入方法依賴的package包/類
/**
* Verifies that logging occurs at the levels set in the LogWriter
*/
@Test
public final void testLogWriterLevels() throws IOException {
final String loggerName = LogService.MAIN_LOGGER_NAME; // this.getClass().getName();
LogService.getLogger(); // Force logging to be initialized
// Create the LogWriterLogger that will be attached to the appender
final LogWriterLogger logWriterLogger = LogWriterLogger.create(loggerName, false);
logWriterLogger.setLevel(Level.INFO);
// Create the appender
final StringWriter stringWriter = new StringWriter();
final PureLogWriter logWriter =
new PureLogWriter(InternalLogWriter.FINEST_LEVEL, new PrintWriter(stringWriter), "");
final AppenderContext[] contexts = new AppenderContext[2];
contexts[0] = LogService.getAppenderContext(); // root context
contexts[1] = LogService.getAppenderContext(LogService.BASE_LOGGER_NAME); // "org.apache"
// context
this.appender = LogWriterAppender.create(contexts, loggerName, logWriter, null);
logWriter.finest("DIRECT MESSAGE");
assertTrue(Pattern.compile(".*\\[finest .*DIRECT MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerFqcn("NAME")
.setLoggerName("NAME").setMessage(new ParameterizedMessage("LOGEVENT MESSAGE")).build();
this.appender.append(event);
assertTrue(Pattern.compile(".*\\[info .*LOGEVENT MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.finest("FINEST MESSAGE");
assertFalse(Pattern.compile(".*\\[finest .*FINEST MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.fine("FINE MESSAGE");
assertFalse(Pattern.compile(".*\\[fine .*FINE MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.info("INFO MESSAGE");
assertTrue(stringWriter.toString(),
Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
// Change the level
logWriterLogger.setLevel(Level.DEBUG);
logWriterLogger.finest("FINEST MESSAGE");
assertFalse(Pattern.compile(".*\\[finest .*FINEST MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.fine("FINE MESSAGE");
assertTrue(Pattern.compile(".*\\[fine .*FINE MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
logWriterLogger.info("INFO MESSAGE");
assertTrue(Pattern.compile(".*\\[info .*INFO MESSAGE.*", Pattern.DOTALL)
.matcher(stringWriter.toString()).matches());
stringWriter.getBuffer().setLength(0);
this.appender.destroy();
}
示例4: testAppenderToConfigHandling
import org.apache.geode.internal.logging.LogService; //導入方法依賴的package包/類
/**
* Verifies that the appender is correctly added and removed from the Log4j configuration and that
* when the configuration is changed the appender is still there.
*/
@Test
public final void testAppenderToConfigHandling() throws Exception {
LogService.setBaseLogLevel(Level.WARN);
final String appenderName = AlertAppender.getInstance().getName();
final AppenderContext appenderContext = LogService.getAppenderContext();
LoggerConfig loggerConfig = appenderContext.getLoggerConfig();
// Find out home many appenders exist before we get started
final int startingSize = loggerConfig.getAppenders().size();
// Add a listener and verify that the appender was added to log4j
DistributedMember member1 = createTestDistributedMember("Member1");
AlertAppender.getInstance().addAlertListener(member1, Alert.SEVERE);
assertEquals(loggerConfig.getAppenders().values().toString(), startingSize + 1,
loggerConfig.getAppenders().size());
assertTrue(loggerConfig.getAppenders().containsKey(appenderName));
// Add another listener and verify that there's still only 1 alert appender
DistributedMember member2 = createTestDistributedMember("Member1");
AlertAppender.getInstance().addAlertListener(member2, Alert.SEVERE);
assertEquals(startingSize + 1, loggerConfig.getAppenders().size());
// Modify the config and verify that the appender still exists
assertEquals(Level.WARN, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
LogService.setBaseLogLevel(Level.INFO);
assertEquals(Level.INFO, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
loggerConfig = appenderContext.getLoggerConfig();
assertEquals(startingSize + 1, loggerConfig.getAppenders().size());
assertTrue(loggerConfig.getAppenders().containsKey(appenderName));
// Remove the listeners and verify that the appender was removed from log4j
assertTrue(AlertAppender.getInstance().removeAlertListener(member2));
assertFalse(AlertAppender.getInstance().removeAlertListener(member1));
assertEquals(startingSize, loggerConfig.getAppenders().size());
assertFalse(loggerConfig.getAppenders().containsKey(appenderName));
}