mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
opt.: logger & shell script
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
|
||||
import '../../data/res/misc.dart';
|
||||
|
||||
/// format: [NAME][LEVEL]: MESSAGE
|
||||
final _headReg = RegExp(r'(\[[A-Za-z]+\])(\[[A-Z]+\]): (.*)');
|
||||
const _level2Color = {
|
||||
'[INFO]': Colors.blue,
|
||||
'[WARNING]': Colors.yellow,
|
||||
@@ -13,40 +12,37 @@ const _level2Color = {
|
||||
class DebugProvider extends ChangeNotifier {
|
||||
final widgets = <Widget>[];
|
||||
|
||||
void addText(String text) {
|
||||
final match = _headReg.allMatches(text);
|
||||
|
||||
if (match.isNotEmpty) {
|
||||
_addWidget(Text.rich(TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: match.first.group(1),
|
||||
style: const TextStyle(color: Colors.cyan),
|
||||
),
|
||||
TextSpan(
|
||||
text: match.first.group(2),
|
||||
style: TextStyle(color: _level2Color[match.first.group(2)]),
|
||||
),
|
||||
TextSpan(
|
||||
text: '\n${match.first.group(3)}',
|
||||
)
|
||||
],
|
||||
)));
|
||||
} else {
|
||||
_addWidget(Text(text));
|
||||
void addLog(LogRecord record) {
|
||||
final color = _level2Color[record.level.name] ?? Colors.blue;
|
||||
widgets.add(Text.rich(TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: '[${record.loggerName}]',
|
||||
style: const TextStyle(color: Colors.cyan),
|
||||
),
|
||||
TextSpan(
|
||||
text: '[${record.level}]',
|
||||
style: TextStyle(color: color),
|
||||
),
|
||||
TextSpan(
|
||||
text: record.error == null
|
||||
? '\n${record.message}'
|
||||
: '\n${record.message}: ${record.error}',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)));
|
||||
if (record.stackTrace != null) {
|
||||
widgets.add(SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Text(
|
||||
'${record.stackTrace}',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void addMultiline(Object data, [Color color = Colors.blue]) {
|
||||
_addWidget(SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Text('$data', style: TextStyle(color: color)),
|
||||
));
|
||||
}
|
||||
|
||||
void _addWidget(Widget widget) {
|
||||
widgets.add(widget);
|
||||
widgets.add(UIs.height13);
|
||||
|
||||
if (widgets.length > Miscs.maxDebugLogLines) {
|
||||
widgets.removeRange(0, widgets.length - Miscs.maxDebugLogLines);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user