搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.2

surf_logger

適用於 Dart 與 Flutter 的生產級日誌記錄器

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1170
喜歡數
24
Pub 分數
150

安裝套件

flutter pub add surf_logger

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

surf_logger 是一個為 Dart 和 Flutter 設計的生產就緒日誌套件,旨在跨多個平台提供結構化、可靠且可配置的日誌記錄。它支援豐富的日誌格式化、過濾以及與外部服務的整合,非常適合在真實應用中進行除錯和監控。此套件由 surf.ru 維護,並可透過 pub.dev 實現無縫安裝。支援 Android、iOS、Web、macOS、Windows 和 Linux,確保在不同部署環境中保持一致的日誌行為。

適用情境

  • 即時應用除錯
  • 生產環境中的錯誤追蹤
  • 效能監控
  • 與分析平台的整合
  • 集中式日誌管理
  • 跨平台一致性

主要特色

  • 結構化日誌輸出
  • 可設定的日誌等級
  • 平台無關設計
  • 可擴展的格式化程式支援
  • 內建效能指標
  • 對自訂日誌接收器的支援

適合對象

  • 生產級別的 Flutter 應用
  • 需要強大日誌記錄的團隊
  • 需要跨平台日誌記錄的應用程式
  • 開發者專注於可觀測性
  • 與後端日誌服務整合的專案
  • 大規模應用維護

使用建議

  • 需要設定才能最佳使用
  • 可能稍微增加應用大小
  • 依賴外部相依性以實現進階功能
  • 在效能關鍵情境中應監控日誌開銷
  • 不適用於簡單的除錯列印
  • 最佳搭配日誌聚合工具使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Surf Logger

Made by Surf 🏄‍♂️🏄‍♂️🏄‍♂️

Build Status Coverage Status Pub Version Pub Likes Pub popularity Flutter Platform

Overview

Surf Logger is a utility that allows for quick and easy configuration of logging for a production-level application.

This library does not limit your use of third-party loggers. Instead, it provides a tool for configuring logging within your application.

Installation

Add surf_logger to your pubspec.yaml file:

dependencies:
  surf_logger: $currentVersion$

At this moment, the current version of surf_logger is surf_logger version.

Example

Creating your own strategy

You can create your own logging strategy for different needs: logging to your own server, through Firebase, through Sentry, etc.

class FirebaseLogStrategy implements LogStrategy {
  final FirebaseCrashlytics _crashlytics;

  CrashlyticsLogStrategy(this._crashlytics);

  @override
  void e(Exception exception, [StackTrace? stackTrace]) {
    _crashlytics.recordError(exception, stackTrace);
  }

  @override
  void log(Object message) {
    _crashlytics.log('$message');
    print('Message: $message');
  }

  @override
  void w(String message, [Exception? exception]) {
    _crashlytics.log('Warning: $message \n Exception: $exception');
  }
}
Choosing a strategy for the circumstances

You can configure the logger for the circumstances. For example, for the application flavor:

LogWriter setupLogger(Env env) {
  return Logger.withStrategies({
    if (env == Env.dev || env == Env.qa) ConsoleLogStrategy(),
    if (env == Env.client || env == Env.qa) FileLogStrategy(),
    if (env == Env.prod) ...[
      FirebaseLogStrategy(),
      SentryLogStrategy(),
    ],
  });
}

Please note that Logger is a class for configuration, while LogWriter is for usage. This way, we provide access only to the necessary methods for logging, namely log, e, and w.

For instance, the following methods will be available to an instance of LogWriter:

void main() {
  final LogWriter logger = _setupLogger();
  runApp(MyApp(logger: logger));
  logger.log('message');
  logger.e(Exception('exception'));
  logger.w('message');
}

And an instance of Logger will have configuration management methods available. It's important to avoid using this class for other purposes, as it could potentially disrupt the configuration.

void main() {
  final Logger logger = _setupLogger();
  runApp(MyApp(logger: logger));
  logger.log('message');
  logger.contains(SomeLogStrategy());
  logger.addStrategy(SomeLogStrategy());
  logger.clearStrategies();
  logger.e(Exception('exception'));
  logger.w('message');
}

Migrating from 1.x.x to 2.x.x

1.x.x

void setupLogger() {
  RemoteLogger.addStrategy(CrashlyticsRemoteLogStrategy());
  Logger.addStrategy(DebugLogStrategy());
  Logger.addStrategy(RemoteLogStrategy());
}

Starting from version 2.0.0, the logger is no longer a singleton. Now, you need to create an instance of the logger. RemoteLogger has been removed. Use LogStrategy to create any required strategy.

LogWriter setupLogger() {
  return Logger.withStrategies({
    CrashlyticsRemoteLogStrategy,
    DebugLogStrategy,
    RemoteLogStrategy(),
  });
}

Changelog

All notable changes to this project will be documented in this file.

Issues

To report your issues, file directly in the Issues section.

Contribute

If you would like to contribute to the package (e.g. by improving the documentation, fixing a bug or adding a cool new feature), please read our contribution guide first and send us your pull request.

Your PRs are always welcome.

How to reach us

Please feel free to ask any questions about this package. Join our community chat on Telegram. We speak English and Russian.

Telegram

License

Apache License, Version 2.0

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。