qupath / log-viewer

Apache License 2.0
5 stars 2 forks source link

Log Viewer

Log viewer

A simple JavaFX log viewer that can be integrated to any Java application (it is currently used by the QuPath software) and that displays live logs generated using the SLF4J API.

The project contains three UI implementations:

Three logging frameworks are currently supported: the JavaTM 2 platform's core logging facilities, Logback, and reload4j.

Installing

The repository contains eight subprojects:

To use the log viewer, choose one of the UI implementation, one of the logging framework, and install them:

//build.gradle

dependencies {
  def logViewerVersion = "0.1.0-SNAPSHOT"

  // Choose one of those UI implementation:
  implementation "io.github.qupath:logviewer-ui-main:${logViewerVersion}"
  implementation "io.github.qupath:logviewer-ui-textarea:${logViewerVersion}"
  implementation "io.github.qupath:logviewer-ui-richtextfx:${logViewerVersion}"

  // Choose one of those logging framework:
  implementation "io.github.qupath:logviewer-logging-jdk:${logViewerVersion}"
  implementation "io.github.qupath:logviewer-logging-logback:${logViewerVersion}"
  implementation "io.github.qupath:logviewer-logging-reload4j:${logViewerVersion}"
}

If you don't use Java modules in your application, you also have to import the javafx.controls and javafx.fxml modules:

//build.gradle

javafx {
    version = ...
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

Then, create the chosen UI implementation. Here is an example with log-viewer:

//TestApp.java

public class TestApp extends Application {
    private final static Logger logger = LoggerFactory.getLogger(TestApp.class);

    public static void main(String[] args) {
        Application.launch(TestApp.class, args);
    }

    @Override
    public void start(Stage primaryStage) throws IOException {
        LogViewer logviewer = new LogViewer();
        Scene scene = new Scene(logviewer, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();

        // These messages should appear in the log viewer
        logger.info("Here's my first log message, for information");
        logger.error("Here's an error");
    }
}

All messages logged with the SLF4J API will automatically be displayed by the log viewer (if they are not filtered).

Take a look at the code of the logviewer-app subproject to see how to use the other UI implementations.

Building

You can build every module of the log viewer from source with:

./gradlew clean build

The outputs will be under each subproject's build/libs.

Developing

The easiest way to develop the application is to use the logviewer-app subproject. It starts an application that uses one of the UI implementation depending on the provided arguments:

Here are two example:

./gradlew logviewer-app:run --args="--app=main"          // starts the log viewer. No logs are generated
./gradlew logviewer-app:run --args="--app=richtextfx -t" // starts the richtextfx implementation and log random messages

If you want to add a new UI implementation:

If you want to add a new logging framework: