Flutter Logging — Solution to Debugging Nightmare

Anirudh J
2 min readFeb 12, 2020

--

In the booming world of flutter, it’s common that you are discovered it recently. Flutter is a hybrid application development solution that essentially covers most of the developer pains. Also turns out to be the best business solution. In this you will learn how to reduce your pain of debugging in Flutter.

With more code comes more responsibility!

Irrespective of the background that you come from both Android & iOS developers would have heard the terms debug, error, info, verbose etc. In order to use them as a debugging tool, Android & iOS ships them out of the box. When it comes to flutter, there is no such function that is helping us. I came across an amazing package logger that will solve.

I created a demo project to showcase. So what are the essentials?

  1. Install the package
  2. Create an Object of Logger class
  3. Set the printer
  4. Call the necessary function
  5. In your pubspec.yaml file of your Flutter project, inject the following dependency:
logger: ^0.8.3

Before you declare your main() it is essential to create an object for the Logger class.

var logger = Logger(
printer: PrettyPrinter(),
);

Creating this will enable you to call globally, with a printer parameter that will be helpful in customizing you console outputs. Now in order to demo this, I created bunch of FlatButton(s) that will show the outputs in the console as expected.

FlatButton(
child: Text("Debug"),
onPressed: () {
logger.d("This is an example for Debug");
},

),
FlatButton(
child: Text("Debug"),
onPressed: () {
logger.v("This is an example for Verbose");
},

),
FlatButton(
child: Text("Debug"),
onPressed: () {
logger.i("This is an example for Info");
},

),
FlatButton(
child: Text("Debug"),
onPressed: () {
logger.e("This is an example for Debug");
},
),

The Essential output after performing this would be as shown below in the image. Code to this demo can be found on my GitHub Profile.

I wish this article comes handy for your development. Leave your thoughts below! If you liked my article, let the world know by sharing it would your connections.

Shout-out to Simon Leier the creator of logger package that you can find on pub.dev

--

--

Anirudh J

Software Developer | Build websites and mobile apps