Search in sources :

Example 11 with Layout

use of org.apache.log4j.Layout in project hadoop by apache.

the class TestYARNRunner method testWarnCommandOpts.

@Test(timeout = 20000)
public void testWarnCommandOpts() throws Exception {
    Logger logger = Logger.getLogger(YARNRunner.class);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, bout);
    logger.addAppender(appender);
    JobConf jobConf = new JobConf();
    jobConf.set(MRJobConfig.MR_AM_ADMIN_COMMAND_OPTS, "-Djava.net.preferIPv4Stack=true -Djava.library.path=foo");
    jobConf.set(MRJobConfig.MR_AM_COMMAND_OPTS, "-Xmx1024m -Djava.library.path=bar");
    YARNRunner yarnRunner = new YARNRunner(jobConf);
    @SuppressWarnings("unused") ApplicationSubmissionContext submissionContext = buildSubmitContext(yarnRunner, jobConf);
    String logMsg = bout.toString();
    assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.admin-command-opts can cause programs to no " + "longer function if hadoop native libraries are used. These values " + "should be set as part of the LD_LIBRARY_PATH in the app master JVM " + "env using yarn.app.mapreduce.am.admin.user.env config settings."));
    assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.command-opts can cause programs to no longer " + "function if hadoop native libraries are used. These values should " + "be set as part of the LD_LIBRARY_PATH in the app master JVM env " + "using yarn.app.mapreduce.am.env config settings."));
}
Also used : WriterAppender(org.apache.log4j.WriterAppender) Appender(org.apache.log4j.Appender) SimpleLayout(org.apache.log4j.SimpleLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 12 with Layout

use of org.apache.log4j.Layout in project zm-mailbox by Zimbra.

the class ZimbraPatternLayout method main.

public static void main(String[] args) {
    Layout layout = new ZimbraPatternLayout("[%z] - %m%n");
    Category cat = Category.getInstance("some.cat");
    cat.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
    ZimbraLog.addAccountNameToContext("my@account.com");
    ZimbraLog.addMboxToContext(99);
    cat.debug("Hello, log");
    cat.info("Hello again...");
    ZimbraLog.clearContext();
    cat.info("No more context");
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Category(org.apache.log4j.Category) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout)

Example 13 with Layout

use of org.apache.log4j.Layout in project zookeeper by apache.

the class QuorumPeerMainTest method testInconsistentPeerType.

/**
 * Verify handling of inconsistent peer type
 */
@Test
public void testInconsistentPeerType() throws Exception {
    ClientBase.setupTestEnv();
    // setup the logger to capture all logs
    Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);
    // servers list, but there's no "peerType=observer" token in config
    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();
        final int CLIENT_PORT_QP3 = PortAssignment.unique();
        String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2 + "\nserver.3=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":observer" + ";" + CLIENT_PORT_QP3;
        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
        MainThread q3 = new MainThread(3, CLIENT_PORT_QP3, quorumCfgSection);
        q1.start();
        q2.start();
        q3.start();
        Assert.assertTrue("waiting for server 1 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 3 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP3, CONNECTION_TIMEOUT));
        q1.shutdown();
        q2.shutdown();
        q3.shutdown();
        Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, ClientBase.CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 3 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP3, ClientBase.CONNECTION_TIMEOUT));
    } finally {
        qlogger.removeAppender(appender);
    }
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean warningPresent = false;
    boolean defaultedToObserver = false;
    Pattern pWarn = Pattern.compile(".*Peer type from servers list.* doesn't match peerType.*");
    Pattern pObserve = Pattern.compile(".*OBSERVING.*");
    while ((line = r.readLine()) != null) {
        if (pWarn.matcher(line).matches()) {
            warningPresent = true;
        }
        if (pObserve.matcher(line).matches()) {
            defaultedToObserver = true;
        }
        if (warningPresent && defaultedToObserver) {
            break;
        }
    }
    Assert.assertTrue("Should warn about inconsistent peer type", warningPresent && defaultedToObserver);
}
Also used : Pattern(java.util.regex.Pattern) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) LineNumberReader(java.io.LineNumberReader) Test(org.junit.Test)

Example 14 with Layout

use of org.apache.log4j.Layout in project zookeeper by apache.

the class QuorumPeerMainTest method testQuorumDefaults.

/**
 * Verify handling of quorum defaults
 * * default electionAlg is fast leader election
 */
@Test
public void testQuorumDefaults() throws Exception {
    ClientBase.setupTestEnv();
    // setup the logger to capture all logs
    Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);
    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();
        String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;
        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
        q1.start();
        q2.start();
        Assert.assertTrue("waiting for server 1 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, CONNECTION_TIMEOUT));
        q1.shutdown();
        q2.shutdown();
        Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT));
        Assert.assertTrue("waiting for server 2 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, ClientBase.CONNECTION_TIMEOUT));
    } finally {
        zlogger.removeAppender(appender);
    }
    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p = Pattern.compile(".*FastLeaderElection.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("fastleaderelection used", found);
}
Also used : Pattern(java.util.regex.Pattern) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) LineNumberReader(java.io.LineNumberReader) Test(org.junit.Test)

Example 15 with Layout

use of org.apache.log4j.Layout in project ignite by apache.

the class GridNodeMetricsLogSelfTest method testNodeMetricsLog.

/**
 * @throws Exception If failed.
 */
public void testNodeMetricsLog() throws Exception {
    // Log to string, to check log content
    Layout layout = new SimpleLayout();
    StringWriter strWr = new StringWriter();
    WriterAppender app = new WriterAppender(layout, strWr);
    Logger.getRootLogger().addAppender(app);
    Ignite g1 = startGrid(1);
    IgniteCache<Integer, String> cache1 = g1.createCache("TestCache1");
    cache1.put(1, "one");
    Ignite g2 = startGrid(2);
    IgniteCache<Integer, String> cache2 = g2.createCache("TestCache2");
    cache2.put(2, "two");
    Thread.sleep(10_000);
    // Check that nodes are alie
    assertEquals("one", cache1.get(1));
    assertEquals("two", cache2.get(2));
    String fullLog = strWr.toString();
    Logger.getRootLogger().removeAppender(app);
    String msg = "Metrics are missing in the log or have an unexpected format";
    // don't check the format strictly, but check that all expected metrics are present
    assertTrue(msg, fullLog.contains("Metrics for local node (to disable set 'metricsLogFrequency' to 0)"));
    assertTrue(msg, fullLog.matches("(?s).*Node \\[id=.*, name=.*, uptime=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*H/N/C \\[hosts=.*, nodes=.*, CPUs=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*CPU \\[cur=.*, avg=.*, GC=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*PageMemory \\[pages=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*Heap \\[used=.*, free=.*, comm=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*Non heap \\[used=.*, free=.*, comm=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*Outbound messages queue \\[size=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*Public thread pool \\[active=.*, idle=.*, qSize=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*System thread pool \\[active=.*, idle=.*, qSize=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*" + CUSTOM_EXECUTOR_0 + " \\[active=.*, idle=.*, qSize=.*].*"));
    assertTrue(msg, fullLog.matches("(?s).*" + CUSTOM_EXECUTOR_1 + " \\[active=.*, idle=.*, qSize=.*].*"));
}
Also used : SimpleLayout(org.apache.log4j.SimpleLayout) StringWriter(java.io.StringWriter) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) Ignite(org.apache.ignite.Ignite) WriterAppender(org.apache.log4j.WriterAppender)

Aggregations

Layout (org.apache.log4j.Layout)19 PatternLayout (org.apache.log4j.PatternLayout)12 WriterAppender (org.apache.log4j.WriterAppender)9 Test (org.junit.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Appender (org.apache.log4j.Appender)6 Logger (org.apache.log4j.Logger)6 LineNumberReader (java.io.LineNumberReader)5 StringReader (java.io.StringReader)5 Pattern (java.util.regex.Pattern)4 LoggingEvent (org.apache.log4j.spi.LoggingEvent)4 File (java.io.File)3 FileAppender (org.apache.log4j.FileAppender)3 SimpleLayout (org.apache.log4j.SimpleLayout)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Category (org.apache.log4j.Category)2 NullAppender (org.apache.log4j.varia.NullAppender)2 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1