Search in sources :

Example 6 with LocationAwareLogger

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

the class SimpleLogger 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)

Example 7 with LocationAwareLogger

use of org.slf4j.spi.LocationAwareLogger in project vert.x by eclipse.

the class SLF4JLogDelegate method log.

private void log(int level, Object message, Throwable t, Object... params) {
    String msg = (message == null) ? "NULL" : message.toString();
    // We need to compute the right parameters.
    // If we have both parameters and an error, we need to build a new array [params, t]
    // If we don't have parameters, we need to build a new array [t]
    // If we don't have error, it's just params.
    Object[] parameters = params;
    if (params != null && t != null) {
        parameters = new Object[params.length + 1];
        System.arraycopy(params, 0, parameters, 0, params.length);
        parameters[params.length] = t;
    } else if (params == null && t != null) {
        parameters = new Object[] { t };
    }
    if (logger instanceof LocationAwareLogger) {
        // make sure we don't format the objects if we don't log the line anyway
        if (level == TRACE_INT && logger.isTraceEnabled() || level == DEBUG_INT && logger.isDebugEnabled() || level == INFO_INT && logger.isInfoEnabled() || level == WARN_INT && logger.isWarnEnabled() || level == ERROR_INT && logger.isErrorEnabled()) {
            LocationAwareLogger l = (LocationAwareLogger) logger;
            FormattingTuple ft = MessageFormatter.arrayFormat(msg, parameters);
            l.log(null, FQCN, level, ft.getMessage(), null, ft.getThrowable());
        }
    } else {
        switch(level) {
            case TRACE_INT:
                logger.trace(msg, parameters);
                break;
            case DEBUG_INT:
                logger.debug(msg, parameters);
                break;
            case INFO_INT:
                logger.info(msg, parameters);
                break;
            case WARN_INT:
                logger.warn(msg, parameters);
                break;
            case ERROR_INT:
                logger.error(msg, parameters);
                break;
            default:
                throw new IllegalArgumentException("Unknown log level " + level);
        }
    }
}
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