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
66linter :
77 rules :
88 - 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';
77abstract class LogFilter {
88 Level ? level;
99
10- void init () {}
10+ Future < void > init () async {}
1111
1212 /// Is called every time a new log message is sent and decides if
1313 /// it will be printed or canceled.
1414 ///
1515 /// Returns `true` if the message should be logged.
1616 bool shouldLog (LogEvent event);
1717
18- void destroy () {}
18+ Future < void > destroy () async {}
1919}
Original file line number Diff line number Diff line change 1+ import 'dart:async' ;
2+
13import 'package:logger/src/logger.dart' ;
24
35/// Log output receives a [OutputEvent] from [LogPrinter] and sends it to the
@@ -6,9 +8,9 @@ import 'package:logger/src/logger.dart';
68/// This can be an output stream, a file or a network target. [LogOutput] may
79/// cache multiple log messages.
810abstract class LogOutput {
9- void init () {}
11+ Future < void > init () async {}
1012
1113 void output (OutputEvent event);
1214
13- void destroy () {}
15+ Future < void > destroy () async {}
1416}
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ import 'package:logger/src/logger.dart';
88///
99/// You can implement a `LogPrinter` from scratch or extend [PrettyPrinter] .
1010abstract class LogPrinter {
11- void init () {}
11+ Future < void > init () async {}
1212
1313 /// Is called every time a new [LogEvent] is sent and handles printing or
1414 /// storing the message.
1515 List <String > log (LogEvent event);
1616
17- void destroy () {}
17+ Future < void > destroy () async {}
1818}
Original file line number Diff line number Diff line change @@ -156,11 +156,11 @@ class Logger {
156156 }
157157
158158 /// Closes the logger and releases all resources.
159- void close () {
159+ Future < void > close () async {
160160 _active = false ;
161- _filter.destroy ();
162- _printer.destroy ();
163- _output.destroy ();
161+ await _filter.destroy ();
162+ await _printer.destroy ();
163+ await _output.destroy ();
164164 }
165165
166166 /// 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 {
1818 });
1919
2020 @override
21- void init () {
21+ Future < void > init () async {
2222 _sink = file.openWrite (
2323 mode: overrideExisting ? FileMode .writeOnly : FileMode .writeOnlyAppend,
2424 encoding: encoding,
@@ -32,7 +32,7 @@ class FileOutput extends LogOutput {
3232 }
3333
3434 @override
35- void destroy () async {
35+ Future < void > destroy () async {
3636 await _sink? .flush ();
3737 await _sink? .close ();
3838 }
Original file line number Diff line number Diff line change @@ -24,10 +24,8 @@ class MultiOutput extends LogOutput {
2424 }
2525
2626 @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 ()));
3129 }
3230
3331 @override
@@ -38,9 +36,7 @@ class MultiOutput extends LogOutput {
3836 }
3937
4038 @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 ()));
4541 }
4642}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class StreamOutput extends LogOutput {
2828 }
2929
3030 @override
31- void destroy () {
32- _controller.close ();
31+ Future < void > destroy () {
32+ return _controller.close ();
3333 }
3434}
Original file line number Diff line number Diff line change @@ -186,10 +186,10 @@ void main() {
186186 expect (printedMessage, 'This is' );
187187 });
188188
189- test ('Logger.close' , () {
189+ test ('Logger.close' , () async {
190190 var logger = Logger ();
191191 expect (logger.isClosed (), false );
192- logger.close ();
192+ await logger.close ();
193193 expect (logger.isClosed (), true );
194194 });
195195}
You can’t perform that action at this time.
0 commit comments