jaspr icon indicating copy to clipboard operation
jaspr copied to clipboard

feat: jaspr_router logging

Open dinko7 opened this issue 1 year ago • 1 comments

Description

GoRouter has a debugLogDiagnostics property which can be set at the router level to show logs during navigation.

Adding this to jaspr_router would help developers debug issues during routing.

The output would be identical to GoRouter's:

Output on startup:

Router: known full paths for routes:
Router:   => /
Router:   =>   /family/:fid
Router:   =>     /family/:fid/person/:pid
Router: known full paths for route names:
Router:   home => /
Router:   family => /family/:fid
Router:   person => /family/:fid/person/:pid

Output on route change:

Router: location changed to /
Router: getting location for name: "person", params: {fid: f2, pid: p1}
Router: going to /family/f2/person/p1
Router: location changed to /family/f2/person/p1

Output on error:

Router: Exception: no routes for location: /foobarquux

Contribution

I would be open to implement this. Haven't really taken a deeper look at the code, but this is what I have so far:

Add debugLogDiagnostics property to the Router:

Router({
    required this.routes,
    this.errorBuilder,
    this.redirect,
    this.redirectLimit = 5,
    this.debugLogDiagnostics = false,
  }) 
  
 final bool debugLogDiagnostics;

Output on startup would be added in the following method:

Future<RouteMatchList> _preload(RouteMatchList match) 

Output on route change would be added in the following method:

 Future<void> _update(
    String location, {
    Object? extra,
    bool updateHistory = true,
    bool replace = false,
  })

Correct me if something is wrong.

dinko7 avatar Mar 25 '24 20:03 dinko7