use of org.apache.log4j.PatternLayout in project OpenOLAT by OpenOLAT.
the class Log4JInitServlet method init.
@Override
public void init() {
String file = getInitParameter("log4j-init-file");
ClassPathResource res = new ClassPathResource(file);
if (!res.exists()) {
// creating basic log4j configuration which writes to console out, Only called when not yet configured
ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"), ConsoleAppender.SYSTEM_OUT);
appender.setThreshold(Level.INFO);
BasicConfigurator.configure(appender);
OLog log = Tracing.createLoggerFor(getClass());
log.info("*****************************************************************************************");
log.info("You don't provide a log4j config file for your OLAT instance. OLAT will just log to standard out (e.g. catalina.out)." + " Please provide a proper log config file (log4j.xml, see olat/conf for an example or read the installation guide) " + "and place it into the root of the classpath e.g. tomcat/lib or WEB-INF/classes");
log.info("*****************************************************************************************");
}
}
use of org.apache.log4j.PatternLayout in project atlas by apache.
the class FailedMessagesLogger method init.
void init() {
String rootLoggerDirectory = getRootLoggerDirectory();
if (rootLoggerDirectory == null) {
return;
}
String absolutePath = new File(rootLoggerDirectory, failedMessageFile).getAbsolutePath();
try {
DailyRollingFileAppender failedLogFilesAppender = new DailyRollingFileAppender(new PatternLayout(PATTERN_SPEC_TIMESTAMP_MESSAGE_NEWLINE), absolutePath, DATE_PATTERN);
logger.addAppender(failedLogFilesAppender);
logger.setLevel(Level.ERROR);
logger.setAdditivity(false);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.log4j.PatternLayout in project pmd-eclipse-plugin by pmd.
the class PMDPlugin method configureLogs.
/**
* Configure the logging
*/
private void configureLogs(IPreferences preferences) {
try {
Layout layout = new PatternLayout("%d{yyyy/MM/dd HH:mm:ss,SSS} %-5p %-32c{1} %m%n");
RollingFileAppender appender = new RollingFileAppender(layout, preferences.getLogFileName());
appender.setName(PMD_ECLIPSE_APPENDER_NAME);
appender.setMaxBackupIndex(1);
appender.setMaxFileSize("10MB");
Logger.getRootLogger().addAppender(new ConsoleAppender(layout));
Logger.getRootLogger().setLevel(Level.WARN);
Logger.getRootLogger().setAdditivity(false);
Logger.getLogger(ROOT_LOG_ID).addAppender(appender);
Logger.getLogger(ROOT_LOG_ID).setLevel(preferences.getLogLevel());
Logger.getLogger(ROOT_LOG_ID).setAdditivity(false);
} catch (IOException e) {
logError("IO Exception when configuring logging.", e);
}
}
use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testQueueTimeout.
@Test
public void testQueueTimeout() throws InterruptedException {
System.setProperty("samza.container.name", "samza-container-1");
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
systemProducerAppender.queueTimeoutS = 1;
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
LOG.addAppender(systemProducerAppender);
int extraMessageCount = 5;
// -1 because when the queue is drained there is one additional message that couldn't be added
int expectedMessagesSent = extraMessageCount - 1;
List<String> messages = new ArrayList<>(StreamAppender.DEFAULT_QUEUE_SIZE + extraMessageCount);
for (int i = 0; i < StreamAppender.DEFAULT_QUEUE_SIZE + extraMessageCount; i++) {
messages.add(String.valueOf(i));
}
// Set up latch
// We expect to drop all but the extra messages
final CountDownLatch allMessagesSent = new CountDownLatch(expectedMessagesSent);
final CountDownLatch waitForTimeout = new CountDownLatch(1);
MockSystemProducer.listeners.add((source, envelope) -> {
allMessagesSent.countDown();
try {
waitForTimeout.await();
} catch (InterruptedException e) {
fail("Test could not run properly because of a thread interrupt.");
}
});
// Log the messages. This is where the timeout will happen!
messages.forEach(LOG::info);
assertEquals(messages.size() - expectedMessagesSent, systemProducerAppender.metrics.logMessagesDropped.getCount());
// Allow all the rest of the messages to send.
waitForTimeout.countDown();
// Wait for messages
assertTrue("Thread did not send all messages. Count: " + allMessagesSent.getCount(), allMessagesSent.await(60, TimeUnit.SECONDS));
assertEquals(expectedMessagesSent, MockSystemProducer.messagesReceived.size());
}
use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testSystemProducerAppenderNotInitialized.
@Test
public void testSystemProducerAppenderNotInitialized() throws InterruptedException {
System.setProperty("samza.container.name", "samza-job-coordinator");
// add a counter to make sure that the initial message doesn't get produced
AtomicInteger numMessagesProduced = new AtomicInteger(0);
MockSystemProducer.listeners.add((source, envelope) -> numMessagesProduced.incrementAndGet());
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender(baseConfig(), false);
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
LOG.addAppender(systemProducerAppender);
// System isn't initialized yet, so this message should be dropped
LOG.info("no-received");
// explicitly trigger initialization to test that new messages do get sent to the stream
systemProducerAppender.setupSystem();
systemProducerAppender.systemInitialized = true;
List<String> messages = Lists.newArrayList("testing3", "testing4");
logAndVerifyMessages(messages);
assertEquals(messages.size(), numMessagesProduced.get());
}
Aggregations