@@ -31,10 +31,10 @@ export class Logger implements ILogger {
31
31
32
32
private handleLog ( type : ILogType , ...msg : ILogArgvTypeWithError [ ] ) : void {
33
33
// 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 ) ) {
35
36
const logHeader = chalk [ this . level [ type ] as ILogColor ] ( `[PicGo ${ type . toUpperCase ( ) } ]:` )
36
37
console . log ( logHeader , ...msg )
37
- this . logLevel = this . ctx . getConfig ( 'settings.logLevel' )
38
38
this . logPath = this . ctx . getConfig < Undefinable < string > > ( 'settings.logPath' ) || path . join ( this . ctx . baseDir , './picgo.log' )
39
39
setTimeout ( ( ) => {
40
40
// 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 {
83
83
84
84
private handleWriteLog ( logPath : string , type : string , ...msg : ILogArgvTypeWithError [ ] ) : void {
85
85
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 )
96
93
}
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 )
102
100
} catch ( e ) {
103
101
console . error ( '[PicGo Error] on writing log file' , e )
104
102
}
0 commit comments