mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 14:48:13 -05:00
🐛 Fix: some case will cause picgo-gui-local.log too large
This commit is contained in:
parent
ae87a512a1
commit
3c01861122
@ -7,6 +7,7 @@ const checkLogFileIsLarge = (logPath: string): {
|
|||||||
logFileSize?: number
|
logFileSize?: number
|
||||||
logFileSizeLimit?: number
|
logFileSizeLimit?: number
|
||||||
} => {
|
} => {
|
||||||
|
try {
|
||||||
if (fs.existsSync(logPath)) {
|
if (fs.existsSync(logPath)) {
|
||||||
const logFileSize = fs.statSync(logPath).size
|
const logFileSize = fs.statSync(logPath).size
|
||||||
const logFileSizeLimit = 10 * 1024 * 1024 // 10 MB default
|
const logFileSizeLimit = 10 * 1024 * 1024 // 10 MB default
|
||||||
@ -19,6 +20,13 @@ const checkLogFileIsLarge = (logPath: string): {
|
|||||||
return {
|
return {
|
||||||
isLarge: false
|
isLarge: false
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// why throw error???
|
||||||
|
console.error(e)
|
||||||
|
return {
|
||||||
|
isLarge: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const recreateLogFile = (logPath: string): void => {
|
const recreateLogFile = (logPath: string): void => {
|
||||||
@ -32,12 +40,18 @@ const recreateLogFile = (logPath: string): void => {
|
|||||||
* for local log before picgo inited
|
* for local log before picgo inited
|
||||||
*/
|
*/
|
||||||
const getLogger = (logPath: string) => {
|
const getLogger = (logPath: string) => {
|
||||||
|
let hasUncathcedError = false
|
||||||
|
try {
|
||||||
if (!fs.existsSync(logPath)) {
|
if (!fs.existsSync(logPath)) {
|
||||||
fs.ensureFileSync(logPath)
|
fs.ensureFileSync(logPath)
|
||||||
}
|
}
|
||||||
if (checkLogFileIsLarge(logPath).isLarge) {
|
if (checkLogFileIsLarge(logPath).isLarge) {
|
||||||
recreateLogFile(logPath)
|
recreateLogFile(logPath)
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
hasUncathcedError = true
|
||||||
|
}
|
||||||
return (type: string, ...msg: any[]) => {
|
return (type: string, ...msg: any[]) => {
|
||||||
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()}] `
|
||||||
@ -54,9 +68,12 @@ 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 (!hasUncathcedError) {
|
||||||
fs.appendFileSync(logPath, log)
|
fs.appendFileSync(logPath, log)
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
hasUncathcedError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user