Search in sources :

Example 1 with LogEvent

use of com.newrelic.agent.model.LogEvent in project newrelic-java-agent by newrelic.

the class LoggingEvent_InstrumentationTest method testLogEventsOffLevel.

@Test
public void testLogEventsOffLevel() {
    final Logger logger = (Logger) LoggerFactory.getLogger(LoggingEvent_InstrumentationTest.class);
    // Logging is OFF at all levels
    logger.setLevel(Level.OFF);
    int expectedTotalEventsCapturedAtError = 0;
    logger.error(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtWarn = 0;
    logger.warn(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtInfo = 0;
    logger.info(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtDebug = 0;
    logger.debug(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtTrace = 0;
    logger.trace(NOT_CAPTURED);
    int expectedTotalEventsCaptured = 0;
    Collection<LogEvent> logEvents = introspector.getLogEvents();
    assertEquals(expectedTotalEventsCaptured, logEvents.size());
    List<LogEvent> errorLevelLogEvents = getErrorLevelLogEvents(logEvents);
    List<LogEvent> warnLevelLogEvents = getWarnLevelLogEvents(logEvents);
    List<LogEvent> infoLevelLogEvents = getInfoLevelLogEvents(logEvents);
    List<LogEvent> debugLevelLogEvents = getDebugLevelLogEvents(logEvents);
    List<LogEvent> traceLevelLogEvents = getTraceLevelLogEvents(logEvents);
    assertEquals(expectedTotalEventsCapturedAtError, errorLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtWarn, warnLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtInfo, infoLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtDebug, debugLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtTrace, traceLevelLogEvents.size());
}
Also used : LogEvent(com.newrelic.agent.model.LogEvent) Logger(ch.qos.logback.classic.Logger) Test(org.junit.Test)

Example 2 with LogEvent

use of com.newrelic.agent.model.LogEvent in project newrelic-java-agent by newrelic.

the class LoggingEvent_InstrumentationTest method testLogEventsAllLevel.

@Test
public void testLogEventsAllLevel() {
    final Logger logger = (Logger) LoggerFactory.getLogger(LoggingEvent_InstrumentationTest.class);
    // Log at ALL level
    logger.setLevel(Level.ALL);
    int expectedTotalEventsCapturedAtError = 1;
    logger.error(CAPTURED);
    int expectedTotalEventsCapturedAtWarn = 2;
    logger.warn(CAPTURED);
    logger.warn(CAPTURED);
    int expectedTotalEventsCapturedAtInfo = 3;
    logger.info(CAPTURED);
    logger.info(CAPTURED);
    logger.info(CAPTURED);
    int expectedTotalEventsCapturedAtDebug = 4;
    logger.debug(CAPTURED);
    logger.debug(CAPTURED);
    logger.debug(CAPTURED);
    logger.debug(CAPTURED);
    int expectedTotalEventsCapturedAtTrace = 5;
    logger.trace(CAPTURED);
    logger.trace(CAPTURED);
    logger.trace(CAPTURED);
    logger.trace(CAPTURED);
    logger.trace(CAPTURED);
    int expectedTotalEventsCaptured = expectedTotalEventsCapturedAtError + expectedTotalEventsCapturedAtWarn + expectedTotalEventsCapturedAtInfo + expectedTotalEventsCapturedAtDebug + expectedTotalEventsCapturedAtTrace;
    Collection<LogEvent> logEvents = introspector.getLogEvents();
    assertEquals(expectedTotalEventsCaptured, logEvents.size());
    List<LogEvent> errorLevelLogEvents = getErrorLevelLogEvents(logEvents);
    List<LogEvent> warnLevelLogEvents = getWarnLevelLogEvents(logEvents);
    List<LogEvent> infoLevelLogEvents = getInfoLevelLogEvents(logEvents);
    List<LogEvent> debugLevelLogEvents = getDebugLevelLogEvents(logEvents);
    List<LogEvent> traceLevelLogEvents = getTraceLevelLogEvents(logEvents);
    assertEquals(expectedTotalEventsCapturedAtError, errorLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtWarn, warnLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtInfo, infoLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtDebug, debugLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtTrace, traceLevelLogEvents.size());
}
Also used : LogEvent(com.newrelic.agent.model.LogEvent) Logger(ch.qos.logback.classic.Logger) Test(org.junit.Test)

Example 3 with LogEvent

use of com.newrelic.agent.model.LogEvent in project newrelic-java-agent by newrelic.

the class LoggingEvent_InstrumentationTest method testLogEventsWarnLevel.

@Test
public void testLogEventsWarnLevel() {
    final Logger logger = (Logger) LoggerFactory.getLogger(LoggingEvent_InstrumentationTest.class);
    // Log at WARN level
    logger.setLevel(Level.WARN);
    int expectedTotalEventsCapturedAtError = 1;
    logger.error(CAPTURED);
    int expectedTotalEventsCapturedAtWarn = 1;
    logger.warn(CAPTURED);
    int expectedTotalEventsCapturedAtInfo = 0;
    logger.info(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtDebug = 0;
    logger.debug(NOT_CAPTURED);
    int expectedTotalEventsCapturedAtTrace = 0;
    logger.trace(NOT_CAPTURED);
    int expectedTotalEventsCaptured = expectedTotalEventsCapturedAtError + expectedTotalEventsCapturedAtWarn + expectedTotalEventsCapturedAtInfo + expectedTotalEventsCapturedAtDebug + expectedTotalEventsCapturedAtTrace;
    Collection<LogEvent> logEvents = introspector.getLogEvents();
    assertEquals(expectedTotalEventsCaptured, logEvents.size());
    List<LogEvent> errorLevelLogEvents = getErrorLevelLogEvents(logEvents);
    List<LogEvent> warnLevelLogEvents = getWarnLevelLogEvents(logEvents);
    List<LogEvent> infoLevelLogEvents = getInfoLevelLogEvents(logEvents);
    List<LogEvent> debugLevelLogEvents = getDebugLevelLogEvents(logEvents);
    List<LogEvent> traceLevelLogEvents = getTraceLevelLogEvents(logEvents);
    assertEquals(expectedTotalEventsCapturedAtError, errorLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtWarn, warnLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtInfo, infoLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtDebug, debugLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtTrace, traceLevelLogEvents.size());
}
Also used : LogEvent(com.newrelic.agent.model.LogEvent) Logger(ch.qos.logback.classic.Logger) Test(org.junit.Test)

Example 4 with LogEvent

use of com.newrelic.agent.model.LogEvent in project newrelic-java-agent by newrelic.

the class LoggingEvent_InstrumentationTest method testLogEventsTraceLevel.

@Test
public void testLogEventsTraceLevel() {
    final Logger logger = (Logger) LoggerFactory.getLogger(LoggingEvent_InstrumentationTest.class);
    // Log at TRACE level
    logger.setLevel(Level.TRACE);
    int expectedTotalEventsCapturedAtError = 1;
    logger.error(CAPTURED);
    int expectedTotalEventsCapturedAtWarn = 1;
    logger.warn(CAPTURED);
    int expectedTotalEventsCapturedAtInfo = 1;
    logger.info(CAPTURED);
    int expectedTotalEventsCapturedAtDebug = 1;
    logger.debug(CAPTURED);
    int expectedTotalEventsCapturedAtTrace = 1;
    logger.trace(CAPTURED);
    int expectedTotalEventsCaptured = expectedTotalEventsCapturedAtError + expectedTotalEventsCapturedAtWarn + expectedTotalEventsCapturedAtInfo + expectedTotalEventsCapturedAtDebug + expectedTotalEventsCapturedAtTrace;
    Collection<LogEvent> logEvents = introspector.getLogEvents();
    assertEquals(expectedTotalEventsCaptured, logEvents.size());
    List<LogEvent> errorLevelLogEvents = getErrorLevelLogEvents(logEvents);
    List<LogEvent> warnLevelLogEvents = getWarnLevelLogEvents(logEvents);
    List<LogEvent> infoLevelLogEvents = getInfoLevelLogEvents(logEvents);
    List<LogEvent> debugLevelLogEvents = getDebugLevelLogEvents(logEvents);
    List<LogEvent> traceLevelLogEvents = getTraceLevelLogEvents(logEvents);
    assertEquals(expectedTotalEventsCapturedAtError, errorLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtWarn, warnLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtInfo, infoLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtDebug, debugLevelLogEvents.size());
    assertEquals(expectedTotalEventsCapturedAtTrace, traceLevelLogEvents.size());
}
Also used : LogEvent(com.newrelic.agent.model.LogEvent) Logger(ch.qos.logback.classic.Logger) Test(org.junit.Test)

Example 5 with LogEvent

use of com.newrelic.agent.model.LogEvent in project newrelic-java-agent by newrelic.

the class RPMServiceTest method doSendLogEvent.

private void doSendLogEvent() throws Exception {
    MockDataSenderFactory dataSenderFactory = new MockDataSenderFactory();
    DataSenderFactory.setDataSenderFactory(dataSenderFactory);
    List<String> appNames = singletonList("Send Log Events Test App");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    svc.launch();
    LogEvent logEvent1 = new LogEvent(null, 1);
    LogEvent logEvent2 = new LogEvent(null, 2);
    List<LogEvent> logEvents = new ArrayList<>();
    logEvents.add(logEvent1);
    logEvents.add(logEvent2);
    svc.sendLogEvents(logEvents);
    List<LogEvent> seen = dataSenderFactory.getLastDataSender().getLogEvents();
    assertEquals("No log events sent currently", logEvents.size(), seen.size());
}
Also used : LogEvent(com.newrelic.agent.model.LogEvent) ArrayList(java.util.ArrayList)

Aggregations

LogEvent (com.newrelic.agent.model.LogEvent)21 Test (org.junit.Test)15 Logger (org.apache.logging.log4j.Logger)8 Logger (ch.qos.logback.classic.Logger)7 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AttributeSender (com.newrelic.agent.attributes.AttributeSender)1 DistributedSamplingPriorityQueue (com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 StatsWork (com.newrelic.agent.stats.StatsWork)1 HttpError (com.newrelic.agent.transport.HttpError)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1