Skip to content

Commit

Permalink
fix: Properly format log timestamps (appium#14889)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Nov 17, 2020
1 parent c083af5 commit 8ed7bae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 9 additions & 6 deletions lib/logsink.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import npmlog from 'npmlog';
import { createLogger, format, transports } from 'winston';
import { fs, logger } from 'appium-support';
import dateformat from 'dateformat';
import _ from 'lodash';


Expand Down Expand Up @@ -36,16 +35,20 @@ const npmToWinstonLevels = {
};

let log = null;
let timeZone = null;
let useLocalTimeZone = false;

// add the timestamp in the correct format to the log info object
const timestampFormat = format.timestamp({
format () {
let date = new Date();
if (!timeZone) {
date = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);
if (useLocalTimeZone) {
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
}
return dateformat(date, 'yyyy-mm-dd HH:MM:ss:l');
// '2012-11-04T14:51:06.157Z' -> '2012-11-04 14:51:06:157'
return date.toISOString()
.replace(/[TZ]/g, ' ')
.replace(/\./g, ':')
.trim();
},
});

Expand Down Expand Up @@ -182,7 +185,7 @@ async function createTransports (args) {

async function init (args) {
// set de facto param passed to timestamp function
timeZone = args.localTimezone;
useLocalTimeZone = args.localTimezone;

// clean up in case we have initiated before since npmlog is a global object
clear();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"axios": "^0.21.0",
"bluebird": "3.x",
"continuation-local-storage": "3.x",
"dateformat": "^3.0.3",
"find-root": "^1.1.0",
"lodash": "^4.17.11",
"longjohn": "^0.2.12",
Expand Down

0 comments on commit 8ed7bae

Please sign in to comment.