Search in sources :

Example 46 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple 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 47 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project infrautils by opendaylight.

the class RememberingLogger method error.

@Override
public void error(Marker marker, String format, Object... arguments) {
    if (!LogRule.getMarker().equals(marker)) {
        FormattingTuple mf = MessageFormatter.arrayFormat(format, arguments);
        ERRORS.add(new LogCapture(ERROR, mf.getMessage(), mf.getThrowable()));
    }
    super.error(marker, format, arguments);
}
Also used : LogCapture(org.opendaylight.infrautils.testutils.LogCapture) FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 48 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project dolphin-platform by canoo.

the class DolphinLogger method log.

private void log(final Level level, final Marker marker, final String msg, final Throwable throwable, final Object... arguments) {
    Objects.requireNonNull(level);
    if (DolphinLoggerUtils.isLevelEnabled(this.level, level)) {
        final List<String> tempMarkers = new ArrayList<>();
        if (marker != null) {
            tempMarkers.addAll(convert(marker));
        }
        final List<String> currentMarkers = new ArrayList<>();
        currentMarkers.addAll(addMarkers(tempMarkers));
        currentMarkers.addAll(loggerFactory.getMarkers());
        try {
            final LogMessage logMessage = new LogMessage();
            logMessage.setLoggerName(name);
            logMessage.setLevel(level);
            logMessage.setMessage(msg);
            logMessage.setTimestamp(ZonedDateTime.now());
            logMessage.setThreadName(Thread.currentThread().getName());
            final Map<String, String> context = new HashMap<>();
            ContextManagerImpl.getInstance().getGlobalContexts().forEach(c -> context.put(c.getType(), c.getValue()));
            ContextManagerImpl.getInstance().getThreadContexts().forEach(c -> context.put(c.getType(), c.getValue()));
            logMessage.setContext(Collections.unmodifiableMap(context));
            logMessage.setMarker(currentMarkers);
            if (throwable != null) {
                logMessage.setThrowable(throwable);
            }
            if (arguments != null && arguments.length > 0) {
                final FormattingTuple tp = MessageFormatter.arrayFormat(msg, arguments);
                logMessage.setMessage(tp.getMessage());
                if (logMessage.getThrowable() == null && tp.getThrowable() != null) {
                    logMessage.setThrowable(tp.getThrowable());
                }
            }
            loggerFactory.addToCache(logMessage);
            for (DolphinLoggerBridge bridge : bridges) {
                try {
                    bridge.log(logMessage);
                } catch (Exception e) {
                    System.err.println("Error in Logger: " + e.getMessage());
                }
            }
        } finally {
            removeMarkers(tempMarkers);
        }
    }
}
Also used : DolphinLoggerBridge(com.canoo.platform.logging.spi.DolphinLoggerBridge) LogMessage(com.canoo.platform.logging.spi.LogMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FormattingTuple(org.slf4j.helpers.FormattingTuple)

Aggregations

FormattingTuple (org.slf4j.helpers.FormattingTuple)48 LogRecord (java.util.logging.LogRecord)4 LocationAwareLogger (org.slf4j.spi.LocationAwareLogger)4 LogTask (alien4cloud.topology.task.LogTask)3 LogCapture (org.opendaylight.infrautils.testutils.LogCapture)2 DolphinLoggerBridge (com.canoo.platform.logging.spi.DolphinLoggerBridge)1 LogMessage (com.canoo.platform.logging.spi.LogMessage)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JsonObject (javax.json.JsonObject)1 Test (org.junit.Test)1