use of com.canoo.platform.logging.spi.DolphinLoggerBridge in project dolphin-platform by canoo.
the class DolphinLoggerFactory method configure.
public synchronized void configure(final DolphinLoggerConfiguration configuration) {
Assert.requireNonNull(configuration, "configuration");
bridges.clear();
final Iterator<DolphinLoggerBridgeFactory> iterator = ServiceLoader.load(DolphinLoggerBridgeFactory.class).iterator();
while (iterator.hasNext()) {
final DolphinLoggerBridge bridge = iterator.next().create(configuration);
if (bridge != null) {
bridges.add(bridge);
}
}
markers.clear();
for (final DolphinLogger logger : loggerMap.values()) {
logger.updateBridges(Collections.unmodifiableList(bridges));
final Level level = configuration.getLevelFor(logger.getName());
logger.setLevel(level);
}
this.configuration = configuration;
configured.set(true);
}
use of com.canoo.platform.logging.spi.DolphinLoggerBridge 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);
}
}
}
Aggregations