diff --git a/lib/settings/defaults.js b/lib/settings/defaults.js index b6502a9905..fc1e18a4ac 100644 --- a/lib/settings/defaults.js +++ b/lib/settings/defaults.js @@ -174,9 +174,15 @@ module.exports = { // Set this to true if you'd like to see timestamps next to the logging output output_timestamp: false, + // Set this to iso if you'd like to see timestamps as ISO strings + timestamp_format: '', + // Set this to true if you'd like to not display errors during the execution of the test (they are shown at the end always). disable_error_log: false, + // By default, API command errors that don't deal with DOM elements (e.g. cookie) are ignored, unless they are thrown by Node.js (e.g. ECONNRESET errors) + report_command_errors: false, + // Take error and failure screenshots during test execution screenshots: false, diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 1cfb1754fe..5ef5231baf 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -28,8 +28,13 @@ function pad(n) { } // 26 Feb 16:19:34 -function timestamp() { +function timestamp(format) { let d = new Date(); + + if (format === 'iso') { + return d.toISOString(); + } + let time = [ pad(d.getHours()), pad(d.getMinutes()), @@ -113,7 +118,7 @@ function logObject(obj) { function logTimestamp() { if (Settings.log_timestamp) { - return colors.white(timestamp()); + return colors.white(timestamp(Settings.timestamp_format)); } return ''; @@ -155,6 +160,15 @@ function logMessage(type, message, args, alwaysShow) { break; } + if (Settings.timestamp_format === 'iso') { + let severity = type.toUpperCase(); + if (severity === Severity.LOG) { + severity = Severity.INFO; + } + + timestamp += ' ' + severity + ' nightwatch:'; + } + console[logMethod](timestamp, messageStr); if (args.length > 0) { @@ -206,7 +220,7 @@ const Logger = { setOptions(settings) { Logger.setOutputEnabled(settings.output); Logger.setDetailedOutput(settings.detailed_output); - Logger.setLogTimestamp(settings.output_timestamp); + Logger.setLogTimestamp(settings.output_timestamp, settings.timestamp_format); Logger.setErrorLog(settings.disable_error_log); if (settings.disable_colors) { @@ -269,8 +283,9 @@ const Logger = { return Settings.outputEnabled && Settings.detailedOutput; }, - setLogTimestamp(val) { + setLogTimestamp(val, format) { Settings.log_timestamp = val; + Settings.timestamp_format = format; }, isLogTimestamp() {