mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-08 21:38:13 -05:00
🐛 Fix: some bugs will case picgo-gui-local.log too large
ISSUES CLOSED: #995
This commit is contained in:
parent
9791ff24d8
commit
012a01d5d9
@ -22,7 +22,7 @@ const checkLogFileIsLarge = (logPath: string): {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// why throw error???
|
// why throw error???
|
||||||
console.error(e)
|
console.log(e)
|
||||||
return {
|
return {
|
||||||
isLarge: true
|
isLarge: true
|
||||||
}
|
}
|
||||||
@ -30,9 +30,13 @@ const checkLogFileIsLarge = (logPath: string): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const recreateLogFile = (logPath: string): void => {
|
const recreateLogFile = (logPath: string): void => {
|
||||||
if (fs.existsSync(logPath)) {
|
try {
|
||||||
fs.unlinkSync(logPath)
|
if (fs.existsSync(logPath)) {
|
||||||
fs.createFileSync(logPath)
|
fs.unlinkSync(logPath)
|
||||||
|
fs.createFileSync(logPath)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,10 +53,16 @@ const getLogger = (logPath: string) => {
|
|||||||
recreateLogFile(logPath)
|
recreateLogFile(logPath)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.log(e)
|
||||||
hasUncathcedError = true
|
hasUncathcedError = true
|
||||||
}
|
}
|
||||||
return (type: string, ...msg: any[]) => {
|
return (type: string, ...msg: any[]) => {
|
||||||
|
if (hasUncathcedError) {
|
||||||
|
if (checkLogFileIsLarge(logPath).isLarge) {
|
||||||
|
recreateLogFile(logPath)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `
|
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `
|
||||||
msg.forEach((item: ILogArgvTypeWithError) => {
|
msg.forEach((item: ILogArgvTypeWithError) => {
|
||||||
@ -68,11 +78,14 @@ const getLogger = (logPath: string) => {
|
|||||||
log += '\n'
|
log += '\n'
|
||||||
console.log(log)
|
console.log(log)
|
||||||
// A synchronized approach to avoid log msg sequence errors
|
// A synchronized approach to avoid log msg sequence errors
|
||||||
|
if (checkLogFileIsLarge(logPath).isLarge) {
|
||||||
|
recreateLogFile(logPath)
|
||||||
|
}
|
||||||
if (!hasUncathcedError) {
|
if (!hasUncathcedError) {
|
||||||
fs.appendFileSync(logPath, log)
|
fs.appendFileSync(logPath, log)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.log(e)
|
||||||
hasUncathcedError = true
|
hasUncathcedError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { dbPathDir } from 'apis/core/datastore/dbChecker'
|
import { app } from 'electron'
|
||||||
import { getLogger } from 'apis/core/utils/localLogger'
|
import { getLogger } from 'apis/core/utils/localLogger'
|
||||||
const STORE_PATH = dbPathDir()
|
const STORE_PATH = app.getPath('userData')
|
||||||
const LOG_PATH = path.join(STORE_PATH, 'picgo-gui-local.log')
|
const LOG_PATH = path.join(STORE_PATH, 'picgo-gui-local.log')
|
||||||
|
|
||||||
const logger = getLogger(LOG_PATH)
|
const logger = getLogger(LOG_PATH)
|
||||||
@ -10,7 +10,6 @@ const logger = getLogger(LOG_PATH)
|
|||||||
// so we can't use the log from picgo
|
// so we can't use the log from picgo
|
||||||
|
|
||||||
const handleProcessError = (error: Error) => {
|
const handleProcessError = (error: Error) => {
|
||||||
console.error(error)
|
|
||||||
logger('error', error)
|
logger('error', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user