// Flutter Tips

Save Time & Money in Flutter Apps
with Smarter Debugging

👤 Rohan Kumar Chaudhary
📅 2024
5 min read
🏷 Flutter · Clean Code · Debugging
"The best bugs are the ones you never ship."

Debugging after an app hits production isn't just frustrating — it's expensive. It drains time, money, and your team's morale. But what if you could catch most issues before they ever reach your users?

That's the power of smart, debug-only logging in Flutter — a small practice that delivers huge returns.

Why Debug-Only Logging?

In Flutter, logs can be useful, but without structure, they become noise. My approach? A custom DebugUtils utility that adds:

And best of all — it only runs when assert statements are active. That means:

The Code

debug_utils.dart
import 'dart:developer' as dev; enum LogLevel { success, info, warning, error, debug } class DebugUtils { static void debugLog( String message, { LogLevel level = LogLevel.debug, bool breakPoint = false, String? tag, }) { assert(() { if (breakPoint) dev.debugger(); _logMessage(message, level: level, tag: tag); return true; }()); } static void _logMessage( String message, { required LogLevel level, String? tag, }) { final timestamp = DateTime.now().toIso8601String(); final levelStr = level.toString().split('.').last.toUpperCase(); final effectiveTag = tag ?? 'DebugUtils'; final formattedMessage = '[$timestamp][$levelStr] $message'; dev.log( formattedMessage, name: '$effectiveTag @rohan-165', level: _mapLogLevelToInt(level), ); } static int _mapLogLevelToInt(LogLevel level) { switch (level) { case LogLevel.success: return 850; case LogLevel.info: return 800; case LogLevel.warning: return 900; case LogLevel.error: return 1000; case LogLevel.debug: return 700; } } }

Real Benefits in Real Projects

This small utility has made a big difference in projects like Nagarik App and Ambition Guru:

How to Use It

main.dart
void main() { DebugUtils.debugLog( "App Init successfully", level: LogLevel.info, ); DebugUtils.debugLog("No Data Found"); DebugUtils.debugLog( "Failed to load user data", level: LogLevel.error, tag: 'UserModel', ); }

Pro Tip: Tag Your Logs

Using tags like 'UserModel' or 'LoginBloc' lets you filter and track logs by feature in the DevTools console. This makes it much easier to diagnose bugs fast — even in large, complex apps.

💡 By Rohan Kumar Chaudhary | Flutter Developer | Clean Code Advocate 🧼💙
Happy Coding! 💙
#FlutterDev #MobileApps #DebuggingTips #CleanArchitecture #AppDevelopment #FlutterTip
Rohan Kumar Chaudhary
Rohan Kumar Chaudhary
Flutter · iOS · Mobile Developer