Skip to content

ogak-github/mylogger

Repository files navigation

MyLogger

A simple and customizable colored logger for Flutter applications. Built on top of the logger package with beautiful ANSI color output.

Features

  • 🎨 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

Preview

Preview

Installation

Add this to your pubspec.yaml:

dependencies:
  mylogger:
    git:
      url: https://github.com/ogak-github/mylogger.git

Getting Started

1. Initialize the logger

Call init() once at app startup:

import 'package:mylogger/mylogger.dart';

void main() async {
  await MyAppLogger().init();
  runApp(MyApp());
}

2. Create a logger instance

final log = MyLogger('MyScreen');

3. Start logging

log.d('Debug message');
log.i('Info message');
log.w('Warning message');
log.e('Error message');

Usage Examples

Basic Logging

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);

Chainable Prefixes

Combine loggers for more context:

final log = MyLogger('AuthService');
final loginLog = log + 'Login';

loginLog.i('Attempting login...'); 
// Output: [INFO] AuthService - Login - Attempting login...

Pretty Print JSON

final data = {'name': 'John', 'age': 30};
print(prettyPrintJson(data));
// Output:
// {
//   "name": "John",
//   "age": 30
// }

Release Mode

By default, logs are disabled in release mode. To enable:

final log = MyLogger('Debug', showInReleaseMode: true);

Log Levels

Level Method Color
Trace - Cyan
Debug d() Purple
Info i() Green
Warning w() Yellow
Error e() Red
Fatal - White

VS Code Debug Console (Optional)

To see colors in VS Code debug mode (F5), add this to .vscode/launch.json:

{
    "configurations": [
        {
            "name": "Flutter",
            "type": "dart",
            "request": "launch",
            "console": "terminal"
        }
    ]
}

License

MIT License

About

A simple custom log for flutter dev

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published