astute_logger 2.4.0
astute_logger: ^2.4.0 copied to clipboard
A simple and powerful logger for Flutter apps with support for color-coding, JSON pretty-printing, and performance tracking.
Astute Logger #
A lightweight, production-ready logging package for Flutter applications that provides structured logging, persistent log storage, automatic sensitive data redaction, JSON formatting, execution time measurement, request context support, and colorful console output.
Designed to replace print() with a more powerful, secure, and maintainable logging solution.
โจ Features #
- ๐ Structured logging with multiple log levels
- ๐ Automatic timestamps for every log
- ๐ Persistent log file storage
- ๐ Automatic sensitive data redaction
- ๐จ ANSI colored console output
- ๐ฆ Pretty JSON formatting
- ๐ Pretty list printing
- โฑ Execution time measurement
- ๐ Request/Zone context support
- โก Release mode optimization
- ๐ Unicode & Emoji support
- ๐ Clean and developer-friendly API
๐ฆ Installation #
Add the package to your pubspec.yaml:
dependencies:
astute_logger: ^latest_version
Then run:
flutter pub get
Import the package:
import 'package:astute_logger/astute_logger.dart';
๐ Quick Start #
Create a logger instance.
final logger = Logger("AuthService");
Write logs.
logger.write(
message: "User logged in successfully",
level: LogLevel.info,
);
๐ Log Levels #
Debug #
logger.write(
message: "Fetching user profile",
level: LogLevel.debug,
);
Info #
logger.write(
message: "User authenticated",
level: LogLevel.info,
);
Warning #
logger.write(
message: "API response is taking longer than expected",
level: LogLevel.warning,
);
Error #
logger.write(
message: "Database connection failed",
level: LogLevel.error,
);
๐ Automatic Timestamp #
Every log automatically includes a timestamp.
Example:
[01-07-2026 15:42:18]
๐ท Class-Based Logging #
Create separate loggers for different classes.
final authLogger = Logger("AuthService");
final apiLogger = Logger("ApiService");
Output:
AuthService::login
ApiService::fetchUsers
This makes it easy to identify where logs originate.
๐ Persistent Log Files #
Logs are automatically saved to persistent storage.
Retrieve the log file:
final file = await Logger.getLogFile();
Useful for:
- Production debugging
- User bug reports
- Offline log collection
๐ Automatic Sensitive Data Redaction #
Astute Logger automatically masks sensitive information before writing logs.
Protected data includes:
- Bearer Tokens
- JWT Tokens
- Email Addresses
- Credit Card Numbers
Example:
Before
Authorization: Bearer eyJhbGciOi...
After
Authorization: Bearer [REDACTED]
No additional configuration is required.
๐ฆ Pretty JSON Logging #
Instead of printing raw JSON:
logger.logJson(response);
Produces beautifully formatted output for easier debugging.
๐ Pretty Print Lists #
Print collections in a readable format.
logger.logPrettyList(
users,
label: "Users",
);
๐ฆ JSON List Logging #
Pretty print JSON arrays.
logger.logJsonList(users);
โฑ Measure Execution Time #
Measure the execution duration of any operation.
final result = logger.logExecutionTime(
"Database Query",
() {
return fetchUsers();
},
);
Example output:
Database Query completed in 128 ms
๐ Request Context Logging #
Automatically attach request metadata to logs.
await LoggerContext.runWithContext(
requestId: "REQ-001",
extra: {
"userId": "123",
"platform": "Android",
},
body: () {
logger.write(
message: "User authenticated",
level: LogLevel.info,
);
},
);
Perfect for:
- API requests
- Authentication
- Distributed tracing
- Debugging asynchronous operations
๐จ Colored Console Output #
Print custom colored logs.
logger.logWithColor(
"Everything looks good!",
color: LogColor.green.code,
);
Supported colors include:
- Green
- Blue
- Yellow
- Red
๐ Unicode Support #
Astute Logger fully supports Unicode characters and emojis.
logger.write(
message: "Hello ๐ ไฝ ๅฅฝ ู
ุฑุญุจุง เคจเคฎเคธเฅเคคเฅ",
level: LogLevel.info,
);
๐ API Overview #
| Method | Description |
|---|---|
write() |
Write a log message |
logJson() |
Pretty print JSON |
logJsonList() |
Pretty print JSON arrays |
logPrettyList() |
Pretty print Dart lists |
logExecutionTime() |
Measure execution time |
logWithColor() |
Print colored logs |
Logger.getLogFile() |
Retrieve the persistent log file |
โ Why Astute Logger? #
Unlike simple print() statements, Astute Logger provides:
| Feature | print() | Astute Logger |
|---|---|---|
| Log Levels | โ | โ |
| File Logging | โ | โ |
| Colored Output | โ | โ |
| Timestamps | โ | โ |
| JSON Formatting | โ | โ |
| Pretty Lists | โ | โ |
| Request Context | โ | โ |
| Sensitive Data Redaction | โ | โ |
| Execution Time | โ | โ |
| Release Optimization | โ | โ |
๐ผ Ideal For #
- Flutter Applications
- Enterprise Apps
- Banking Apps
- Healthcare Applications
- E-commerce Platforms
- REST API Clients
- Production Monitoring
- Debugging Complex Applications
๐ค Contributing #
Contributions, feature requests, and bug reports are welcome!
If you find a bug or have a suggestion, please open an issue or submit a pull request.
๐ License #
This project is licensed under the MIT License.