Skip to content

Commit

Permalink
#1281: add new global option --errorLog
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Apr 23, 2024
1 parent 74e9e7c commit c116a84
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,12 @@ yargs(hideBin(process.argv))
description: 'Interactive questions where possible and go with defaults instead',
})
.option('api', {
description: 'Print API calls to log ',
choices: ['log', 'cli'],
description: 'Print API calls to log',
})
.option('errorLog', {
type: 'boolean',
description: 'Create a second log file that only contains error messages',
})
.demandCommand(1, 'Please enter a valid command')
.strict()
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Mcdev {
'changeKeyField',
'changeKeyValue',
'commitHistory',
'errorLog',
'execute',
'filter',
'fixShared',
Expand Down
31 changes: 17 additions & 14 deletions lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,23 @@ export const Util = {
)
),
});
transports.fileError = new winston.transports.File({
// Write logs to additional error-logfile for better visibility of errors
filename: 'logs/' + logFileName + '-errors.log',
level: 'error', // only log errors
lazy: true, // if true, log files will be created on demand, not at the initialization time.
format: winston.format.combine(
winston.format.uncolorize(),
winston.format.timestamp({ format: 'HH:mm:ss.SSS' }),
winston.format.simple(),
winston.format.printf(
(info) => `${info.timestamp} ${info.level}: ${info.message}`
)
),
});
if (Util.OPTIONS.errorLog) {
// used by CI/CD solutions like Copado to quickly show the error message to admins/users
transports.fileError = new winston.transports.File({
// Write logs to additional error-logfile for better visibility of errors
filename: 'logs/' + logFileName + '-errors.log',
level: 'error', // only log errors
lazy: true, // if true, log files will be created on demand, not at the initialization time.
format: winston.format.combine(
winston.format.uncolorize(),
winston.format.timestamp({ format: 'HH:mm:ss.SSS' }),
winston.format.simple(),
winston.format.printf(
(info) => `${info.timestamp} ${info.level}: ${info.message}`
)
),
});
}
}
return transports;
},
Expand Down

0 comments on commit c116a84

Please sign in to comment.