Every production app needs a logger functionality that allows you to output log messages at varying levels of severity (information/warning/debug) to the (web browser's debug) console or a file. This recipe will enable you to do just that quickly and easily.
Use the logging package developed by the Dart team available from pub for this purpose. Add it to your pubspec.yaml
file, and add the code line import 'package:logging/logging.dart'
; to your code. See it in action in bank_terminal_polymer
. We add the import to the code of the Polymer component and model class BankAccount
.
In
web\bank_account.dart
, we have at the top level the following code:import 'package:logging/logging.dart'; final Logger log = new Logger('Bank Account');
We change the constructor to the following code:
BankAccount.created() : super.created() { setupLogger(); log.info('Bank Account component is created'); } setupLogger() is the place where you can define...