Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flutter_ume_kit_console): add consolePrint method #108

Merged
merged 6 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kits/flutter_ume_kit_console/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.0

* 增加 `consolePrint` 方法,用于适配其他日志库。

* Add `consolePrint` method to adapt other log libraries.

## 1.0.0

* 正式版
Expand Down
46 changes: 46 additions & 0 deletions kits/flutter_ume_kit_console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,54 @@

flutter_ume_kit_console 是 flutter_ume 的日志查看插件包。接入方式请见 [flutter_ume](https://pub.dev/packages/flutter_ume)。

此插件无法直接监听 `print` 或 `developer.log`,需要使用 `debugPrint` 方法打印日志,或者结合 [logging](https://pub.dev/packages/logging)、[logger](https://pub.dev/packages/logger) 等日志库使用。

如果使用其他日志库,可以调用 `consolePrint` 将日志输出到应用内控制台。

```dart
// logging
Logger.root.onRecord.listen((record) {
consolePrint(record.message);
});
```

```dart
// logger
class UmeConsoleOutput extends LogOutput {
@override
void output(OutputEvent event) {
for (var line in event.lines) {
consolePrint(line);
}
}
}
```

----

[flutter_ume](https://pub.dev/packages/flutter_ume) is an in-app debug kits platform produced for Flutter apps by ByteDance Flutter Infra team.

flutter_ume_kit_console is the Console kits package of flutter_ume. Please visit [flutter_ume](https://pub.dev/packages/flutter_ume) for details.

This plugin cannot listen to `print` or `developer.log` directly. You need to use the `debugPrint` method to print logs, or use it with another log library such as [logging](https://pub.dev/packages/logging) or [logger](https://pub.dev/packages/logger).

If you use another log library, you can call `consolePrint` to print the log to the in-app console.

```dart
// logging
Logger.root.onRecord.listen((record) {
consolePrint(record.message);
});
```

```dart
// logger
class UmeConsoleOutput extends LogOutput {
@override
void output(OutputEvent event) {
for (var line in event.lines) {
consolePrint(line);
}
}
}
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:collection';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:tuple/tuple.dart';

const int maxLine = 1000;
Expand Down
6 changes: 6 additions & 0 deletions kits/flutter_ume_kit_console/lib/console/console_print.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'console_manager.dart';

/// Print the message to the console.
void consolePrint(String message) {
ConsoleManager.streamController!.add(message);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library flutter_ume_kit_console;

export 'console/console_panel.dart';
export 'console/console_print.dart';
2 changes: 1 addition & 1 deletion kits/flutter_ume_kit_console/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_ume_kit_console
description: Show debugPrint kit for flutter_ume.
version: 1.0.0
version: 1.1.0
homepage: https://github.com/bytedance/flutter_ume

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tuple/tuple.dart';
import 'package:flutter_ume/core/ui/global.dart';
import 'package:flutter_ume_kit_console/console/console_manager.dart';
import 'package:flutter_ume_kit_console/flutter_ume_kit_console.dart';

import '../mock_classes.dart';
import 'package:tuple/tuple.dart';

void main() {
group('ConsoleManager', () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_ume/core/ui/global.dart';
import 'package:flutter_ume_kit_console/console/console_manager.dart';
Expand Down
15 changes: 15 additions & 0 deletions kits/flutter_ume_kit_console/test/console/console_print_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_ume_kit_console/console/console_manager.dart';
import 'package:flutter_ume_kit_console/flutter_ume_kit_console.dart';

const testMessage = 'Lorem ipsum dolor sit ame';

void main() {
test('consolePrint', () async {
consolePrint(testMessage);
await Future.delayed(Duration.zero);

final lastLog = ConsoleManager.logData.last.item2;
expect(lastLog, testMessage);
});
}