Feature: add logFileSizeLimit for log file

ISSUES CLOSED: #935, #945
This commit is contained in:
PiEgg
2022-07-31 17:47:15 +08:00
parent 3102d7b1ea
commit 219b367f7c
12 changed files with 122 additions and 54 deletions

View File

@@ -1,36 +1,17 @@
import fse from 'fs-extra'
import path from 'path'
import dayjs from 'dayjs'
import util from 'util'
import { dbPathDir } from 'apis/core/datastore/dbChecker'
import { getLogger } from 'apis/core/utils/localLogger'
const STORE_PATH = dbPathDir()
const LOG_PATH = path.join(STORE_PATH, '/picgo.log')
const LOG_PATH = path.join(STORE_PATH, 'picgo-gui-local.log')
const logger = getLogger(LOG_PATH)
// since the error may occur in picgo-core
// so we can't use the log from picgo
export const loggerWriter = (error: Error) => {
try {
const time = dayjs().format('YYYY-MM-DD HH:mm:ss')
let log = `${time} [PicGo ERROR] process error begin`
if (error?.stack) {
log += `\n------Error Stack Begin------\n${util.format(error.stack)}\n-------Error Stack End-------\n`
} else {
const msg = JSON.stringify(error)
log += `${msg}\n`
}
log += `${time} [PicGo ERROR] process error end`
if (!fse.existsSync(LOG_PATH)) {
fse.ensureFileSync(LOG_PATH)
}
fse.appendFileSync(LOG_PATH, log)
} catch (e) {
console.error(e)
}
}
const handleProcessError = (error: Error) => {
console.error(error)
loggerWriter(error)
logger('error', error)
}
process.on('uncaughtException', error => {