mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-06 16:07:06 +08:00
🐛 Fix: some case will cause picgo-gui-local.log too large
This commit is contained in:
@@ -7,17 +7,25 @@ const checkLogFileIsLarge = (logPath: string): {
|
|||||||
logFileSize?: number
|
logFileSize?: number
|
||||||
logFileSizeLimit?: number
|
logFileSizeLimit?: number
|
||||||
} => {
|
} => {
|
||||||
if (fs.existsSync(logPath)) {
|
try {
|
||||||
const logFileSize = fs.statSync(logPath).size
|
if (fs.existsSync(logPath)) {
|
||||||
const logFileSizeLimit = 10 * 1024 * 1024 // 10 MB default
|
const logFileSize = fs.statSync(logPath).size
|
||||||
|
const logFileSizeLimit = 10 * 1024 * 1024 // 10 MB default
|
||||||
|
return {
|
||||||
|
isLarge: logFileSize > logFileSizeLimit,
|
||||||
|
logFileSize,
|
||||||
|
logFileSizeLimit
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
isLarge: logFileSize > logFileSizeLimit,
|
isLarge: false
|
||||||
logFileSize,
|
}
|
||||||
logFileSizeLimit
|
} catch (e) {
|
||||||
|
// why throw error???
|
||||||
|
console.error(e)
|
||||||
|
return {
|
||||||
|
isLarge: true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return {
|
|
||||||
isLarge: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +40,17 @@ 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) => {
|
||||||
if (!fs.existsSync(logPath)) {
|
let hasUncathcedError = false
|
||||||
fs.ensureFileSync(logPath)
|
try {
|
||||||
}
|
if (!fs.existsSync(logPath)) {
|
||||||
if (checkLogFileIsLarge(logPath).isLarge) {
|
fs.ensureFileSync(logPath)
|
||||||
recreateLogFile(logPath)
|
}
|
||||||
|
if (checkLogFileIsLarge(logPath).isLarge) {
|
||||||
|
recreateLogFile(logPath)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
hasUncathcedError = true
|
||||||
}
|
}
|
||||||
return (type: string, ...msg: any[]) => {
|
return (type: string, ...msg: any[]) => {
|
||||||
try {
|
try {
|
||||||
@@ -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
|
||||||
fs.appendFileSync(logPath, log)
|
if (!hasUncathcedError) {
|
||||||
|
fs.appendFileSync(logPath, log)
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
hasUncathcedError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user