搜索插件、代码仓与 APP 分类

插件详情v5.0.1

l

跨平台的 html/io 日志库,拥有简单的 API。可通过原生和 Web 控制台进行操作。支持 ASCII 颜色输出。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3220
喜欢数
93
Pub 分数
160

安装插件

flutter pub add l

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

‘l’ 包是适用于 Flutter 的跨平台日志库,为 Android、iOS、Web、macOS、Windows 和 Linux 提供了简单的 API 来记录消息。它支持通过原生和 Web 控制台进行输出操作,并内置 ASCII 颜色化功能以提高日志可读性。非常适合实时调试和监控应用程序行为,可无缝集成到开发工作流中,且不会增加复杂性。该库轻量级,专为需要一致、彩色且跨平台的日志记录的开发者设计。

适合场景

  • 跨平台实时调试
  • 彩色控制台输出,以提高日志可见性
  • 开发和测试中的简单集成
  • 跨平台日志一致性
  • 在开发过程中监控应用程序行为
  • 同时调试网页和移动应用

主要特点

  • 简单直观的 API
  • ASCII 颜色输出
  • 支持所有主要的Flutter平台
  • 原生和网页控制台兼容性
  • 轻量且快速
  • 通过 flutter pub add 轻松设置

适合对象

  • Flutter 开发人员寻求简易日志记录
  • 构建多平台应用的团队
  • 专注于调试效率的开发者
  • 需要彩色控制台输出的项目
  • 希望减少样板代码记录日志的用户
  • 前端和后端调试日志

使用建议

  • 不适用于生产日志
  • 颜色输出可能在所有环境中都无法渲染
  • 有限的配置选项
  • 最适合开发使用
  • 大型应用中可能需要额外的过滤
  • 取决于控制台的可用性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

[L]ogger

Pub Actions Status Coverage License: MIT Linter GitHub stars

About

Cross-platform html/io logger with simple API. No need to create a logger object. Just import and use. Simple and w/o boilerplate. Work with native console.

Core API

Example of usage

Example of using the library to display a message in the console.

Key features
Method Description
[s] A shout is always displayed
[v1], [v] Regular message with verbose level 1
[e] Error message with verbose level 1
[v2], [vv] Regular message with verbose level 2
[w] Warning message with verbose level 2
[v3], [vvv] Regular message with verbose level 3
[i], [<] Inform message with verbose level 3
[v4], [vvvv] Regular message with verbose level 4
[d], [<<] Debug message with verbose level 4
[v5], [vvvvv] Regular message with verbose level 5
[v6], [vvvvvv] Regular message with verbose level 6
l.s('shout me');
l.e('error msg');
l.w('warning msg');
l.i('info msg');
l < 'alt info msg';
l.d('debug msg');
l << 'alt debug msg';
l.v('verbose lvl #1');
l.vv('verbose lvl #2');
l.vvv('verbose lvl #3');
l.v4('verbose lvl #4');
l.v5('verbose lvl #5');
l.v6('verbose lvl #6');
Integration capabilities
Method Description
[listen] Broadcast stream receiving logs.
// Broadcast stream instantly receiving logs.
l.forEach((log) => print('* ${log.level} : ${log.message}'));
Print handling and customizing

Logger supports fine-tuning with the second argument LogOptions in a capture method. Also, you can handle print and output with l on some function or in a whole app with this simple syntax:

import 'package:l/l.dart';

void main() => l.capture(
      someFunction,
      const LogOptions(
        handlePrint: true,
        printColors: true,
        outputInRelease: false,
        messageFormatting: _messageFormatting,
      ),
    );

Future<void> someFunction() async {
  print('Hello');
  await Future<void>.delayed(const Duration(milliseconds: 150));
  l.d('world');
  await Future<void>.delayed(const Duration(milliseconds: 150));
  l.e('!!!');
}

Object _messageFormatting(Object message, LogLevel logLevel, DateTime now) =>
    '${now.hour}:${now.minute.toString().padLeft(2, '0')} $message';

Handling errors

Flutter
final sourceFlutterError = FlutterError.onError;
FlutterError.onError = (details) {
  l.w(details.exceptionAsString(), details.stack);
  sourceFlutterError?.call(details);
};
Crashlytics
l.where((msg) => msg.level.maybeWhen(
      error: () => true,
      warning: () => true,
      orElse: () => false,
    ))
  .map<String>((msg) => msg.message.toString())
  .listen(FirebaseCrashlytics.instance.log);
Zoned Errors
runZonedGuarded(someFunction, l.e);
Handling uncaught errors
Isolate.current
       ..setErrorsFatal(false)
       ..addErrorListener(
         RawReceivePort(
           (List<dynamic> pair) => // ignore: avoid_types_on_closure_parameters
               l.e(pair.first as Object),
         ).sendPort,
       );

Limitations

  • When there is no direct access to the terminal, it works through print.
  • !!! PLEASE, DO NOT LOG SENSITIVE INFORMATION !!!

Changelog

Refer to the Changelog to get all release notes.

Maintainers

Plague Fox

Funding

If you want to support the development of our library, there are several ways you can do it:

We appreciate any form of support, whether it's a financial donation or just a star on GitHub. It helps us to continue developing and improving our library. Thank you for your support!

License

MIT

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。