Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogInterceptor #27

Open
jaumard opened this issue Sep 13, 2018 · 5 comments
Open

LogInterceptor #27

jaumard opened this issue Sep 13, 2018 · 5 comments

Comments

@jaumard
Copy link
Contributor

jaumard commented Sep 13, 2018

Would be nice to have by default a logInterceptor that we can add if you want.

We can put log level on it like BASIC / FULL.

BASIC will print: starting POST https://myurl result POST https://myurl status 201

FULL will print:
starting POST https://myurl with data {all the data pretty printed json/form...} result POST https://myurl status 201 with data {all the data pretty printed json/form...}

it will help a lot during debug

@jaumard
Copy link
Contributor Author

jaumard commented Nov 20, 2018

Here is what I've done on my project


class LogInterceptor extends Interceptor {

  static final _log = Logger('LogInterceptor');

  @override
  FutureOr<void> before(RouteBase route) {
    var query = '?';
    route.getQuery.forEach((key, value) => query += '$key=$value&');
    _log.fine('==> ${route.getUrl}$query');
    route.getHeaders.forEach((key, value) => _log.fine('==> $key: $value'));
    if (route is RouteWithBody) {
      _log.fine('\n${route.getBody()}');
    }
    return super.before(route);
  }

  @override
  FutureOr after(StringResponse response) {
    _log.fine('<== ${response.statusCode} ${response.request.url}');
    response.headers.forEach((key, value) => _log.fine('<== $key: $value'));
    _log.fine('\n${response.body}');
    return response;
  }
}

@tejainece
Copy link
Member

    var query = '?';
    route.getQuery.forEach((key, value) => query += '$key=$value&');
    _log.fine('==> ${route.getUrl}$query');

This can be achieved with route.url, i think.

@tejainece
Copy link
Member

This is a good idea. Can you contribute it in resty codebase? Then we make it generic.

@jaumard
Copy link
Contributor Author

jaumard commented Nov 20, 2018

@tejainece route.url is not accessible on RouteBase.
I'll try to make a PR when I've some time :)

@tejainece
Copy link
Member

Oh. We have to move it to RouteBase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants