[clean] add logger
This commit is contained in:
parent
914ba0b9bb
commit
215c334fa3
|
|
@ -1,13 +1,19 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:logger/logger.dart';
|
||||||
import 'package:notube/screens/settings.dart';
|
import 'package:notube/screens/settings.dart';
|
||||||
import 'package:notube/wrapper.dart';
|
import 'package:notube/wrapper.dart';
|
||||||
import 'package:notube/constants.dart';
|
import 'package:notube/constants.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:upgrader/upgrader.dart';
|
import 'package:upgrader/upgrader.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:notube/videoList/cubit/videos_cubit.dart';
|
import 'package:notube/videoList/cubit/videos_cubit.dart';
|
||||||
|
import 'package:notube/services/file_logger.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
@ -25,6 +31,12 @@ void main() async {
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await FileLogger().init();
|
||||||
|
|
||||||
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
|
FileLogger().e('FlutterError', details.exception, details.stack);
|
||||||
|
};
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
EasyLocalization(
|
EasyLocalization(
|
||||||
supportedLocales: [Locale('en', 'US'), Locale('fr', 'FR')],
|
supportedLocales: [Locale('en', 'US'), Locale('fr', 'FR')],
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:get/get_navigation/src/nav2/get_router_delegate.dart';
|
||||||
|
import 'package:logger/logger.dart';
|
||||||
import 'package:notube/constants.dart';
|
import 'package:notube/constants.dart';
|
||||||
import 'package:notube/models/video.dart';
|
import 'package:notube/models/video.dart';
|
||||||
|
import 'package:notube/services/file_logger.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:process_run/shell.dart';
|
import 'package:process_run/shell.dart';
|
||||||
|
|
||||||
|
|
@ -91,12 +94,29 @@ class DLServices {
|
||||||
var command = '${url.trim()} -q --flat-playlist -J';
|
var command = '${url.trim()} -q --flat-playlist -J';
|
||||||
|
|
||||||
var shellLinesController = ShellLinesController();
|
var shellLinesController = ShellLinesController();
|
||||||
var shell = Shell(stdout: shellLinesController.sink, verbose: false);
|
var shellErrorController = ShellLinesController();
|
||||||
|
|
||||||
|
shellErrorController.stream.listen((event) {
|
||||||
|
debugPrint('Analyse error: $event');
|
||||||
|
FileLogger().e('Analyse error: $event');
|
||||||
|
});
|
||||||
|
|
||||||
|
var shell = Shell(
|
||||||
|
stdout: shellLinesController.sink,
|
||||||
|
stderr: shellErrorController.sink,
|
||||||
|
verbose: false);
|
||||||
|
|
||||||
await shell.run('''
|
await shell.run('''
|
||||||
$ytDlpPath $command
|
$ytDlpPath $command
|
||||||
''').then((result) {
|
''').then((result) {
|
||||||
debugPrint('Analyse result: $result');
|
debugPrint('Analyse error: $result');
|
||||||
|
|
||||||
|
FileLogger().d('Analyse result: ${result.toString()}');
|
||||||
|
}).catchError((
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
) {
|
||||||
|
FileLogger().e('Analyse error: $error');
|
||||||
});
|
});
|
||||||
|
|
||||||
return shellLinesController.stream;
|
return shellLinesController.stream;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:logger/logger.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
class FileLogger {
|
||||||
|
static final FileLogger _instance = FileLogger._internal();
|
||||||
|
late Logger _logger;
|
||||||
|
late File _logFile;
|
||||||
|
|
||||||
|
factory FileLogger() {
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileLogger._internal();
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
_logFile = File('apps_logs.txt');
|
||||||
|
|
||||||
|
_logger = Logger(
|
||||||
|
printer: PrettyPrinter(),
|
||||||
|
output: FileOutput(file: _logFile),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void d(String message) {
|
||||||
|
_logger.d(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void i(String message) {
|
||||||
|
_logger.i(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void w(String message) {
|
||||||
|
_logger.w(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void e(String message, [dynamic error, StackTrace? stackTrace]) {
|
||||||
|
_logger.e(message, error: error, stackTrace: stackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> getLogContent() async {
|
||||||
|
return await _logFile.readAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue