Search in sources :

Example 16 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project cloudstack by apache.

the class SnmpEnhancedPatternLayoutTest method ParseAlertWithPairDelimeterInMessageTest.

@Test
public void ParseAlertWithPairDelimeterInMessageTest() {
    LoggingEvent event = mock(LoggingEvent.class);
    setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" + " //network CIDR is not configured originally. Set it default to 10.102.192.0/22", event);
    SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event);
    commonAssertions(info, "Management //network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22");
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Test(org.junit.Test)

Example 17 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project cloudstack by apache.

the class SnmpEnhancedPatternLayoutTest method ParseAlertWithKeyValueDelimeterInMessageTest.

@Test
public void ParseAlertWithKeyValueDelimeterInMessageTest() {
    LoggingEvent event = mock(LoggingEvent.class);
    setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" + " ::network CIDR is not configured originally. Set it default to 10.102.192.0/22", event);
    SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event);
    commonAssertions(info, "Management ::network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22");
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Test(org.junit.Test)

Example 18 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project samza by apache.

the class TestJmxAppender method testJmxAppender.

@Test
public void testJmxAppender() throws Exception {
    MBeanServerConnection mbserver = JMXConnectorFactory.connect(URL).getMBeanServerConnection();
    ObjectName objectName = new ObjectName(JmxAppender.JMX_OBJECT_DOMAIN + ":type=" + JmxAppender.JMX_OBJECT_TYPE + ",name=" + JmxAppender.JMX_OBJECT_NAME);
    String level = null;
    MockAppender mockAppender = new MockAppender();
    Logger.getRootLogger().addAppender(mockAppender);
    // Check INFO is set (from log4j.xml).
    level = (String) mbserver.getAttribute(objectName, "Level");
    assertEquals("INFO", level);
    log.info("info1");
    log.debug("debug1");
    // Set to debug.
    mbserver.setAttribute(objectName, new Attribute("Level", "debug"));
    // Check DEBUG is set.
    level = (String) mbserver.getAttribute(objectName, "Level");
    assertEquals("DEBUG", level);
    log.info("info2");
    log.debug("debug2");
    List<LoggingEvent> logLines = mockAppender.getLogLines();
    // Should not have debug1 because log level is info at first.
    Iterator<LoggingEvent> logLineIterator = logLines.iterator();
    assertEquals(3, logLines.size());
    assertEquals("info1", logLineIterator.next().getMessage());
    assertEquals("info2", logLineIterator.next().getMessage());
    assertEquals("debug2", logLineIterator.next().getMessage());
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Attribute(javax.management.Attribute) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 19 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project samza by apache.

the class TestLoggingEventStringSerde method test.

@Test
public void test() {
    String testLog = "testing";
    Logger logger = Logger.getLogger(TestLoggingEventStringSerde.class);
    LoggingEvent log = new LoggingEvent(logger.getName(), logger, logger.getLevel(), testLog, null);
    LoggingEventStringSerde loggingEventStringSerde = new LoggingEventStringSerde();
    assertNull(loggingEventStringSerde.fromBytes(null));
    assertNull(loggingEventStringSerde.toBytes(null));
    assertArrayEquals(testLog.getBytes(), loggingEventStringSerde.toBytes(log));
    // only the log messages are guaranteed to be equivalent 
    assertEquals(log.getMessage().toString(), loggingEventStringSerde.fromBytes(testLog.getBytes()).getMessage().toString());
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 20 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.

the class SshLog method onExecute.

void onExecute(DispatchCommand dcmd, int exitValue, SshSession sshSession) {
    final Context ctx = context.get();
    ctx.finished = TimeUtil.nowMs();
    String cmd = extractWhat(dcmd);
    final LoggingEvent event = log(cmd);
    event.setProperty(P_WAIT, (ctx.started - ctx.created) + "ms");
    event.setProperty(P_EXEC, (ctx.finished - ctx.started) + "ms");
    final String status;
    switch(exitValue) {
        case BaseCommand.STATUS_CANCEL:
            status = "killed";
            break;
        case BaseCommand.STATUS_NOT_FOUND:
            status = "not-found";
            break;
        case BaseCommand.STATUS_NOT_ADMIN:
            status = "not-admin";
            break;
        default:
            status = String.valueOf(exitValue);
            break;
    }
    event.setProperty(P_STATUS, status);
    String peerAgent = sshSession.getPeerAgent();
    if (peerAgent != null) {
        event.setProperty(P_AGENT, peerAgent);
    }
    if (async != null) {
        async.append(event);
    }
    audit(context.get(), status, dcmd);
}
Also used : Context(com.google.gerrit.sshd.SshScope.Context) LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Aggregations

LoggingEvent (org.apache.log4j.spi.LoggingEvent)48 Test (org.junit.Test)21 Logger (org.apache.log4j.Logger)12 Pattern (java.util.regex.Pattern)7 Matcher (java.util.regex.Matcher)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)3 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)2 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)2 IOException (java.io.IOException)2 Appender (org.apache.log4j.Appender)2 Category (org.apache.log4j.Category)2 Level (org.apache.log4j.Level)2 Filter (org.apache.log4j.spi.Filter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 SystemLogLevel (com.axway.ats.log.model.SystemLogLevel)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1