Search in sources :

Example 6 with LogMessage

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;
}
Also used : Pos(javafx.geometry.Pos) Assert(com.canoo.dp.impl.platform.core.Assert) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) LogMessage(com.canoo.platform.logging.spi.LogMessage) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) Level(org.slf4j.event.Level) LocalTime(java.time.LocalTime) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) DatePicker(javafx.scene.control.DatePicker) PopOver(org.controlsfx.control.PopOver) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label) Property(javafx.beans.property.Property) Set(java.util.Set) Spinner(javafx.scene.control.Spinner) ZoneId(java.time.ZoneId) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) LoggerSearchRequest(com.canoo.platform.logger.model.LoggerSearchRequest) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) Optional(java.util.Optional) CustomTextField(org.controlsfx.control.textfield.CustomTextField) Collections(java.util.Collections) LocalTime(java.time.LocalTime) ZonedDateTime(java.time.ZonedDateTime) Level(org.slf4j.event.Level) LocalDate(java.time.LocalDate)

Example 7 with LogMessage

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);
        }
    }
}
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)

Example 8 with LogMessage

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);
        }
    }
}
Also used : HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) VBox(javafx.scene.layout.VBox) LogMessage(com.canoo.platform.logging.spi.LogMessage) Priority(javafx.scene.layout.Priority) Insets(javafx.geometry.Insets) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Paint(javafx.scene.paint.Paint) Level(org.slf4j.event.Level) DateTimeFormatter(java.time.format.DateTimeFormatter) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) Optional(java.util.Optional) LogMessage(com.canoo.platform.logging.spi.LogMessage) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) Paint(javafx.scene.paint.Paint)

Example 9 with LogMessage

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());
}
Also used : Objects(java.util.Objects) DolphinLoggerConfiguration(com.canoo.platform.logging.DolphinLoggerConfiguration) Date(java.util.Date) Level(org.slf4j.event.Level) DolphinLoggerBridge(com.canoo.platform.logging.spi.DolphinLoggerBridge) Optional(java.util.Optional) LogMessage(com.canoo.platform.logging.spi.LogMessage) AnsiOut(com.canoo.dp.impl.platform.core.ansi.AnsiOut) DateFormat(java.text.DateFormat) Date(java.util.Date)

Aggregations

LogMessage (com.canoo.platform.logging.spi.LogMessage)9 Optional (java.util.Optional)3 Level (org.slf4j.event.Level)3 DolphinLoggerBridge (com.canoo.platform.logging.spi.DolphinLoggerBridge)2 FontAwesomeIcon (de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon)2 FontAwesomeIconView (de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Collections (java.util.Collections)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 Insets (javafx.geometry.Insets)2 Label (javafx.scene.control.Label)2 HBox (javafx.scene.layout.HBox)2 VBox (javafx.scene.layout.VBox)2 Assert (com.canoo.dp.impl.platform.core.Assert)1 AnsiOut (com.canoo.dp.impl.platform.core.ansi.AnsiOut)1 DolphinLoggerFactory (com.canoo.impl.dp.logging.DolphinLoggerFactory)1 Subscription (com.canoo.platform.core.functional.Subscription)1 LogFilterView (com.canoo.platform.logger.client.widgets.LogFilterView)1 LogListCell (com.canoo.platform.logger.client.widgets.LogListCell)1 LoggerSearchRequest (com.canoo.platform.logger.model.LoggerSearchRequest)1