Skip to content

Commit

Permalink
修正日志堆栈信息
Browse files Browse the repository at this point in the history
fix stacktrace in log
  • Loading branch information
jiangtian616 committed Apr 5, 2022
1 parent 443c3af commit e441f29
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apk_build.cmd
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion apk_build.sh
Original file line number Diff line number Diff line change
@@ -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 \
2 changes: 1 addition & 1 deletion ipa.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 12 additions & 8 deletions lib/src/utils/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit e441f29

Please sign in to comment.