use proper logging

master
fuwa 5 years ago
parent 79c163e88f
commit 7ed76efd02

@ -19,9 +19,13 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
*/ */
import 'package:logging/logging.dart';
import 'config/prototype.dart'; import 'config/prototype.dart';
import 'config/cyberwow.dart' as cryptoConfig; import 'config/cyberwow.dart' as cryptoConfig;
final Logger log = new Logger('Default');
const config = cryptoConfig.config; const config = cryptoConfig.config;
const arch = 'arm64'; const arch = 'arm64';
@ -29,3 +33,4 @@ const arch = 'arm64';
const minimumHeight = 118361; const minimumHeight = 118361;
const isPC = arch == 'x86_64'; const isPC = arch == 'x86_64';

@ -56,7 +56,7 @@ Stream<String> runBinary (String name) async* {
"--non-interactive", "--non-interactive",
] + extraArgs + config.extraArgs; ] + extraArgs + config.extraArgs;
print('args: ' + args.toString()); log.info('args: ' + args.toString());
final outputProcess = await Process.start(newPath, args); final outputProcess = await Process.start(newPath, args);
await for (var line in outputProcess.stdout.transform(utf8.decoder)) { await for (var line in outputProcess.stdout.transform(utf8.decoder)) {
@ -64,5 +64,6 @@ Stream<String> runBinary (String name) async* {
} }
// the app should never reach here // the app should never reach here
log.severe('Daemon is gone!');
exit(1); exit(1);
} }

@ -21,6 +21,8 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'dart:io'; import 'dart:io';
import 'dart:async'; import 'dart:async';
@ -35,9 +37,15 @@ import 'widget/syncing.dart';
import 'widget/synced.dart'; import 'widget/synced.dart';
import 'widget/resyncing.dart'; import 'widget/resyncing.dart';
void main() => runApp(MyApp()); void main() {
Logger.root.level = kReleaseMode ? Level.INFO : Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
runApp(CyberWOW_App());
}
class MyApp extends StatelessWidget { class CyberWOW_App extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp return MaterialApp
@ -47,20 +55,20 @@ class MyApp extends StatelessWidget {
( (
primarySwatch: Colors.purple, primarySwatch: Colors.purple,
), ),
home: MyHomePage(title: 'CyberWOW'), home: CyberWOW_Page(title: 'CyberWOW'),
); );
} }
} }
class MyHomePage extends StatefulWidget { class CyberWOW_Page extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key); CyberWOW_Page({Key key, this.title}) : super(key: key);
final String title; final String title;
@override @override
_MyHomePageState createState() => _MyHomePageState(); _CyberWOW_PageState createState() => _CyberWOW_PageState();
} }
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver class _CyberWOW_PageState extends State<CyberWOW_Page> with WidgetsBindingObserver
{ {
int _counter = 0; int _counter = 0;
// AppState _state = LoadingState("init..."); // AppState _state = LoadingState("init...");
@ -70,7 +78,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
// print('app cycle: ${state}'); log.fine('app cycle: ${state}');
setState(() { _notification = state; }); setState(() { _notification = state; });
} }
@ -97,7 +105,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver
void _updateLoading(LoadingState state, String msg) { void _updateLoading(LoadingState state, String msg) {
print('updateLoading: ' + msg); log.fine('updateLoading: ' + msg);
} }
Future<void> buildStateMachine(BlankState _blankState) async { Future<void> buildStateMachine(BlankState _blankState) async {
@ -132,7 +140,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver
@override @override
void initState() { void initState() {
super.initState(); super.initState();
print("MyHomePageState initState"); log.fine("CyberWOW_PageState initState");
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
@ -145,7 +153,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver
} }
Future<bool> _exitApp(BuildContext context) async { Future<bool> _exitApp(BuildContext context) async {
print("MyHomePageState _exitApp"); log.info("CyberWOW_PageState _exitApp");
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
exit(0); exit(0);
} }

@ -112,10 +112,10 @@ class LoadingState extends HookedState {
} }
Future<void> load() async { Future<void> load() async {
print("Loading next"); log.fine("Loading next");
await for (var line in loadingProgress) { await for (var line in loadingProgress) {
// append(line); // append(line);
print(line); log.info(line);
} }
} }
@ -145,7 +145,7 @@ class SyncingState extends HookedState {
} }
Future<SyncedState> next(Stream<String> processOutput) async { Future<SyncedState> next(Stream<String> processOutput) async {
print("Syncing next"); log.fine("Syncing next");
Future<void> printStdout() async { Future<void> printStdout() async {
await for (var line in processOutput) { await for (var line in processOutput) {
@ -155,7 +155,7 @@ class SyncingState extends HookedState {
append(line); append(line);
print(line); log.info(line);
} }
} }
@ -180,7 +180,7 @@ class SyncingState extends HookedState {
printStdout(); printStdout();
await checkSync(); await checkSync();
print('syncing: loop exit'); log.fine('syncing: loop exit');
final _height = await rpc.height(); final _height = await rpc.height();
SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput); SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput);
@ -200,14 +200,14 @@ class SyncedState extends HookedState {
SyncedState(f, s, this.stdout, this.processOutput) : super (f, s); SyncedState(f, s, this.stdout, this.processOutput) : super (f, s);
Future<ReSyncingState> next() async { Future<ReSyncingState> next() async {
print("Synced next"); log.fine("Synced next");
Future<void> logStdout() async { Future<void> logStdout() async {
await for (var line in processOutput) { await for (var line in processOutput) {
if (!synced) break; if (!synced) break;
// print('synced: print stdout loop'); // print('synced: print stdout loop');
stdout += line; stdout += line;
print(line); log.info(line);
} }
} }
@ -228,7 +228,7 @@ class SyncedState extends HookedState {
await checkSync(); await checkSync();
print('synced: loop exit'); log.fine('synced: loop exit');
ReSyncingState _next = ReSyncingState(setState, getNotification, stdout, processOutput); ReSyncingState _next = ReSyncingState(setState, getNotification, stdout, processOutput);
setState(_next); setState(_next);
@ -250,14 +250,14 @@ class ReSyncingState extends HookedState {
} }
Future<SyncedState> next() async { Future<SyncedState> next() async {
print("ReSyncing next"); log.fine("ReSyncing next");
Future<void> printStdout() async { Future<void> printStdout() async {
await for (var line in processOutput) { await for (var line in processOutput) {
if (synced) break; if (synced) break;
// print('re-syncing: print stdout loop'); // print('re-syncing: print stdout loop');
append(line); append(line);
print(line); log.info(line);
} }
} }
@ -275,7 +275,7 @@ class ReSyncingState extends HookedState {
printStdout(); printStdout();
await checkSync(); await checkSync();
print('resync: await exit'); log.fine('resync: await exit');
SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput); SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput);
_next.height = await rpc.height(); _next.height = await rpc.height();
setState(_next); setState(_next);

@ -1,5 +1,5 @@
# Generated by pub # Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
async: async:
dependency: transitive dependency: transitive
@ -7,7 +7,7 @@ packages:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.2.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -60,6 +60,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.3" version: "3.1.3"
logging:
dependency: "direct main"
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.3+2"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
@ -94,14 +101,14 @@ packages:
name: pedantic name: pedantic
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.0" version: "1.7.0"
quiver: quiver:
dependency: transitive dependency: transitive
description: description:
name: quiver name: quiver
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.2" version: "2.0.3"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -148,7 +155,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.4" version: "0.2.5"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -164,5 +171,5 @@ packages:
source: hosted source: hosted
version: "2.0.8" version: "2.0.8"
sdks: sdks:
dart: ">=2.2.0 <3.0.0" dart: ">=2.2.2 <3.0.0"
flutter: ">=0.1.4 <2.0.0" flutter: ">=0.1.4 <2.0.0"

@ -25,6 +25,7 @@ dependencies:
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.2
path_provider: ^1.1.0 path_provider: ^1.1.0
http: ^0.12.0 http: ^0.12.0
logging: ^0.11.3
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save