Skip to main content

Command Palette

Search for a command to run...

Understand logging | flutter

Updated
2 min read
Understand logging | flutter
K

I'm leading or guiding a flutter team(2-3 people) at ketto.org where I've to make apps in solid form which matches the industry app standards. I've more than 5 years of experience [2+yr remote] in mobile platforms

with service and product- based companies. I'm very

passionate to write code for thousands of users.

Ok, So let's start with simple logging first, Which every developer knew

print()

easy to start by logging in to flutter. Right 😀

Okay now, let's play with more sample log data.

  1. "Hello world!"

  2. "I\'m Kishansinh Parmar"

The result of the logs

As you can see that first 2 sample data print everything correctly but what happen with 3rd sample data? It discards some lines from the output, which we aren't expecting right?

If you output too much at once, then Android sometimes discards some log lines. To avoid this, use debugPrint(), from Flutter’s foundation library. This is a wrapper around print that throttles the output to a level that avoids being dropped by Android’s kernel.

The other option for application logging is to use the dart:developer log() function. This allows you to include a bit more granularity and information in the logging output.

Now let's print longer string outputs using the log() function. It works ✌🏻

So as we experienced the developer log() function makes sense for logging in to flutter. Nice

But, wait are you looking for something which is more beautiful for logging then try this package which helps you to log better visible logs.

Caution ⚠️: This package also reduces your log lines if a message is longer.

So my suggestion is to extend the logger class into your own class and gives your class more power with the developer:log function.

Tip: Extend Logger class to your own class

73 views