|
| 1 | +--- |
| 2 | +title: Logging Integration |
| 3 | +caseStyle: canonical |
| 4 | +supportLevel: production |
| 5 | +sidebar_order: 3 |
| 6 | +description: "Learn more about the Sentry Logging integration for the Dart SDK." |
| 7 | +--- |
| 8 | + |
| 9 | +The `sentry_logging` library provides [Logging](https://pub.dev/packages/logging) support for Sentry using the [onRecord property](https://pub.dev/documentation/logging/latest/logging/Logger/onRecord.html). It is able to collect breadcrumbs and capture events. Once this integration is configured, you can use Logging’s public API exclusively or in combination to the Sentry's SDK API to capture and enrich events. |
| 10 | + |
| 11 | +The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/logging/). |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +To add the Logging integration, add the `sentry_logging` dependency. |
| 16 | + |
| 17 | +```yml {filename:pubspec.yaml} |
| 18 | +dependencies: |
| 19 | + sentry: ^6.3.0 |
| 20 | + sentry_logging: ^6.3.0 |
| 21 | + logging: ^1.0.2 |
| 22 | +``` |
| 23 | +
|
| 24 | +## Configure |
| 25 | +
|
| 26 | +Configuration should happen as early as possible in your application's lifecycle. |
| 27 | +
|
| 28 | +```dart |
| 29 | +import 'package:sentry_logging/sentry_logging.dart'; |
| 30 | +import 'package:sentry/sentry.dart'; |
| 31 | + |
| 32 | +Future<void> main() async { |
| 33 | + await Sentry.init( |
| 34 | + (options) { |
| 35 | + options.dsn = '___PUBLIC_DSN___'; |
| 36 | + options.addIntegration(LoggingIntegration()); |
| 37 | + }, |
| 38 | + appRunner: initApp, // Init your App. |
| 39 | + ); |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +## Verify |
| 44 | + |
| 45 | +This snippet captures an intentional error, so you can test that everything is working as soon as you set it up: |
| 46 | + |
| 47 | +```dart |
| 48 | +import 'package:logging/logging.dart'; |
| 49 | +
|
| 50 | +void main() async { |
| 51 | + final log = Logger('MyAwesomeLogger'); |
| 52 | +
|
| 53 | + log.info('a breadcrumb!'); |
| 54 | +
|
| 55 | + try { |
| 56 | + throw Exception(); |
| 57 | + } catch (error, stackTrace) { |
| 58 | + log.severe('an error!', error, stackTrace); |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +<Note> |
| 64 | + |
| 65 | +Learn more about manually capturing an error or message, in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>. |
| 66 | + |
| 67 | +</Note> |
| 68 | + |
| 69 | +To view and resolve the recorded message, log into [sentry.io](https://sentry.io) and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. |
0 commit comments