Skip to content

Commit

Permalink
Split docs into Dart/Flutter and add information about dart:developer
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnroyal committed Sep 27, 2023
1 parent 437901b commit e208147
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 17 additions & 7 deletions dio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,23 +484,33 @@ For the complete code see [here](../example/lib/queued_interceptor_crsftoken.dar

#### LogInterceptor

You can apply the `LogInterceptor` to log requests and responses automatically in the DEBUG mode:
You can apply the `LogInterceptor` to log requests and responses automatically.

**Note:** `LogInterceptor` should always be the last interceptor added,
otherwise modifications by following interceptors will not be logged.

#### Dart

```dart
dio.interceptors.add(LogInterceptor(responseBody: false)); // Do not output responses body.
```

When using Flutter, you should use `debugPrint` to print logs:
**Note:** When using the default `logPrint` function, logs will only be printed
in DEBUG mode (when the assertion is enabled).


Alternatively `dart:developer`'s log can also be used to log messages.

#### Flutter

When using Flutter, Flutters own `debugPrint` function should be used.
This ensures, that debug messages are also available via `flutter logs`.


```dart
dio.interceptors.add(LogInterceptor(logPrint: (o) => debugPrint(o.toString())));
```

**Note:** `LogInterceptor` should be the last interceptor added, otherwise modifications by following interceptors
will not be logged.

**Note:** Logs will only be printed in the DEBUG mode (when the assertion is enabled).

#### Custom Interceptor

You can customize interceptor by extending the `Interceptor/QueuedInterceptor` class.
Expand Down
3 changes: 3 additions & 0 deletions dio/lib/src/interceptors/log.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:developer';

import '../dio_exception.dart';
import '../dio_mixin.dart';
import '../options.dart';
Expand All @@ -10,6 +12,7 @@ import '../response.dart';
///
/// **Note**
/// When used in Flutter, make sure to use `debugPrint` to print logs.
/// Alternatively `dart:developer`'s `log` function can also be used.
///
/// ```dart
/// dio.interceptors.add(LogInterceptor(
Expand Down

0 comments on commit e208147

Please sign in to comment.