Lumberdash Logging API

repository·master·Indexed 41 days ago

https://github.com/bmw-tech/lumberdash

A simple and powerful logging API for Dart applications featuring a plugin-based architecture. It allows developers to route logs to multiple destinations using LumberdashClient implementations, with official plugins for stdout coloring (colorize_lumberdash), file system logging (file_lumberdash), Firebase Analytics (firebase_lumberdash), Sentry (sentry_lumberdash), and standard printing (print_lumberdash).

Tokens
4.9K
Snippets
17
Records
21
Agent score
50%

What's inside Lumberdash

  1. How Lumberdash clients and plugins work together

    master

    Lumberdash uses a plugin-based architecture where functionality is provided by LumberdashClient implementations. You can register multiple clients simultaneously to route logs to different destinations (e.g., printing to stdout with colors while also sending logs to a remote service like Firebase).

    import 'package:lumberdash/lumberdash.dart';
    import 'package:colorize_lumberdash/colorize_lumberdash.dart';
    import 'package:firebase_lumberdash/firebase_lumberdash.dart';
    
    void main() {
      putLumberdashToWork(withClients: [
        ColorizeLumberdash(),
        FirebaseLumberdash(
          firebaseAnalyticsClient: FirebaseAnalytics(),
          environment: 'development',
          releaseVersion: '1.0.0',
        ),
      ]);
      
      logWarning('Hello Warning');
    }
  2. Integrate Sentry with Lumberdash

    master

    To send logs to Sentry with the appropriate severity levels, use the sentry_lumberdash plugin.

    1. Add sentry_lumberdash to your project dependencies.
    2. Initialize Sentry using Sentry.init and provide your DSN.
    3. Pass an instance of SentryLumberdash() to the putLumberdashToWork function from the lumberdash package using the withClient parameter.

    This plugin is compatible with both sentry-dart and sentry-flutter.

    import 'package:lumberdash/lumberdash.dart';
    import 'package:sentry_lumberdash/sentry_lumberdash.dart';
    import 'dart:async';
    import 'package:sentry/sentry.dart';
    
    Future<void> main() async {
      await Sentry.init(
        (options) {
          options.dsn = 'https://example@sentry.io/add-your-dsn-here';
        },
        appRunner: initApp, // Init your App.
      );
    }
    
    void initApp() {
      putLumberdashToWork(
        withClient: SentryLumberdash(),
      );
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  3. Install and use firebase_lumberdash

    master

    To send logs to Firebase Analytics using Lumberdash, add firebase_lumberdash to your project dependencies. You must instantiate FirebaseLumberdash and pass it to the putLumberdashToWork function within the withClients parameter.

    FirebaseLumberdash requires a firebaseAnalyticsClient (an instance of FirebaseAnalytics) and metadata such as loggerName, environment, and releaseVersion to categorize the logs in Firebase.

    import 'package:lumberdash/lumberdash.dart';
    import 'package:firebase_analytics/firebase_analytics.dart';
    import 'package:firebase_lumberdash/firebase_lumberdash.dart';
    
    void main() {
      putLumberdashToWork(
        withClients: [FirebaseLumberdash(
          firebaseAnalyticsClient: FirebaseAnalytics(),
          loggerName: 'FirebaseLumberdash',
          environment: 'development',
          releaseVersion: '1.0.0',
        )],
      );
    
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  4. Install and use print_lumberdash

    master

    To use print_lumberdash, add it to your project's dependencies. This plugin allows lumberdash to output logs directly to the terminal using the standard print function.

    To initialize it, call putLumberdashToWork from the lumberdash package and pass an instance of PrintLumberdash() in the withClients list.

    import 'package:lumberdash/lumberdash.dart';
    import 'package:print_lumberdash/print_lumberdash.dart';
    
    void main() {
      putLumberdashToWork(
        withClients: [PrintLumberdash()],
      );
    
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  5. Initialize Lumberdash with `putLumberdashToWork`

    master

    To start using Lumberdash, call putLumberdashToWork and provide a list of LumberdashClient instances via the withClients parameter. Once initialized, you can use top-level logging functions like logWarning, logFatal, logMessage, and logError throughout your application.

    import 'package:lumberdash/lumberdash.dart';
    import 'package:colorize_lumberdash/colorize_lumberdash.dart';
    
    void main() {
      putLumberdashToWork(withClients: [ColorizeLumberdash()]);
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  6. Use colorize_lumberdash to colorize log output

    master

    The colorize_lumberdash plugin enables colored log output in your terminal. It prints logs to stdout with different colors based on the severity level of the log message. To use it, add colorize_lumberdash to your project dependencies and pass an instance of ColorizeLumberdash() to the putLumberdashToWork function from the lumberdash package.

    import 'package:colorize_lumberdash/colorize_lumberdash.dart';
    import 'package:lumberdash/lumberdash.dart';
    
    void main() {
      // Initialize lumberdash with the ColorizeLumberdash client
      putLumberdashToWork(withClients: [ColorizeLumberdash()]);
    
      // Logs will now appear in color based on severity
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  7. Create a custom Lumberdash plugin

    master
    To create a custom plugin, add lumberdash to your project dependencies and create a class that extends LumberdashClient. For implementation guidance, you can refer to the SimpleClient provided within the lumberdash package.
  8. Customize iOS launch screen assets

    master

    To customize the launch screen for the iOS version of the project, you can replace the existing image files in the LaunchImage.imageset directory with your own assets.

    Alternatively, you can use Xcode to manage these assets:

    1. Open the iOS workspace using open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog.
    open ios/Runner.xcworkspace
  9. Install and use file_lumberdash

    master

    To log data to the file system using file_lumberdash, add file_lumberdash to your project's dependencies. You must then instantiate FileLumberdash with a filePath and pass it to the putLumberdashToWork function from the core lumberdash package.

    import 'package:lumberdash/lumberdash.dart';
    import 'package:file_lumberdash/file_lumberdash.dart';
    
    void main() {
      putLumberdashToWork(
        withClients: [
            FileLumberdash(filePath: yourFilePath)
        ],
      );
      logWarning('Hello Warning');
      logFatal('Hello Fatal!');
      logMessage('Hello Message!');
      logError(Exception('Hello Error'));
    }
  10. Configure FirebaseLumberdash client

    master

    The FirebaseLumberdash class is used to bridge Lumberdash logs to Firebase Analytics. It accepts the following configuration parameters:

    • firebaseAnalyticsClient: An instance of FirebaseAnalytics used to transmit the data.
    • loggerName: A string identifier for the logger.
    • environment: A string representing the current environment (e.g., 'development', 'production').
    • releaseVersion: A string representing the current version of the application.
  11. Officially supported Lumberdash plugins

    master

    The following plugins are officially supported by BMW for various logging destinations and formatting:

    • colorize_lumberdash: Prints logs to stdout with colors.
    • firebase_lumberdash: Sends logs to Firebase.
    • print_lumberdash: Standard printing.
    • sentry_lumberdash: Sends logs to Sentry.