Skip to content

utpal-barman/trace-logger-flutter

Repository files navigation

🕵️ trace_logger: ^1.0.2

Lightweight Flutter/Dart Logger with Class Traceability using the power of StackTrace 🔍

pub package Last Commits Pull Requests Code size License

🔥 TraceLogger is a simple Flutter logging package that logs messages with class names and includes color-coded output for easier debugging and better readability. Use it to automatically capture the calling class context in your logs, along with level-specific emojis (🕵️ ℹ️ ⚠️ ❌) !

Resources 📚

Installation 💻

  1. Add trace_logger to your pubspec.yaml:

    dependencies:
      trace_logger: ^1.0.2
  2. Install the package:

    flutter packages get

Usage

To use TraceLogger, import the package and create an instance of TraceLogger:

import 'package:trace_logger/trace_logger.dart';

final logger = TraceLogger();

Logging with Class Traceability

TraceLogger automatically captures the calling class name when logging messages. Here's an example:

class HomeScreen {
  void someMethod() {
    logger.d('Debugging information');
    logger.i('Informational message');
    logger.w('Warning message');
    logger.e('Error message');
  }
}

Output:

🕵️ [HomeScreen] Debugging information
ℹ️ [HomeScreen] Informational message
⚠️ [HomeScreen] Warning message
❌ [HomeScreen] Error message

Log Levels and Emojis

Level Emoji Color
Debug 🕵️ Cyan
Info ℹ️ Green
Warning ⚠️ Yellow
Error Red

Each log level is represented by an emoji and a color for quick identification.

API Reference

  • logger.d(message) - Logs a debug message.
  • logger.i(message) - Logs an informational message.
  • logger.w(message) - Logs a warning message.
  • logger.e(message) - Logs an error message.

License 📝

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.