搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目

暂无相关数据。