本文整理汇总了Java中org.apache.log4j.Logger.getAppender方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.getAppender方法的具体用法?Java Logger.getAppender怎么用?Java Logger.getAppender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Logger
的用法示例。
在下文中一共展示了Logger.getAppender方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: smoketestByArn
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void smoketestByArn() throws Exception
{
setUp("SNSAppenderIntegrationTest-smoketestByArn.properties");
localLogger.info("smoketest: starting");
createTopicAndQueue();
final int numMessages = 11;
Logger testLogger = Logger.getLogger("TestLogger");
SNSAppender appender = (SNSAppender)testLogger.getAppender("test");
(new MessageWriter(testLogger, numMessages)).run();
localLogger.info("smoketest: reading messages");
List<String> messages = retrieveMessages(numMessages);
assertEquals("number of messages", numMessages, messages.size());
assertMessageContent(messages, "");
assertEquals("client factory called", "com.kdgregory.log4j.aws.SNSAppenderIntegrationTest.createClient",
getWriter(appender).getClientFactoryUsed());
}
示例2: smoketest
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void smoketest() throws Exception
{
final String streamName = "AppenderIntegrationTest-smoketest";
final int numMessages = 1001;
setUp("KinesisAppenderIntegrationTest-smoketest.properties", streamName);
localLogger.info("smoketest: starting");
Logger testLogger = Logger.getLogger("TestLogger");
KinesisAppender appender = (KinesisAppender)testLogger.getAppender("test");
(new MessageWriter(testLogger, numMessages)).run();
localLogger.info("smoketest: reading messages");
List<RetrievedRecord> messages = retrieveAllMessages(streamName, numMessages);
assertMessages(messages, 1, numMessages, "test");
assertShardCount(streamName, 1);
assertRetentionPeriod(streamName, 48);
assertEquals("client factory called", "com.kdgregory.log4j.aws.KinesisAppenderIntegrationTest.createClient", getWriter(appender).getClientFactoryUsed());
localLogger.info("smoketest: finished");
}
示例3: setup
import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
* Sets ripper's:
* Working directory
* Logger (for debugging)
* FileAppender
* Threadpool
* @throws IOException
* Always be prepared.
*/
public void setup() throws IOException {
setWorkingDir(this.url);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
fa.setFile(this.workingDir + File.separator + "log.txt");
fa.activateOptions();
}
this.threadPool = new DownloadThreadPool();
}
示例4: init
import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
* Initializes the log4j logging with an additional appender which routes the logging to the Eclipse ErrorView.
*/
public static void init() {
Logger rootLogger = Logger.getRootLogger();
// # This appender will write to the Eclipse error log. It will ONLY log ERROR and FATAL messages.
// log4j.appender.eclipse=org.eclipse.xtext.logging.EclipseLogAppender
EclipseLogAppender eclipseAppender = new EclipseLogAppender();
eclipseAppender.setName("eclipse");
rootLogger.addAppender(eclipseAppender);
// log4j.appender.eclipse.layout=org.apache.log4j.PatternLayout
// log4j.appender.eclipse.layout.ConversionPattern=%c %x - %m%n
eclipseAppender.setLayout(new PatternLayout("%c %x - %m%n"));
// # EclipseLogAppender must not log to the 'eclipse' appender as that would cause a stack overflow!
// log4j.additivity.org.eclipse.xtext.logging.EclipseLogAppender=false
// log4j.logger.org.eclipse.xtext.logging.EclipseLogAppender=WARN, default
Logger eclipseAppenderLogger = Logger.getLogger(EclipseLogAppender.class);
eclipseAppenderLogger.setAdditivity(false);
eclipseAppenderLogger.setLevel(Level.WARN);
Appender defaultAppender = eclipseAppenderLogger.getAppender("default");
if (eclipseAppenderLogger.getAllAppenders().hasMoreElements()) {
eclipseAppenderLogger.removeAllAppenders();
}
if (defaultAppender != null) {
eclipseAppenderLogger.addAppender(defaultAppender);
}
}
示例5: checkIfComplete
import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
* Notifies observers and updates state if all files have been ripped.
*/
void checkIfComplete() {
if (observer == null) {
logger.debug("observer is null");
return;
}
if (!completed) {
completed = true;
logger.info(" Rip completed!");
RipStatusComplete rsc = new RipStatusComplete(workingDir, getCount());
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, rsc);
observer.update(this, msg);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
logger.debug("Changing log file back to 'ripme.log'");
fa.setFile("ripme.log");
fa.activateOptions();
}
if (Utils.getConfigBoolean("urls_only.save", false)) {
String urlFile = this.workingDir + File.separator + "urls.txt";
try {
Desktop.getDesktop().open(new File(urlFile));
} catch (IOException e) {
logger.warn("Error while opening " + urlFile, e);
}
}
}
}
示例6: initialize
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void initialize(String propsName)
throws Exception
{
URL config = ClassLoader.getSystemResource(propsName);
assertNotNull("was able to retrieve config", config);
PropertyConfigurator.configure(config);
logger = Logger.getLogger(getClass());
Logger rootLogger = Logger.getRootLogger();
appender = (TestableCloudWatchAppender)rootLogger.getAppender("default");
appender.setThreadFactory(new InlineThreadFactory());
appender.setWriterFactory(new MockCloudWatchWriterFactory(appender));
}
示例7: initialize
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void initialize(String propsName)
throws Exception
{
URL config = ClassLoader.getSystemResource(propsName);
assertNotNull("was able to retrieve config", config);
PropertyConfigurator.configure(config);
logger = Logger.getLogger(getClass());
Logger rootLogger = Logger.getRootLogger();
appender = (TestableSNSAppender)rootLogger.getAppender("default");
appender.setThreadFactory(new InlineThreadFactory());
appender.setWriterFactory(new MockSNSWriterFactory());
}
示例8: initialize
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void initialize(String propsName)
throws Exception
{
URL config = ClassLoader.getSystemResource(propsName);
assertNotNull("was able to retrieve config", config);
PropertyConfigurator.configure(config);
logger = Logger.getLogger(getClass());
Logger rootLogger = Logger.getRootLogger();
appender = (TestableKinesisAppender)rootLogger.getAppender("default");
appender.setThreadFactory(new InlineThreadFactory());
appender.setWriterFactory(new MockKinesisWriterFactory(appender));
}
示例9: initialize
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void initialize(String propsName)
throws Exception
{
URL config = ClassLoader.getSystemResource(propsName);
PropertyConfigurator.configure(config);
logger = Logger.getLogger(getClass());
Logger rootLogger = Logger.getRootLogger();
appender = (WriterAppender)rootLogger.getAppender("default");
writer = new StringWriter();
appender.setWriter(writer);
}
示例10: smoketest
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void smoketest() throws Exception
{
final String logGroupName = "AppenderIntegrationTest-smoketest";
final int numMessages = 1001;
final int rotationCount = 333;
setUp("CloudWatchAppenderIntegrationTest-smoketest.properties", logGroupName);
localLogger.info("smoketest: starting");
Logger testLogger = Logger.getLogger("TestLogger");
CloudWatchAppender appender = (CloudWatchAppender)testLogger.getAppender("test");
(new MessageWriter(testLogger, numMessages)).run();
localLogger.info("smoketest: all messages written; sleeping to give writers chance to run");
Thread.sleep(5000);
assertMessages(logGroupName, LOGSTREAM_BASE + "1", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "2", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "3", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "4", numMessages % rotationCount);
CloudWatchLogWriter lastWriter = getWriter(appender);
assertEquals("number of batches for last writer", 1, lastWriter.getBatchCount());
assertEquals("client factory", "com.kdgregory.log4j.aws.CloudWatchAppenderIntegrationTest.createClient", lastWriter.getClientFactoryUsed());
// while we're here, verify that batch delay is propagated
appender.setBatchDelay(1234L);
assertEquals("batch delay", 1234L, lastWriter.getBatchDelay());
localLogger.info("smoketest: finished");
}
示例11: testMultipleThreadsSingleAppender
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testMultipleThreadsSingleAppender() throws Exception
{
final String logGroupName = "AppenderIntegrationTest-testMultipleThreadsSingleAppender";
final int messagesPerThread = 200;
final int rotationCount = 333;
setUp("CloudWatchAppenderIntegrationTest-testMultipleThreadsSingleAppender.properties", logGroupName);
localLogger.info("multi-thread/single-appender: starting");
Logger testLogger = Logger.getLogger("TestLogger");
CloudWatchAppender appender = (CloudWatchAppender)testLogger.getAppender("test");
MessageWriter[] writers = new MessageWriter[]
{
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread)
};
MessageWriter.runOnThreads(writers);
localLogger.info("multi-thread/single-appender: all threads started; sleeping to give writer chance to run");
Thread.sleep(3000);
assertMessages(logGroupName, LOGSTREAM_BASE + "1", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "2", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "3", rotationCount);
assertMessages(logGroupName, LOGSTREAM_BASE + "4", (messagesPerThread * writers.length) % rotationCount);
assertEquals("client factory", "com.amazonaws.services.logs.AWSLogsClientBuilder.defaultClient", getWriter(appender).getClientFactoryUsed());
localLogger.info("multi-thread/single-appender: finished");
}
示例12: testMultipleThreadsMultipleAppenders
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testMultipleThreadsMultipleAppenders() throws Exception
{
final String logGroupName = "AppenderIntegrationTest-testMultipleThreadsMultipleAppenders";
final int messagesPerThread = 300;
setUp("CloudWatchAppenderIntegrationTest-testMultipleThreadsMultipleAppenders.properties", logGroupName);
localLogger.info("multi-thread/multi-appender: starting");
Logger testLogger = Logger.getLogger("TestLogger1");
CloudWatchAppender appender = (CloudWatchAppender)testLogger.getAppender("test1");
MessageWriter.runOnThreads(
new MessageWriter(Logger.getLogger("TestLogger1"), messagesPerThread),
new MessageWriter(Logger.getLogger("TestLogger2"), messagesPerThread),
new MessageWriter(Logger.getLogger("TestLogger3"), messagesPerThread));
localLogger.info("multi-thread/multi-appender: all threads started; sleeping to give writer chance to run");
Thread.sleep(3000);
assertMessages(logGroupName, LOGSTREAM_BASE + "1", messagesPerThread);
assertMessages(logGroupName, LOGSTREAM_BASE + "2", messagesPerThread);
assertMessages(logGroupName, LOGSTREAM_BASE + "3", messagesPerThread);
assertEquals("client factory", "com.amazonaws.services.logs.AWSLogsClientBuilder.defaultClient", getWriter(appender).getClientFactoryUsed());
localLogger.info("multi-thread/multi-appender: finished");
}
示例13: testMultipleThreadsSingleAppender
import org.apache.log4j.Logger; //导入方法依赖的package包/类
@Test
public void testMultipleThreadsSingleAppender() throws Exception
{
final String streamName = "AppenderIntegrationTest-testMultipleThreadsSingleAppender";
int messagesPerThread = 500;
setUp("KinesisAppenderIntegrationTest-testMultipleThreadsSingleAppender.properties", streamName);
localLogger.info("multi-thread/single-appender: starting");
Logger testLogger = Logger.getLogger("TestLogger");
KinesisAppender appender = (KinesisAppender)testLogger.getAppender("test");
MessageWriter[] writers = new MessageWriter[]
{
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread),
new MessageWriter(testLogger, messagesPerThread)
};
MessageWriter.runOnThreads(writers);
int expectedMessages = writers.length * messagesPerThread;
localLogger.info("multi-thread/single-appender: reading messages");
List<RetrievedRecord> messages = retrieveAllMessages(streamName, expectedMessages);
assertMessages(messages, writers.length, messagesPerThread * writers.length, "test");
Map<String,List<RetrievedRecord>> groupedByShard = groupByShard(messages);
assertEquals("all messages written to same shard", 1, groupedByShard.size());
assertShardCount(streamName, 2);
assertRetentionPeriod(streamName, 24);
assertEquals("client factory called", "com.amazonaws.services.kinesis.AmazonKinesisClientBuilder.defaultClient", getWriter(appender).getClientFactoryUsed());
localLogger.info("multi-thread/single-appender: finished");
}
示例14: changeFileAppenderIfNew
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private static void changeFileAppenderIfNew(Logger logger,
String fileAppenderName, RollingFileAppender newFileAppender) {
Appender existingFileAppender = logger.getAppender(fileAppenderName);
if (existingFileAppender == null) {
logger.removeAppender(consoleAppender);
logger.addAppender(newFileAppender);
} else if (existingFileAppender != newFileAppender) {
logger.removeAppender(existingFileAppender);
logger.addAppender(newFileAppender);
}
return;
}
示例15: getRequestLog
import org.apache.log4j.Logger; //导入方法依赖的package包/类
public static RequestLog getRequestLog(String name) {
String lookup = serverToComponent.get(name);
if (lookup != null) {
name = lookup;
}
String loggerName = "http.requests." + name;
String appenderName = name + "requestlog";
Log logger = LogFactory.getLog(loggerName);
boolean isLog4JLogger;;
try {
isLog4JLogger = logger instanceof Log4JLogger;
} catch (NoClassDefFoundError err) {
// In some dependent projects, log4j may not even be on the classpath at
// runtime, in which case the above instanceof check will throw
// NoClassDefFoundError.
LOG.debug("Could not load Log4JLogger class", err);
isLog4JLogger = false;
}
if (isLog4JLogger) {
Log4JLogger httpLog4JLog = (Log4JLogger)logger;
Logger httpLogger = httpLog4JLog.getLogger();
Appender appender = null;
try {
appender = httpLogger.getAppender(appenderName);
} catch (LogConfigurationException e) {
LOG.warn("Http request log for " + loggerName
+ " could not be created");
throw e;
}
if (appender == null) {
LOG.info("Http request log for " + loggerName
+ " is not defined");
return null;
}
if (appender instanceof HttpRequestLogAppender) {
HttpRequestLogAppender requestLogAppender
= (HttpRequestLogAppender)appender;
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename(requestLogAppender.getFilename());
requestLog.setRetainDays(requestLogAppender.getRetainDays());
return requestLog;
}
else {
LOG.warn("Jetty request log for " + loggerName
+ " was of the wrong class");
return null;
}
}
else {
LOG.warn("Jetty request log can only be enabled using Log4j");
return null;
}
}