Search in sources :

Example 1 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project dubbo by alibaba.

the class Slf4jLoggerTest method testLocationAwareLogger.

@Test
public void testLocationAwareLogger() {
    LocationAwareLogger locationAwareLogger = mock(LocationAwareLogger.class);
    Slf4jLogger logger = new Slf4jLogger(locationAwareLogger);
    logger.error("error");
    logger.warn("warn");
    logger.info("info");
    logger.debug("debug");
    logger.trace("info");
    verify(locationAwareLogger, times(5)).log(isNull(Marker.class), anyString(), anyInt(), anyString(), isNull(Object[].class), isNull(Throwable.class));
    logger.error(new Exception("error"));
    logger.warn(new Exception("warn"));
    logger.info(new Exception("info"));
    logger.debug(new Exception("debug"));
    logger.trace(new Exception("trace"));
    logger.error("error", new Exception("error"));
    logger.warn("warn", new Exception("warn"));
    logger.info("info", new Exception("info"));
    logger.debug("debug", new Exception("debug"));
    logger.trace("trace", new Exception("trace"));
    verify(locationAwareLogger, times(10)).log(isNull(Marker.class), anyString(), anyInt(), anyString(), isNull(Object[].class), any(Throwable.class));
}
Also used : LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) Marker(org.slf4j.Marker) Test(org.junit.jupiter.api.Test)

Example 2 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project new-cloud by xie-summer.

the class SimpleLogger method entry.

/**
 * Log method entry.
 *
 * @param argArray supplied parameters
 */
public void entry(Object... argArray) {
    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
        String messagePattern = null;
        if (argArray.length < ENTRY_MESSAGE_ARRAY_LEN) {
            messagePattern = ENTRY_MESSAGE_ARRAY[argArray.length];
        } else {
            messagePattern = buildMessagePattern(argArray.length);
        }
        FormattingTuple tp = MessageFormatter.arrayFormat(messagePattern, argArray);
        ((LocationAwareLogger) logger).log(ENTRY_MARKER, FQCN, LocationAwareLogger.TRACE_INT, tp.getMessage(), argArray, tp.getThrowable());
    }
}
Also used : LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 3 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project new-cloud by xie-summer.

the class JsonLogger method entry.

/**
 * Log method entry.
 *
 * @param argArray
 *           supplied parameters
 */
public void entry(Object... argArray) {
    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
        String messagePattern = null;
        if (argArray.length < ENTRY_MESSAGE_ARRAY_LEN) {
            messagePattern = ENTRY_MESSAGE_ARRAY[argArray.length];
        } else {
            messagePattern = buildMessagePattern(argArray.length);
        }
        FormattingTuple tp = MessageFormatter.arrayFormat(messagePattern, argArray);
        ((LocationAwareLogger) logger).log(ENTRY_MARKER, FQCN, LocationAwareLogger.TRACE_INT, tp.getMessage(), argArray, tp.getThrowable());
    }
}
Also used : LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 4 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project netty by netty.

the class Slf4JLoggerFactoryTest method testFormatMessage.

@Test
public void testFormatMessage() {
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    LocationAwareLogger logger = mock(LocationAwareLogger.class);
    when(logger.isDebugEnabled()).thenReturn(true);
    when(logger.isErrorEnabled()).thenReturn(true);
    when(logger.isInfoEnabled()).thenReturn(true);
    when(logger.isTraceEnabled()).thenReturn(true);
    when(logger.isWarnEnabled()).thenReturn(true);
    when(logger.getName()).thenReturn("testlogger");
    InternalLogger internalLogger = Slf4JLoggerFactory.wrapLogger(logger);
    internalLogger.debug("{}", "debug");
    internalLogger.debug("{} {}", "debug1", "debug2");
    internalLogger.debug("{} {} {}", "debug1", "debug2", "debug3");
    internalLogger.error("{}", "error");
    internalLogger.error("{} {}", "error1", "error2");
    internalLogger.error("{} {} {}", "error1", "error2", "error3");
    internalLogger.info("{}", "info");
    internalLogger.info("{} {}", "info1", "info2");
    internalLogger.info("{} {} {}", "info1", "info2", "info3");
    internalLogger.trace("{}", "trace");
    internalLogger.trace("{} {}", "trace1", "trace2");
    internalLogger.trace("{} {} {}", "trace1", "trace2", "trace3");
    internalLogger.warn("{}", "warn");
    internalLogger.warn("{} {}", "warn1", "warn2");
    internalLogger.warn("{} {} {}", "warn1", "warn2", "warn3");
    verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN), eq(LocationAwareLogger.DEBUG_INT), captor.capture(), any(Object[].class), ArgumentMatchers.<Throwable>isNull());
    verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN), eq(LocationAwareLogger.ERROR_INT), captor.capture(), any(Object[].class), ArgumentMatchers.<Throwable>isNull());
    verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN), eq(LocationAwareLogger.INFO_INT), captor.capture(), any(Object[].class), ArgumentMatchers.<Throwable>isNull());
    verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN), eq(LocationAwareLogger.TRACE_INT), captor.capture(), any(Object[].class), ArgumentMatchers.<Throwable>isNull());
    verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN), eq(LocationAwareLogger.WARN_INT), captor.capture(), any(Object[].class), ArgumentMatchers.<Throwable>isNull());
    Iterator<String> logMessages = captor.getAllValues().iterator();
    assertEquals("debug", logMessages.next());
    assertEquals("debug1 debug2", logMessages.next());
    assertEquals("debug1 debug2 debug3", logMessages.next());
    assertEquals("error", logMessages.next());
    assertEquals("error1 error2", logMessages.next());
    assertEquals("error1 error2 error3", logMessages.next());
    assertEquals("info", logMessages.next());
    assertEquals("info1 info2", logMessages.next());
    assertEquals("info1 info2 info3", logMessages.next());
    assertEquals("trace", logMessages.next());
    assertEquals("trace1 trace2", logMessages.next());
    assertEquals("trace1 trace2 trace3", logMessages.next());
    assertEquals("warn", logMessages.next());
    assertEquals("warn1 warn2", logMessages.next());
    assertEquals("warn1 warn2 warn3", logMessages.next());
    assertFalse(logMessages.hasNext());
}
Also used : LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) Test(org.junit.jupiter.api.Test)

Example 5 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project new-cloud by xie-summer.

the class JsonLogger method exit.

/**
 * Log method exit
 *
 * @param result
 *           The result of the method being exited
 */
public void exit(Object result) {
    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
        FormattingTuple tp = MessageFormatter.format(EXIT_MESSAGE_1, result);
        ((LocationAwareLogger) logger).log(EXIT_MARKER, FQCN, LocationAwareLogger.TRACE_INT, tp.getMessage(), new Object[] { result }, tp.getThrowable());
    }
}
Also used : LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) FormattingTuple(org.slf4j.helpers.FormattingTuple)

Aggregations

LocationAwareLogger (org.slf4j.spi.LocationAwareLogger)7 FormattingTuple (org.slf4j.helpers.FormattingTuple)5 Test (org.junit.jupiter.api.Test)2 Marker (org.slf4j.Marker)1