Skip to content

Commit 6b305d6

Browse files
authored
Add integration for logging package (#631)
1 parent c2941ed commit 6b305d6

17 files changed

+664
-0
lines changed

.github/workflows/dart.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
branches:
55
- main
66
pull_request:
7+
paths-ignore:
8+
- 'logging/**'
79
defaults:
810
run:
911
shell: bash

.github/workflows/flutter.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
branches:
55
- main
66
pull_request:
7+
paths-ignore:
8+
- 'logging/**'
79
defaults:
810
run:
911
shell: bash

.github/workflows/logging.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: logging
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
defaults:
8+
run:
9+
shell: bash
10+
jobs:
11+
build:
12+
name: Build ${{matrix.sdk}} on ${{matrix.os}}
13+
runs-on: ${{ matrix.os }}
14+
timeout-minutes: 20
15+
defaults:
16+
run:
17+
working-directory: ./logging
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, windows-latest, macos-latest]
22+
sdk: [stable, beta, dev]
23+
exclude:
24+
# Bad state: Could not run tests with Observatory enabled. Try setting a different port with --port option.
25+
- os: ubuntu-latest
26+
sdk: beta
27+
# hanging often
28+
- os: ubuntu-latest
29+
sdk: dev
30+
- os: macos-latest
31+
sdk: beta
32+
# macos-latest is taking hours due to limited resources
33+
- os: macos-latest
34+
sdk: dev
35+
36+
steps:
37+
- uses: dart-lang/setup-dart@v1
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- uses: actions/checkout@v2
41+
# coverage with 'chrome' platform hangs the build
42+
- name: Test (VM and browser)
43+
run: |
44+
dart pub get
45+
dart test -p chrome
46+
dart test -p vm --coverage=coverage
47+
dart pub run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.packages --report-on=lib
48+
49+
- uses: codecov/codecov-action@v1
50+
if: runner.os == 'Linux'
51+
with:
52+
name: sentry
53+
file: ./logging/coverage/lcov.info
54+
55+
- uses: VeryGoodOpenSource/[email protected]
56+
if: runner.os == 'Linux'
57+
with:
58+
path: "./logging/coverage/lcov.info"
59+
min_coverage: 90
60+
61+
analyze:
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 20
64+
defaults:
65+
run:
66+
working-directory: ./dart
67+
steps:
68+
- uses: dart-lang/setup-dart@v1
69+
with:
70+
sdk: stable
71+
- uses: actions/checkout@v2
72+
- run: |
73+
dart pub get
74+
dart analyze --fatal-infos
75+
dart format --set-exit-if-changed ./
76+
77+
package-analysis:
78+
runs-on: ubuntu-latest
79+
timeout-minutes: 20
80+
steps:
81+
- uses: actions/checkout@v2
82+
- uses: axel-op/dart-package-analyzer@v3
83+
id: analysis
84+
with:
85+
githubToken: ${{ secrets.GITHUB_TOKEN }}
86+
relativePath: dart/
87+
- name: Check scores
88+
env:
89+
TOTAL: ${{ steps.analysis.outputs.total }}
90+
TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
91+
run: |
92+
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
93+
if (( $PERCENTAGE < 100 ))
94+
then
95+
echo Score too low!
96+
exit 1
97+
fi

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
* Feat: Integration for `logging` (#631)
34
* Feat: Add logger name to `SentryLogger` and send errors in integrations to the registered logger (#641)
45

56
# 6.1.2

logging/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build outputs.
6+
build/
7+
8+
# Omit committing pubspec.lock for library packages; see
9+
# https://dart.dev/guides/libraries/private-files#pubspeclock.
10+
pubspec.lock

logging/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CHANGELOG.md

logging/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Sentry integration for `logging` package
2+
===========
3+
4+
<p align="center">
5+
<a href="https://sentry.io" target="_blank" align="center">
6+
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
7+
</a>
8+
<br />
9+
</p>
10+
11+
| package | build | pub | likes | popularity | pub points |
12+
| ------- | ------- | ------- | ------- | ------- | ------- |
13+
| sentry | [![build](https://github.com/getsentry/sentry-dart/workflows/logging/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Alogging) | [![pub package](https://img.shields.io/pub/v/sentry_logging.svg)](https://pub.dev/packages/sentry_logging) | [![likes](https://badges.bar/sentry_logging/likes)](https://pub.dev/packages/sentry_logging/score) | [![popularity](https://badges.bar/sentry_logging/popularity)](https://pub.dev/packages/sentry_logging/score) | [![pub points](https://badges.bar/sentry_logging/pub%20points)](https://pub.dev/packages/sentry_logging/score)
14+
15+
Integration for the [`logging`](https://pub.dev/packages/logging) package.
16+
17+
#### Usage
18+
19+
- Sign up for a Sentry.io account and get a DSN at http://sentry.io.
20+
21+
- Follow the installing instructions on [pub.dev](https://pub.dev/packages/sentry/install).
22+
23+
- Initialize the Sentry SDK using the DSN issued by Sentry.io and add the `LoggingIntegration`
24+
25+
```dart
26+
import 'package:sentry/sentry.dart';
27+
28+
Future<void> main() async {
29+
await Sentry.init(
30+
(options) {
31+
options.dsn = 'https://[email protected]/example';
32+
options.addIntegration(LoggingIntegration());
33+
},
34+
appRunner: initApp, // Init your App.
35+
);
36+
}
37+
38+
void initApp() {
39+
// your app code
40+
}
41+
```
42+
43+
#### Resources
44+
45+
* [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/dart/)
46+
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
47+
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
48+
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
49+
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)

logging/analysis_options.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
include: package:lints/recommended.yaml
2+
3+
analyzer:
4+
strong-mode:
5+
implicit-casts: false
6+
implicit-dynamic: false
7+
language:
8+
strict-raw-types: true
9+
errors:
10+
# treat missing required parameters as a warning (not a hint)
11+
missing_required_param: error
12+
# treat missing returns as a warning (not a hint)
13+
missing_return: error
14+
# allow having TODOs in the code
15+
todo: ignore
16+
# allow self-reference to deprecated members (we do this because otherwise we have
17+
# to annotate every member in every test, assert, etc, when we deprecate something)
18+
deprecated_member_use_from_same_package: warning
19+
# ignore sentry/path on pubspec as we change it on deployment
20+
invalid_dependency: ignore
21+
exclude:
22+
- example/**
23+
24+
linter:
25+
rules:
26+
- prefer_final_locals
27+
- public_member_api_docs
28+
- prefer_single_quotes
29+
- prefer_relative_imports
30+
- unnecessary_brace_in_string_interps
31+
- implementation_imports
32+
- require_trailing_commas
33+
- unawaited_futures
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:sentry_logging/sentry_logging.dart';
2+
import 'dart:async';
3+
import 'package:sentry/sentry.dart';
4+
import 'package:logging/logging.dart';
5+
6+
Future<void> main() async {
7+
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
8+
const dsn =
9+
'https://[email protected]/5428562';
10+
11+
await Sentry.init(
12+
(options) {
13+
options.dsn = dsn;
14+
options.addIntegration(LoggingIntegration());
15+
},
16+
appRunner: runApp,
17+
);
18+
}
19+
20+
Future<void> runApp() async {
21+
final log = Logger('MyAwesomeLogger');
22+
23+
log.warning('a warning!');
24+
25+
try {
26+
throw Exception();
27+
} catch (error, stackTrace) {
28+
// The log from above will be contained in this crash report.
29+
await Sentry.captureException(
30+
error,
31+
stackTrace: stackTrace,
32+
);
33+
}
34+
}

logging/lib/sentry_logging.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library sentry_logging;
2+
3+
export 'src/logging_integration.dart';

0 commit comments

Comments
 (0)