flutter_debug_logger 2.1.0
flutter_debug_logger: ^2.1.0 copied to clipboard
FlutterDebugLogger is a singleton utility class designed to print neatly formatted and readable JSON responses (especially for debugging HTTP calls) in your Flutter application.
flutter_debug_logger #
flutter_debug_logger is a lightweight and developer-friendly Flutter utility package for logging API responses in a clean, Postman-like style.
It pretty-prints JSON and adds status emojis, making your console logs more structured and readable while debugging REST APIs. #
π Features #
- β Pretty JSON Logging β Beautifies Map, List, or JSON String responses
- β Custom Tags β Easily identify logs with tag values
- β HTTP Method Logging β Log request method (GET, POST, PUT, etc.)
- β Status Emojis β Visual status indicators (β , β οΈ, β) based on status code
- β Safe & Error-Handled β Handles invalid JSON, null/empty bodies, and unsupported types gracefully
- β Zero Dependencies β Simple and efficient with no external dependencies
π¦ Installation #
Add this to your pubspec.yaml:
dependencies:
flutter_debug_logger: ^2.1.0
π§© Getting Started #
Simply import the package in your Dart file:
import 'package:flutter_debug_logger/flutter_debug_logger.dart';
β Usage Example #
FlutterDebugLogger.printJsonResponse(
url: 'https://api.example.com/product',
method: Method.GET,
tag: 'PRODUCT_API',
statusCode: response.statusCode,
responseBody: response.body,
);
π§ͺ Example Output #
βββββββββββββββ π¦ [PRODUCT_API] API DEBUG LOG START βββββββββββββββ
----->[PRODUCT_API] URL ==> https://api.example.com/product
----->[PRODUCT_API] Method ==> GET
----->[PRODUCT_API] StatusCode ==> 200 β
----->[PRODUCT_API] Body ==> {
"success": true,
"product": {
"id": 101,
"name": "Wireless Headphones",
"price": 59.99,
"in_stock": true,
"categories": [
"Electronics",
"Audio"
],
"rating": {
"average": 4.5,
"count": 234
}
}
}
βββββββββββββββ π [PRODUCT_API] API DEBUG LOG END βββββββββββββββ
β οΈ Error Handling #
- flutter_debug_logger will never crash your app when encountering unexpected data:
- Null or empty body β Logs βΉοΈ No Content
- HTTP 204 β Logs βΉοΈ No Content (204 response)
- Invalid JSON string β Logs raw string as-is
- Unsupported types β Logs a fallback message like:
---->> β οΈ Unsupported response body type: double
or
---->> [TAG] Failed to parse response body: FormatException...
π§ Why Use This Package? #
- Simplifies API debugging
- Makes log outputs human-readable
- Visual cues for response success/warning/error
- Works with both JSON strings and structured data
- Clearly separates logs by tag and request method
- Safe from crashes or formatting exceptions
π Whatβs New (v2.1.0) #
- π¨ Added status emojis for quick status recognition (
βsuccess,β οΈwarning,βerror,βΉοΈinfo) - π Improved DartDoc for both
Methodenum andFlutterDebugLoggerclass - π‘ Enhanced error handling for:
- Null responses
- Empty string bodies
- Invalid or malformed JSON
- HTTP 204 No Content responses
- π¦ Added log block markers for start/end to make console logs Postman-like
- β‘ Fallback handling for unsupported types (logs type warning instead of crashing)
π Migration Notes #
- If you previously passed raw string bodies, they are now safely logged even if not valid JSON
- Start and end separators are automatically added to make logs visually clearer
- JSON strings are pretty-printed with indentation by default
π¨βπ» Author #
Raihan Sikdar
Website: raihansikdar.com
Email: [email protected]
GitHub: raihansikdar
LinkedIn: raihansikdar
License #
This project is licensed under the MIT License. See the LICENSE file for more details.
MIT License
Copyright (c) 2025 Raihan Sikdar
Permission is hereby granted, free of charge, to any person obtaining a copy...