Skip to content

Commit

Permalink
Added option to display timestamps in iso format.
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Oct 18, 2020
1 parent 165023a commit 1dad022
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/settings/defaults.js
Expand Up @@ -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,

Expand Down
23 changes: 19 additions & 4 deletions lib/utils/logger.js
Expand Up @@ -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()),
Expand Down Expand Up @@ -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 '';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1dad022

Please sign in to comment.