Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding logging to your app


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.

Getting ready

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.

How to do it...

  1. 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'); 
    
  2. 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...