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");
}
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");
}
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());
}
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());
}
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);
}
Aggregations