From e441f29d278bd5e4eb8ed94c536ffd7f5d6c36e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=85=B1=E5=A4=A9=E5=B0=8F=E7=A6=BD=E5=85=BD?= Date: Tue, 5 Apr 2022 23:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A5=E5=BF=97=E5=A0=86?= =?UTF-8?q?=E6=A0=88=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix stacktrace in log --- apk_build.cmd | 2 +- apk_build.sh | 2 +- ipa.sh | 2 +- .../gallerys/gallerys_view_logic.dart | 2 +- .../ranklist/ranklist_view_logic.dart | 2 +- lib/src/utils/log.dart | 20 +++++++++++-------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apk_build.cmd b/apk_build.cmd index 87d62e24..e300ad45 100644 --- a/apk_build.cmd +++ b/apk_build.cmd @@ -1 +1 @@ -flutter build apk -t lib/src/main.dart --split-per-abi --obfuscate --split-debug-info=build/app/outputs/symbols +flutter build apk -t lib/src/main.dart --split-per-abi diff --git a/apk_build.sh b/apk_build.sh index 9014cdac..cbbd9486 100644 --- a/apk_build.sh +++ b/apk_build.sh @@ -1,6 +1,6 @@ version=$(head -n 5 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2) -flutter build apk -t lib/src/main.dart --split-per-abi --obfuscate --split-debug-info=build/app/outputs/symbols \ +flutter build apk -t lib/src/main.dart --split-per-abi \ && cp build/app/outputs/apk/release/app-arm64-v8a-release.apk ~/Desktop/JHenTai-${version}-arm64-v8a.apk \ && cp build/app/outputs/apk/release/app-armeabi-v7a-release.apk ~/Desktop/JHenTai-${version}-arm64-v8a.apk \ && cp build/app/outputs/apk/release/app-x86_64-release.apk ~/Desktop/JHenTai-${version}-arm64-v8a.apk \ diff --git a/ipa.sh b/ipa.sh index 7640c4fb..d4c1aa9d 100644 --- a/ipa.sh +++ b/ipa.sh @@ -1,6 +1,6 @@ version=$(head -n 5 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2) -flutter build ios --release --obfuscate --split-debug-info=build/app/outputs/symbols -t lib/src/main.dart \ +flutter build ios --release -t lib/src/main.dart \ && mkdir ~/Desktop/Payload \ && cp -r build/ios/Release-iphoneos/Runner.app/ ~/Desktop/Payload/Runner.app/ \ && cd ~/Desktop \ diff --git a/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart b/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart index fd5e96c6..6b5abe8c 100644 --- a/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart +++ b/lib/src/pages/home/tab_view/gallerys/gallerys_view_logic.dart @@ -239,7 +239,7 @@ class GallerysViewLogic extends GetxController with GetTickerProviderStateMixin .catchError((error) { /// 404 => hide or remove if (error.response?.statusCode != 404) { - Log.error('${'getHistoryGallerysFailed'.tr}:$url', error.message); + Log.error('${'getSomeOfGallerysFailed'.tr}:$url', error.message); } else { Log.info('Gallery 404: $url', false); } diff --git a/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart b/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart index f8f29299..e833ecf8 100644 --- a/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart +++ b/lib/src/pages/home/tab_view/ranklist/ranklist_view_logic.dart @@ -62,7 +62,7 @@ class RanklistViewLogic extends GetxController { ).then((value) => results[index] = value).catchError((error) { /// 404 => hide or remove if (error.response?.statusCode != 404) { - Log.error('${'getRanklistFailed'.tr}: ${baseGallery.galleryUrl}', error.message); + Log.error('${'getSomeOfGallerysFailed'.tr}: ${baseGallery.galleryUrl}', error.message); } else { Log.info('Gallery 404: ${baseGallery.galleryUrl}', false); } diff --git a/lib/src/utils/log.dart b/lib/src/utils/log.dart index d90233b3..18d3a65e 100644 --- a/lib/src/utils/log.dart +++ b/lib/src/utils/log.dart @@ -8,7 +8,7 @@ import 'package:logger/src/outputs/file_output.dart'; import 'package:path/path.dart' as path; class Log { - static final Logger _log = Logger(printer: PrettyPrinter(stackTraceBeginIndex: 1)); + static Logger? _log; static Logger? _logFile; static late final logPath; @@ -19,37 +19,41 @@ class Log { } logPath = path.join(PathSetting.getVisibleDir().path, 'logs'); - io.File logFile = io.File(path.join(logPath, '${DateFormat('yyyy-MM-dd HH:mm:mm').format(DateTime.now())}.log')); await logFile.create(recursive: true); + LogPrinter devPrinter = PrettyPrinter(stackTraceBeginIndex: 1); + LogPrinter prodPrinterWithBox = PrettyPrinter(stackTraceBeginIndex: 1, colors: false, printTime: true); + LogPrinter prodPrinterWithoutBox = PrettyPrinter(stackTraceBeginIndex: 1, colors: false, noBoxingByDefault: true); + + _log = Logger(printer: PrettyPrinter(stackTraceBeginIndex: 1)); _logFile = Logger( - printer: PrettyPrinter(stackTraceBeginIndex: 1, noBoxingByDefault: true, colors: false, printTime: false), + printer: HybridPrinter(prodPrinterWithBox, verbose: prodPrinterWithoutBox, info: prodPrinterWithoutBox), filter: ProductionFilter(), output: FileOutput(file: logFile), ); - PrettyPrinter.levelEmojis[Level.verbose] = '⚙ '; + PrettyPrinter.levelEmojis[Level.verbose] = '✔ '; verbose('init LogUtil success', false); } static void verbose(Object? msg, [bool withStack = true]) { - _log.v(msg, null, withStack ? null : StackTrace.empty); + _log?.v(msg, null, withStack ? null : StackTrace.empty); _logFile?.v(msg, null, withStack ? null : StackTrace.empty); } static void info(Object? msg, [bool withStack = true]) { - _log.i(msg, null, withStack ? null : StackTrace.empty); + _log?.i(msg, null, withStack ? null : StackTrace.empty); _logFile?.i(msg, null, withStack ? null : StackTrace.empty); } static void warning(Object? msg, [bool withStack = true]) { - _log.w(msg, null, withStack ? null : StackTrace.empty); + _log?.w(msg, null, withStack ? null : StackTrace.empty); _logFile?.w(msg, null, withStack ? null : StackTrace.empty); } static void error(Object? msg, [Object? error, StackTrace? stackTrace]) { - _log.e(msg, error, stackTrace); + _log?.e(msg, error, stackTrace); _logFile?.e(msg, error, stackTrace); }