DEIS-Tools / H-Uppaal

MIT License
8 stars 3 forks source link

Refactor: New Logging framework #52

Closed sillydan1 closed 1 year ago

sillydan1 commented 1 year ago

New Logging Framework

This PR adds a revamp of the log-tab panel(s). Providing a much more extendable and unified way for notifying the user with information, warnings and errors.

https://user-images.githubusercontent.com/4085393/201477650-6a3271aa-acbc-47a8-ace3-d2394bdc94a4.mov

How to use

Using the logging framework is easy, thread-safe and reactive!

Anatomy of a log entry

UUID id,                // autogenerated uuid
String service,         // service that produced the service
String message,         // information about what happened
LogLevel level          // Info/Warn/Error level

Add Entries

The basic usage - simply add new logs:

Log.addInfo("Some information")
Log.addWarning("Some warning");
Log.addError("Some error");

Origin Service

If the log originates from somewhere that is not an internal place (i.e. jecdar, uppaal, codeanalysis or some custom program), you can specify what service generated the log:

var myService = "NotHuppaal";
Log.addInfo(myService, "Some information")
Log.addWarning(myService, "Some warning");
Log.addError(myService, "Some error");

Links

You can add inline links to your log message, markdown style:

Log.addWarning("Something is wrong at location [L23](component:MyComponent/L23). Please check it out");

A link can link to many types of things:

// location regex:      [text](location:ComponentName/LocationId)
// edge regex:          [text](edge:ComponentName/EdgeId)
// subcomponent regex:  [text](subcomponent:ComponentName/SubcomponentId)
// jork regex:          [text](jork:ComponentName/JorkId)
// tag regex:           [text](tag:ComponentName/TagId)
// query regex:         [text](query:QueryId)
// component regex:     [text](component:ComponentName)
// file:                [text](generic:filename) (open OS default app)

On Log Entry Events

You can also add event listeners for when new logs are added:

private void subscribeOnLogAdded() {
    Log.addOnLogAddedListener(this::onLogAdded);
}

private void onLogAdded(Log log) {
    // Your code here...
}

Note that the events are being called on the main javafx thread - so you don't need to perform any Platform.runLater operations in your handlers.

Backwards Compatibility

You may notice that this PR doesn't remove the old tabs. This is on purpose. Links to locations doesn't actually work at the moment, since classes in the dk.cs.aau.huppaal.abstractions.* (everything that is a Nearable implementation) doesn't know who their parent component is, so they can't actually create any (working) clickable links. Because of this, I haven't implemented all syntactic elements in the LogLinkQuantifier enumeration.

I have integrated all static functions from CodeAnalysis to also use the new logging framework. I haven't deleted the old code though.

sillydan1 commented 1 year ago

Update: current implementations of Nearable will be linked correctly (the old tabs are still present, but I am fairly sure they could be removed pretty soon):

https://user-images.githubusercontent.com/4085393/202027530-b6229cac-c9ea-4bec-8949-d29b8dda8f2b.mov