| 1 | | | import 'package:logger/web.dart'; |
| 2 | | | |
| 3 | | | class InternalLogger extends Logger { |
| 4 | | 10 | InternalLogger() |
| 5 | | 10 | : super( |
| 6 | | 10 | filter: _LogAllFilter(), |
| 7 | | 10 | printer: _DummyPrinter(), |
| 8 | | 10 | output: _NoLogOutput(), |
| 9 | | | ); |
| 10 | | | } |
| 11 | | | |
| 12 | | | class _NoLogOutput extends LogOutput { |
| 13 | | 10 | @override |
| 14 | | | void output(OutputEvent event) { |
| 15 | | | // Do nothing in this logger (which lives in the worker thread). |
| 16 | | | // The log event will be captured and forwarded to the channelLogger (which |
| 17 | | | // lives in the main thread). |
| 18 | | | } |
| 19 | | | } |
| 20 | | | |
| 21 | | | class _DummyPrinter extends LogPrinter { |
| 22 | | 10 | @override |
| 23 | | | List<String> log(LogEvent event) => |
| 24 | | | // Logger will ignore log events that produce an empty array. |
| 25 | | | // Make sure the array is not empty so the log event is notified |
| 26 | | | // through Logger's output callbacks. |
| 27 | | | const ['']; |
| 28 | | | } |
| 29 | | | |
| 30 | | | class _LogAllFilter extends LogFilter { |
| 31 | | 10 | @override |
| 32 | | | bool shouldLog(LogEvent event) => |
| 33 | | | // Log everything. It's up to the receiving channelLogger to decide |
| 34 | | | // whether the message should be logged or not. |
| 35 | | | true; |
| 36 | | | } |