fix: Properly format log timestamps
MODIFY
lib/logsink.js
lib/logsink.js
import npmlog from 'npmlog';
import { createLogger, format, transports } from 'winston';
import { fs, logger } from 'appium-support';
-import dateformat from 'dateformat';
import _ from 'lodash';
@@ -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);
- }
- return dateformat(date, 'yyyy-mm-dd HH:MM:ss:l');
+ if (useLocalTimeZone) {
+ date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
+ }
+ // '2012-11-04T14:51:06.157Z' -> '2012-11-04 14:51:06:157'
+ return date.toISOString()
+ .replace(/[TZ]/g, ' ')
+ .replace(/\./g, ':')
+ .trim();
},
});
@@ -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();

MODIFY
package.json
package.json
"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",

fix: Properly format log timestamps (#14889)