Skip to content

Commit 7c24d50

Browse files
committed
🐛 Fix: logLevel bug
1 parent 5be055c commit 7c24d50

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/lib/Logger.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class Logger implements ILogger {
3131

3232
private handleLog (type: ILogType, ...msg: ILogArgvTypeWithError[]): void {
3333
// check config.silent
34-
if (!this.ctx.getConfig<Undefinable<string>>('silent')) {
34+
this.logLevel = this.ctx.getConfig('settings.logLevel')
35+
if (!this.ctx.getConfig<Undefinable<string>>('silent') && this.checkLogLevel(type, this.logLevel)) {
3536
const logHeader = chalk[this.level[type] as ILogColor](`[PicGo ${type.toUpperCase()}]:`)
3637
console.log(logHeader, ...msg)
37-
this.logLevel = this.ctx.getConfig('settings.logLevel')
3838
this.logPath = this.ctx.getConfig<Undefinable<string>>('settings.logPath') || path.join(this.ctx.baseDir, './picgo.log')
3939
setTimeout(() => {
4040
// fix log file is too large, now the log file's default size is 10 MB
@@ -83,22 +83,20 @@ export class Logger implements ILogger {
8383

8484
private handleWriteLog (logPath: string, type: string, ...msg: ILogArgvTypeWithError[]): void {
8585
try {
86-
if (this.checkLogLevel(type, this.logLevel)) {
87-
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `
88-
msg.forEach((item: ILogArgvTypeWithError) => {
89-
if (item instanceof Error && type === 'error') {
90-
log += `\n------Error Stack Begin------\n${util.format(item?.stack)}\n-------Error Stack End------- `
91-
} else {
92-
if (typeof item === 'object') {
93-
item = JSON.stringify(item, null, 2)
94-
}
95-
log += `${item as string} `
86+
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ${type.toUpperCase()}] `
87+
msg.forEach((item: ILogArgvTypeWithError) => {
88+
if (item instanceof Error && type === 'error') {
89+
log += `\n------Error Stack Begin------\n${util.format(item?.stack)}\n-------Error Stack End------- `
90+
} else {
91+
if (typeof item === 'object') {
92+
item = JSON.stringify(item, null, 2)
9693
}
97-
})
98-
log += '\n'
99-
// A synchronized approach to avoid log msg sequence errors
100-
fs.appendFileSync(logPath, log)
101-
}
94+
log += `${item as string} `
95+
}
96+
})
97+
log += '\n'
98+
// A synchronized approach to avoid log msg sequence errors
99+
fs.appendFileSync(logPath, log)
102100
} catch (e) {
103101
console.error('[PicGo Error] on writing log file', e)
104102
}

0 commit comments

Comments
 (0)