Add Logger

This commit is contained in:
LollipopKit
2021-10-25 17:31:35 +08:00
parent b5f5fe2dfc
commit 44e9780e5a
6 changed files with 35 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
# toolbox # Server Monitor & Toolbox
A new Flutter project. A new Flutter project which provide a chart view to display server status data.
## ScreenShots ## ScreenShots
<table> <table>
@@ -14,3 +14,15 @@ A new Flutter project.
</tr> </tr>
</table> </table>
## Milestone
- [x] SSH Connect
- [x] Server Info Store
- [x] Status Chart View
- [x] Base64/Url En/Decode
- [ ] Private Key Store
- [ ] Server Status Detail Page
- [ ] Theme Switch
- [ ] Custom Home Page
## License
`Apache License. LollipopKit 2021`

View File

@@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:logging/logging.dart';
import 'package:ssh2/ssh2.dart'; import 'package:ssh2/ssh2.dart';
import 'package:toolbox/core/extension/stringx.dart'; import 'package:toolbox/core/extension/stringx.dart';
import 'package:toolbox/core/provider_base.dart'; import 'package:toolbox/core/provider_base.dart';
@@ -15,6 +16,8 @@ class ServerProvider extends BusyProvider {
List<ServerInfo> _servers = []; List<ServerInfo> _servers = [];
List<ServerInfo> get servers => _servers; List<ServerInfo> get servers => _servers;
final logger = Logger('ServerProvider');
ServerStatus get emptyStatus => ServerStatus( ServerStatus get emptyStatus => ServerStatus(
cpuPercent: 0, cpuPercent: 0,
memList: [100, 0], memList: [100, 0],
@@ -92,7 +95,11 @@ class ServerProvider extends BusyProvider {
final client = _servers[idx].client; final client = _servers[idx].client;
final connected = await client.isConnected(); final connected = await client.isConnected();
if (!connected) { if (!connected) {
final time1 = DateTime.now();
await client.connect(); await client.connect();
final time2 = DateTime.now();
logger.info(
'Connected to [${info.name}] in [${time2.difference(time1).toString()}].');
} }
final cpu = await client.execute( final cpu = await client.execute(
"top -bn1 | grep load | awk '{printf \"%.2f\", \$(NF-2)}'") ?? "top -bn1 | grep load | awk '{printf \"%.2f\", \$(NF-2)}'") ??

View File

@@ -2,9 +2,9 @@
class BuildData { class BuildData {
static const String name = "ToolBox"; static const String name = "ToolBox";
static const int build = 15; static const int build = 18;
static const String engine = static const String engine =
"Flutter 2.5.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision ffb2ecea52 (2 weeks ago) • 2021-09-17 15:26:33 -0400\nEngine • revision b3af521a05\nTools • Dart 2.14.2\n"; "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (10 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
static const String buildAt = "2021-10-02 19:52:07.676336"; static const String buildAt = "2021-10-25 16:56:13.551427";
static const int modifications = 71; static const int modifications = 0;
} }

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolbox/app.dart'; import 'package:toolbox/app.dart';
import 'package:toolbox/core/analysis.dart'; import 'package:toolbox/core/analysis.dart';
@@ -13,7 +14,13 @@ import 'package:toolbox/locator.dart';
Future<void> initApp() async { Future<void> initApp() async {
await Hive.initFlutter(); await Hive.initFlutter();
await setupLocator(); await setupLocator();
locator<ServerProvider>().loadLocalData();
///设置Logger
Logger.root.level = Level.ALL; // defaults to Level.INFO
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print('[${record.loggerName}][${record.level.name}]: ${record.message}');
});
} }
void runInZone(dynamic Function() body) { void runInZone(dynamic Function() body) {

View File

@@ -222,7 +222,7 @@ packages:
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
logging: logging:
dependency: transitive dependency: "direct main"
description: description:
name: logging name: logging
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View File

@@ -45,6 +45,7 @@ dependencies:
ref: master ref: master
ssh2: ^2.2.3 ssh2: ^2.2.3
charts_flutter: ^0.11.0 charts_flutter: ^0.11.0
logging: ^1.0.2
dev_dependencies: dev_dependencies: