mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-14 20:33:41 +00:00
fix: client log is not recorded (#141)
This commit is contained in:
1 parent
9249613601
commit
abe3cec13d
6 files changed
+23
-37
No files matched your search
@@ -21,6 +21,7 @@ bin/
|
|||||||
|
|
||||||
*.data
|
*.data
|
||||||
*.db
|
*.db
|
||||||
|
*.log
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func NewDownloader(cfg *DownloaderConfig) *Downloader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logPanic(cfg.StorageDir)
|
logPanic(filepath.Join(cfg.StorageDir, "logs"))
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,22 +640,12 @@ func (d *Downloader) doContinue(task *Task) (err error) {
|
|||||||
|
|
||||||
// redirect stderr to log file, when panic happened log it
|
// redirect stderr to log file, when panic happened log it
|
||||||
func logPanic(logDir string) {
|
func logPanic(logDir string) {
|
||||||
fp := filepath.Join(logDir, "crash.log")
|
if err := util.CreateDirIfNotExist(logDir); err != nil {
|
||||||
// if log file not exists, create it
|
return
|
||||||
var f *os.File
|
}
|
||||||
if _, err := os.Stat(fp); err != nil {
|
f, err := os.Create(filepath.Join(logDir, "crash.log"))
|
||||||
if !os.IsNotExist(err) {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
|
||||||
f, err = os.Create(fp)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
f, err = os.OpenFile(fp, os.O_APPEND|os.O_WRONLY, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
paniclog.RedirectStderr(f)
|
paniclog.RedirectStderr(f)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-13
@@ -3,7 +3,6 @@ package util
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
syspath "path"
|
syspath "path"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -83,17 +82,9 @@ func GetSingleDir(paths []string) string {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// check directory is empty
|
func CreateDirIfNotExist(dir string) error {
|
||||||
func isEmpty(name string) (bool, error) {
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
f, err := os.Open(name)
|
return os.MkdirAll(dir, 0o777)
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
defer f.Close()
|
return nil
|
||||||
|
|
||||||
_, err = f.Readdirnames(1) // Or f.Readdir(1)
|
|
||||||
if err == io.EOF {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
return false, err // Either not empty or error, suits both cases
|
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ class SettingView extends GetView<SettingController> {
|
|||||||
debounceSave({bool needRestart = false}) {
|
debounceSave({bool needRestart = false}) {
|
||||||
var completer = Completer<void>();
|
var completer = Completer<void>();
|
||||||
timer?.cancel();
|
timer?.cancel();
|
||||||
timer = Timer(const Duration(milliseconds: 500), () {
|
timer = Timer(const Duration(milliseconds: 1000), () {
|
||||||
appController
|
appController
|
||||||
.saveConfig()
|
.saveConfig()
|
||||||
.then(completer.complete)
|
.then(completer.complete)
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
|
||||||
import 'util.dart';
|
import 'util.dart';
|
||||||
|
|
||||||
final logger = Logger(
|
final logger = Logger(
|
||||||
printer: PrettyPrinter(),
|
filter: ProductionFilter(),
|
||||||
|
printer: LogfmtPrinter(),
|
||||||
output: buildOutput(),
|
output: buildOutput(),
|
||||||
);
|
);
|
||||||
|
|
||||||
buildOutput() {
|
buildOutput() {
|
||||||
// if is debug mode, output to console
|
// if is debug mode, don't log to file
|
||||||
if (!kDebugMode && Util.isDesktop()) {
|
if (!kDebugMode && Util.isDesktop()) {
|
||||||
return FileOutput(file: File('log.txt'));
|
const logDirPath = 'logs';
|
||||||
|
var logDir = Directory(logDirPath);
|
||||||
|
if (!logDir.existsSync()) {
|
||||||
|
logDir.createSync();
|
||||||
|
}
|
||||||
|
return FileOutput(file: File('$logDirPath/client.log'));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ void showErrorMessage(msg) {
|
|||||||
Get.snackbar(title, ((msg as dynamic).message as Result).msg!);
|
Get.snackbar(title, ((msg as dynamic).message as Result).msg!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Get.snackbar(title, msg);
|
Get.snackbar(title, msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void showMessage(title, msg) {
|
void showMessage(title, msg) {
|
||||||
|
|||||||
Reference in new issue
Block a user