ghost_logger 1.1.0 copy "ghost_logger: ^1.1.0" to clipboard
ghost_logger: ^1.1.0 copied to clipboard

Can be Unseen but always there. Stealing errors before they steal your users' experience. A flexible logging utility with optional crash reporting integration.

Ghost Logger #

Can be Unseen but always there. Stealing errors before they steal your users' experience.

A lightweight, flexible logging utility with colors/emoji indicators and optional crash reporting integration.

Features #

  • ๐Ÿ‘ป Silent Operation - Works invisibly in the background
  • ๐Ÿšจ Automatic Reporting - Steals errors to prevent user impact
  • ๐ŸŽฏ Multiple Log Levels - Debug, info, warning, and error categorization
  • ๐Ÿ˜Š Emoji Indicators - Quick visual scanning of logs
  • ๐Ÿ”Œ Pluggable Crash Reporting - Implement CrashReporter interface for any service
  • ๐Ÿ› ๏ธ Multiple Output Mechanisms - Print or developer.log output
  • ๐Ÿงช Fully Testable - Zero hard dependencies on crash services
  • ๐Ÿ“ฆ Zero Dependencies - Only depends on Flutter SDK
  • ๐ŸŒ Multi-Platform - Works on iOS, Android, Web, macOS, Windows, Linux

Installation #

Add ghost_logger to your pubspec.yaml:

dependencies:
  ghost_logger: ^1.0.0

Then run:

dart pub get

Quick Start #

Basic Setup #

Import and configure Ghost Logger at your app startup:

import 'package:ghost_logger/ghost_logger.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await GhostLogger.configure(
    isDebugMode: true, // defaults to Flutter's kDebugMode
    loggerType: LoggerType.console,
  );

  runApp(const MyApp());
}

Logging Messages #

Log messages with different severity levels:

GhostLogger.log(
  message: 'Processing user data',
  level: LogLevel.debug,
  tag: 'DataManager',
);

GhostLogger.log(
  message: 'User logged in successfully',
  level: LogLevel.info,
  tag: 'Auth',
);

GhostLogger.log(
  message: 'Deprecated API usage detected',
  level: LogLevel.warning,
  tag: 'API',
);

GhostLogger.log(
  message: 'Network request failed',
  level: LogLevel.error,
  tag: 'Network',
  stackTrace: StackTrace.current,
);

Log Levels #

Ghost Logger supports four severity levels, each with a unique emoji for quick identification:

Level Emoji Use Case
Debug โš’๏ธ Development information, variable values
Info ๐Ÿ‘‰ General app events, user actions
Warning โš ๏ธ Potential issues, deprecations
Error โŒ Failures that need attention

Colored Terminal Output #

Ghost Logger automatically colors your terminal logs based on severity level for better readability:

  • ๐ŸŽจ Debug - Gray text
  • ๐ŸŽจ Info - Cyan text
  • ๐ŸŽจ Warning - Yellow text
  • ๐ŸŽจ Error - Red text

Colors work in most modern terminals and IDEs like VS Code, Android Studio, and IntelliJ IDEA.

Output Mechanisms #

Choose how Ghost Logger outputs messages using LoggerType:

Uses Dart's print() function. Simple but may truncate very long messages.

await GhostLogger.configure(
  isDebugMode: true, // defaults to Flutter's kDebugMode
  loggerType: LoggerType.print,
);

Console #

Uses dart:developer log with enhanced features including log levels but in some IDEs the coloring may not work properly.

await GhostLogger.configure(
  isDebugMode: true,
  loggerType: LoggerType.console,
);

Crash Reporting Integration #

Ghost Logger becomes truly powerful when integrated with crash reporting services. It works with any service that implements the CrashReporter interface.

With Firebase Crashlytics #

Implement the CrashReporter interface for your preferred service:

import 'package:ghost_logger/ghost_logger.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';

class FirebaseCrashReporter implements CrashReporter {
  @override
  Future<void> log(String message) async {
    await FirebaseCrashlytics.instance.log(message);
  }
  
  @override
  Future<void> recordError(
    dynamic exception,
    StackTrace? stackTrace, {
    String? reason,
  }) async {
    await FirebaseCrashlytics.instance.recordError(
      exception,
      stackTrace,
      reason: reason,
    );
  }
  
  @override
  Future<void> setCollectionEnabled(bool enabled) async {
    await FirebaseCrashlytics.instance
        .setCrashlyticsCollectionEnabled(enabled);
  }
}

// Configure with crash reporting
await GhostLogger.configure(
  isDebugMode: false,
  loggerType: LoggerType.console,
  crashReporter: FirebaseCrashReporter(),
  enableCrashReporting: true,
);

Now all errors are silently reported to Firebase Crashlytics while still appearing in your console during development.

Custom Crash Reporter #

Implement the CrashReporter interface for custom services:

import 'package:ghost_logger/ghost_logger.dart';

class CustomCrashReporter implements CrashReporter {
  @override
  Future<void> log(String message) async {
    await sendToCrashService(message);
  }

  @override
  Future<void> recordError(
    dynamic exception,
    StackTrace? stackTrace, {
    String? reason,
  }) async {
    await sendErrorToCrashService(exception, stackTrace, reason);
  }

  @override
  Future<void> setCollectionEnabled(bool enabled) async {
    await configureCollection(enabled);
  }
}

await GhostLogger.configure(
  isDebugMode: false,
  crashReporter: CustomCrashReporter(),
  enableCrashReporting: true,
);

API Reference #

GhostLogger.configure() #

Initializes Ghost Logger with configuration options.

Parameters:

  • isDebugMode Enable/disable console output (default: kDebugMode)
  • loggerType: Output mechanism (default: LoggerType.print)
  • crashReporter: Crash reporting implementation (optional)
  • enableCrashReporting: Enable crash service reporting (default: false)
await GhostLogger.configure(
  isDebugMode: !kReleaseMode,
  loggerType: LoggerType.console,
  crashReporter: GhostFirebase(),
  enableCrashReporting: !kDebugMode,
);

GhostLogger.log() #

Logs a message with optional metadata.

Parameters:

  • message (required): The log content
  • level: Log severity (default: LogLevel.debug)
  • tag: Optional identifier for the log source
  • stackTrace: Optional stack trace for context
  • reportToCrashService: Override crash reporting for this log (optional)
await GhostLogger.log(
  message: 'Something happened',
  level: LogLevel.info,
  tag: 'MyClass',
  stackTrace: StackTrace.current,
);

Best Practices #

  1. Configure Once: Set up Ghost Logger in your main() function, before running the app

  2. Use Tags: Add meaningful tags to identify log sources

GhostLogger.log(message: 'Data loaded', tag: 'DataService');
  1. Appropriate Levels: Use the correct log level for better filtering
LogLevel.debug     // Development only
LogLevel.info      // User actions, flow
LogLevel.warning   // Potential issues
LogLevel.error     // Failures and exceptions
  1. Include Stack Traces: Always include stack traces for errors
GhostLogger.log(
  message: 'Operation failed',
  level: LogLevel.error,
  stackTrace: StackTrace.current,
);
  1. Production Configuration: Disable debug output in production
await GhostLogger.configure(
  isDebugMode: kDebugMode,
  loggerType: LoggerType.console,
  crashReporter: GhostFirebase(),
  enableCrashReporting: kReleaseMode,
);

Examples #

See the example directory for a complete Flutter app demonstrating Ghost Logger usage.

Run the example:

cd example
flutter run

Platform Support #

Ghost Logger works on all platforms:

  • โœ… Android
  • โœ… iOS
  • โœ… Web
  • โœ… macOS
  • โœ… Windows
  • โœ… Linux

Contributing #

Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

For issues, questions, or suggestions, please open an issue on GitHub.


Ghost Logger - Stealing errors before they steal your users' experience. ๐Ÿ‘ป

1
likes
0
points
72
downloads

Publisher

unverified uploader

Weekly Downloads

Can be Unseen but always there. Stealing errors before they steal your users' experience. A flexible logging utility with optional crash reporting integration.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ghost_logger