use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testSystemProducerAppenderInContainer.
@Test
public void testSystemProducerAppenderInContainer() throws InterruptedException {
System.setProperty("samza.container.name", "samza-container-1");
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
LOG.addAppender(systemProducerAppender);
List<String> messages = Lists.newArrayList("testing1", "testing2");
logAndVerifyMessages(messages);
}
use of org.apache.log4j.PatternLayout in project samza by apache.
the class TestStreamAppender method testExceptionsDoNotKillTransferThread.
@Test
public void testExceptionsDoNotKillTransferThread() throws InterruptedException {
System.setProperty("samza.container.name", "samza-container-1");
MockSystemProducerAppender systemProducerAppender = new MockSystemProducerAppender();
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%m");
systemProducerAppender.setLayout(layout);
systemProducerAppender.activateOptions();
LOG.addAppender(systemProducerAppender);
List<String> messages = Lists.newArrayList("testing5", "testing6", "testing7");
// Set up latch
final CountDownLatch allMessagesSent = new CountDownLatch(messages.size());
MockSystemProducer.listeners.add((source, envelope) -> {
allMessagesSent.countDown();
if (allMessagesSent.getCount() == messages.size() - 1) {
// Throw on the first message
throw new RuntimeException();
}
});
// Log the messages
messages.forEach(LOG::info);
// Wait for messages
assertTrue("Thread did not send all messages. Count: " + allMessagesSent.getCount(), allMessagesSent.await(60, TimeUnit.SECONDS));
}
use of org.apache.log4j.PatternLayout in project pinpoint by naver.
the class PatternLayoutInterceptor method updatePattern.
private void updatePattern(Object target, String oldPattern, List<String> searchList, String replace) {
if (!(target instanceof PatternLayout)) {
return;
}
String newPattern = oldPattern;
boolean changed = false;
for (String search : searchList) {
newPattern = oldPattern.replace(search, replace);
if (!oldPattern.contentEquals(newPattern)) {
changed = true;
if (debug) {
logger.debug("Log4j pattern replaced, old pattern({}) and new pattern({}).", oldPattern, newPattern);
}
break;
}
}
if (changed) {
final PatternLayout layout = (PatternLayout) target;
layout.setConversionPattern(newPattern);
}
}
use of org.apache.log4j.PatternLayout in project alluxio by Alluxio.
the class InodeStoreBench method main.
public static void main(String[] args) throws Exception {
// Enable logging to stdout.
Layout layout = new PatternLayout("%d [%t] %-5p %c %x - %m%n");
Logger.getRootLogger().addAppender(new ConsoleAppender(layout));
System.out.printf("Running benchmarks for rocks inode store%n");
sStore = new RocksInodeStore(ServerConfiguration.getString(PropertyKey.MASTER_METASTORE_DIR));
runBenchmarks();
System.out.printf("%nRunning benchmarks for heap inode store%n");
sStore = new HeapInodeStore();
runBenchmarks();
}
use of org.apache.log4j.PatternLayout in project alluxio by Alluxio.
the class BaseIntegrationTest method logHandler.
private TestWatcher logHandler() {
return new TestWatcher() {
private String mLogPath;
private Appender mAppender;
@Override
protected void starting(Description description) {
try {
mLogPath = logPath(description);
// In case the file already exists, truncate it.
new FileWriter(mLogPath).close();
mAppender = new FileAppender(new PatternLayout("%d{ISO8601} [%t] %-5p %c{2} (%F:%M) - %m%n"), mLogPath);
LogManager.getRootLogger().addAppender(mAppender);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected void succeeded(Description description) {
try {
Files.delete(Paths.get(mLogPath));
} catch (Throwable t) {
LOG.error("Failed to delete success log file {}", mLogPath);
}
}
@Override
protected void skipped(AssumptionViolatedException e, Description description) {
succeeded(description);
}
@Override
protected void finished(Description description) {
LogManager.getRootLogger().removeAppender(mAppender);
}
private String logPath(Description description) {
String basename = String.format("tests-%s-%s.log", description.getClassName(), description.getMethodName());
return PathUtils.concatPath(Constants.TEST_LOG_DIR, basename);
}
};
}
Aggregations