Search in sources :

Example 81 with PatternLayout

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);
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) Test(org.junit.Test)

Example 82 with PatternLayout

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));
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 83 with PatternLayout

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);
    }
}
Also used : PatternLayout(org.apache.log4j.PatternLayout)

Example 84 with PatternLayout

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();
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) RocksInodeStore(alluxio.master.metastore.rocks.RocksInodeStore) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) HeapInodeStore(alluxio.master.metastore.heap.HeapInodeStore)

Example 85 with PatternLayout

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);
        }
    };
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) Description(org.junit.runner.Description) TestWatcher(org.junit.rules.TestWatcher) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileWriter(java.io.FileWriter) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)101 ConsoleAppender (org.apache.log4j.ConsoleAppender)51 Logger (org.apache.log4j.Logger)27 IOException (java.io.IOException)21 Appender (org.apache.log4j.Appender)18 FileAppender (org.apache.log4j.FileAppender)17 Layout (org.apache.log4j.Layout)15 File (java.io.File)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)6 WriterAppender (org.apache.log4j.WriterAppender)6