File tree Expand file tree Collapse file tree 9 files changed +23
-24
lines changed Expand file tree Collapse file tree 9 files changed +23
-24
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ include: package:lints/recommended.yaml
6
6
linter :
7
7
rules :
8
8
- prefer_const_constructors
9
+ - unawaited_futures
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ import 'package:logger/src/logger.dart';
7
7
abstract class LogFilter {
8
8
Level ? level;
9
9
10
- void init () {}
10
+ Future < void > init () async {}
11
11
12
12
/// Is called every time a new log message is sent and decides if
13
13
/// it will be printed or canceled.
14
14
///
15
15
/// Returns `true` if the message should be logged.
16
16
bool shouldLog (LogEvent event);
17
17
18
- void destroy () {}
18
+ Future < void > destroy () async {}
19
19
}
Original file line number Diff line number Diff line change
1
+ import 'dart:async' ;
2
+
1
3
import 'package:logger/src/logger.dart' ;
2
4
3
5
/// Log output receives a [OutputEvent] from [LogPrinter] and sends it to the
@@ -6,9 +8,9 @@ import 'package:logger/src/logger.dart';
6
8
/// This can be an output stream, a file or a network target. [LogOutput] may
7
9
/// cache multiple log messages.
8
10
abstract class LogOutput {
9
- void init () {}
11
+ Future < void > init () async {}
10
12
11
13
void output (OutputEvent event);
12
14
13
- void destroy () {}
15
+ Future < void > destroy () async {}
14
16
}
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ import 'package:logger/src/logger.dart';
8
8
///
9
9
/// You can implement a `LogPrinter` from scratch or extend [PrettyPrinter] .
10
10
abstract class LogPrinter {
11
- void init () {}
11
+ Future < void > init () async {}
12
12
13
13
/// Is called every time a new [LogEvent] is sent and handles printing or
14
14
/// storing the message.
15
15
List <String > log (LogEvent event);
16
16
17
- void destroy () {}
17
+ Future < void > destroy () async {}
18
18
}
Original file line number Diff line number Diff line change @@ -156,11 +156,11 @@ class Logger {
156
156
}
157
157
158
158
/// Closes the logger and releases all resources.
159
- void close () {
159
+ Future < void > close () async {
160
160
_active = false ;
161
- _filter.destroy ();
162
- _printer.destroy ();
163
- _output.destroy ();
161
+ await _filter.destroy ();
162
+ await _printer.destroy ();
163
+ await _output.destroy ();
164
164
}
165
165
166
166
/// Register a [LogCallback] which is called for each new [LogEvent] .
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class FileOutput extends LogOutput {
18
18
});
19
19
20
20
@override
21
- void init () {
21
+ Future < void > init () async {
22
22
_sink = file.openWrite (
23
23
mode: overrideExisting ? FileMode .writeOnly : FileMode .writeOnlyAppend,
24
24
encoding: encoding,
@@ -32,7 +32,7 @@ class FileOutput extends LogOutput {
32
32
}
33
33
34
34
@override
35
- void destroy () async {
35
+ Future < void > destroy () async {
36
36
await _sink? .flush ();
37
37
await _sink? .close ();
38
38
}
Original file line number Diff line number Diff line change @@ -24,10 +24,8 @@ class MultiOutput extends LogOutput {
24
24
}
25
25
26
26
@override
27
- void init () {
28
- for (var o in _outputs) {
29
- o.init ();
30
- }
27
+ Future <void > init () async {
28
+ await Future .wait (_outputs.map ((e) => e.init ()));
31
29
}
32
30
33
31
@override
@@ -38,9 +36,7 @@ class MultiOutput extends LogOutput {
38
36
}
39
37
40
38
@override
41
- void destroy () {
42
- for (var o in _outputs) {
43
- o.destroy ();
44
- }
39
+ Future <void > destroy () async {
40
+ await Future .wait (_outputs.map ((e) => e.destroy ()));
45
41
}
46
42
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class StreamOutput extends LogOutput {
28
28
}
29
29
30
30
@override
31
- void destroy () {
32
- _controller.close ();
31
+ Future < void > destroy () {
32
+ return _controller.close ();
33
33
}
34
34
}
Original file line number Diff line number Diff line change @@ -186,10 +186,10 @@ void main() {
186
186
expect (printedMessage, 'This is' );
187
187
});
188
188
189
- test ('Logger.close' , () {
189
+ test ('Logger.close' , () async {
190
190
var logger = Logger ();
191
191
expect (logger.isClosed (), false );
192
- logger.close ();
192
+ await logger.close ();
193
193
expect (logger.isClosed (), true );
194
194
});
195
195
}
You can’t perform that action at this time.
0 commit comments