use of com.canoo.platform.logging.spi.LogMessage in project dolphin-platform by canoo.
the class LogFilterView method filter.
public boolean filter(final LogMessage message) {
Assert.requireNonNull(message, "message");
final LocalDate startDate = Optional.ofNullable(startDatePicker.getValue()).orElse(LocalDate.now());
final LocalTime startTime = LocalTime.of(startHourSpinner.getValue(), startMinuteSpinner.getValue(), startSecondSpinner.getValue(), startMilliSpinner.getValue() * 1_000_000);
final ZonedDateTime startDateTime = ZonedDateTime.of(LocalDateTime.of(startDate, startTime), ZoneId.systemDefault());
final LocalDate endDate = Optional.ofNullable(endDatePicker.getValue()).orElse(LocalDate.now());
final LocalTime endTime = LocalTime.of(endHourSpinner.getValue(), endMinuteSpinner.getValue(), endSecondSpinner.getValue(), endMilliSpinner.getValue() * 1_000_000);
final ZonedDateTime endDateTime = ZonedDateTime.of(LocalDateTime.of(endDate, endTime), ZoneId.systemDefault());
final Set<Level> selectedLevels = Optional.ofNullable(levelComboBox.getSelectionModel().getSelectedItem()).map(l -> Collections.singleton(l)).orElse(Collections.emptySet());
if (!selectedLevels.contains(message.getLevel())) {
return false;
}
if (message.getTimestamp().isBefore(startDateTime)) {
return false;
}
if (message.getTimestamp().isAfter(endDateTime)) {
return false;
}
return true;
}
use of com.canoo.platform.logging.spi.LogMessage 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);
}
}
}
use of com.canoo.platform.logging.spi.LogMessage in project dolphin-platform by canoo.
the class LogListView method update.
private void update() {
final LogMessage message = logMessage.get();
if (message == null) {
messageLabel.setText(null);
levelIconView.setIcon(FontAwesomeIcon.QUESTION);
levelIconView.setFill(Color.TRANSPARENT);
timestampLabel.setText(null);
detailsLabel.setText(null);
detailsLabel.setVisible(false);
detailsLabel.setManaged(false);
} else {
messageLabel.setText(message.getMessage());
final FontAwesomeIcon icon = Optional.ofNullable(message.getLevel()).map(l -> {
if (l.equals(Level.INFO)) {
return FontAwesomeIcon.INFO_CIRCLE;
} else if (l.equals(Level.DEBUG)) {
return FontAwesomeIcon.BUG;
} else if (l.equals(Level.ERROR)) {
return FontAwesomeIcon.TIMES_CIRCLE;
} else if (l.equals(Level.TRACE)) {
return FontAwesomeIcon.MINUS_CIRCLE;
} else if (l.equals(Level.WARN)) {
return FontAwesomeIcon.WARNING;
} else {
return FontAwesomeIcon.QUESTION;
}
}).orElse(FontAwesomeIcon.QUESTION);
levelIconView.setIcon(icon);
final Paint iconFill = Optional.ofNullable(message.getLevel()).map(l -> {
if (l.equals(Level.INFO)) {
return Color.LIGHTBLUE;
} else if (l.equals(Level.DEBUG)) {
return Color.LIGHTBLUE;
} else if (l.equals(Level.ERROR)) {
return Color.RED;
} else if (l.equals(Level.TRACE)) {
return Color.LIGHTBLUE;
} else if (l.equals(Level.WARN)) {
return Color.ORANGE;
} else {
return Color.LIGHTBLUE;
}
}).orElse(Color.LIGHTBLUE);
levelIconView.setFill(iconFill);
final String timestamp = Optional.ofNullable(message.getTimestamp()).map(t -> DateTimeFormatter.ofPattern("dd/MM/yyyy - hh:mm:ss.SSS").format(t)).orElse("unknown");
timestampLabel.setText(timestamp);
detailsLabel.setText(message.getExceptionDetail());
if (Optional.ofNullable(detailsLabel.getText()).orElse("").length() == 0) {
detailsLabel.setVisible(false);
detailsLabel.setManaged(false);
} else {
detailsLabel.setVisible(true);
detailsLabel.setManaged(true);
}
}
}
use of com.canoo.platform.logging.spi.LogMessage in project dolphin-platform by canoo.
the class SimpleDolphinLogger method log.
@Override
public void log(final LogMessage logMessage) {
final String textColor = Optional.ofNullable(logMessage.getLevel()).map(l -> {
if (l.equals(Level.ERROR)) {
return AnsiOut.ANSI_RED;
}
if (l.equals(Level.WARN)) {
return AnsiOut.ANSI_YELLOW;
}
if (l.equals(Level.INFO)) {
return AnsiOut.ANSI_BLUE;
}
return AnsiOut.ANSI_CYAN;
}).orElse(AnsiOut.ANSI_CYAN);
final StringBuilder buf = new StringBuilder();
buf.append(AnsiOut.ANSI_WHITE);
final Date timestamp = Date.from(logMessage.getTimestamp().toInstant());
buf.append(dateFormat.format(timestamp));
buf.append(AnsiOut.ANSI_RESET);
buf.append(" ");
buf.append(AnsiOut.ANSI_BOLD);
buf.append(textColor);
buf.append(logMessage.getLevel());
buf.append(" - ");
buf.append(logMessage.getMessage());
buf.append(AnsiOut.ANSI_RESET);
buf.append(AnsiOut.ANSI_WHITE);
buf.append(" - ");
buf.append(logMessage.getLoggerName());
if (!logMessage.getMarker().isEmpty()) {
buf.append(" - [");
for (String marker : logMessage.getMarker()) {
buf.append(marker);
if (logMessage.getMarker().indexOf(marker) < logMessage.getMarker().size() - 1) {
buf.append(", ");
}
}
buf.append("]");
}
buf.append(" - ");
buf.append(logMessage.getThreadName());
buf.append(AnsiOut.ANSI_RESET);
if (logMessage.getThrowable() != null) {
buf.append(AnsiOut.ANSI_RED);
buf.append(System.lineSeparator());
buf.append(logMessage.getExceptionDetail());
buf.append(AnsiOut.ANSI_RESET);
}
print(buf.toString());
}
Aggregations