A simple and customizable colored logger for Flutter applications. Built on top of the logger package with beautiful ANSI color output.
- 🎨 Colored console output - Different colors for each log level
- 🏷️ Prefix-based logging - Create loggers with custom prefixes for better organization
- ⏰ Timestamp support - Optional time display in log messages
- 🔗 Chainable prefixes - Combine loggers using the
+operator - 📦 Pretty JSON printing - Utility function to format JSON output
Add this to your pubspec.yaml:
dependencies:
mylogger:
git:
url: https://github.com/ogak-github/mylogger.gitCall init() once at app startup:
import 'package:mylogger/mylogger.dart';
void main() async {
await MyAppLogger().init();
runApp(MyApp());
}final log = MyLogger('MyScreen');log.d('Debug message');
log.i('Info message');
log.w('Warning message');
log.e('Error message');final log = MyLogger('UserService');
log.d('Fetching user data...');
log.i('User logged in successfully');
log.w('Token will expire soon');
log.e('Failed to fetch user', error: exception, stackTrace: stackTrace);Combine loggers for more context:
final log = MyLogger('AuthService');
final loginLog = log + 'Login';
loginLog.i('Attempting login...');
// Output: [INFO] AuthService - Login - Attempting login...final data = {'name': 'John', 'age': 30};
print(prettyPrintJson(data));
// Output:
// {
// "name": "John",
// "age": 30
// }By default, logs are disabled in release mode. To enable:
final log = MyLogger('Debug', showInReleaseMode: true);| Level | Method | Color |
|---|---|---|
| Trace | - | Cyan |
| Debug | d() |
Purple |
| Info | i() |
Green |
| Warning | w() |
Yellow |
| Error | e() |
Red |
| Fatal | - | White |
To see colors in VS Code debug mode (F5), add this to .vscode/launch.json:
{
"configurations": [
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"console": "terminal"
}
]
}MIT License
