diff --git a/ts/nni_manager/common/log.ts b/ts/nni_manager/common/log.ts index bcb01145cb..8d54af85e3 100644 --- a/ts/nni_manager/common/log.ts +++ b/ts/nni_manager/common/log.ts @@ -75,15 +75,17 @@ export class Logger { return; } - // `time.toLocaleString('sv')` trick does not work for Windows - const isoTime = new Date(new Date().toLocaleString() + ' UTC').toISOString(); - const time = isoTime.slice(0, 10) + ' ' + isoTime.slice(11, 19); + const zeroPad = (num: number): string => num.toString().padStart(2, '0'); + const now = new Date(); + const date = now.getFullYear() + '-' + zeroPad(now.getMonth() + 1) + '-' + zeroPad(now.getDate()); + const time = zeroPad(now.getHours()) + ':' + zeroPad(now.getMinutes()) + ':' + zeroPad(now.getSeconds()); + const datetime = date + ' ' + time; const levelName = levelNames.has(level) ? levelNames.get(level) : level.toString(); const message = args.map(arg => (typeof arg === 'string' ? arg : util.inspect(arg))).join(' '); - const record = `[${time}] ${levelName} (${this.name}) ${message}\n`; + const record = `[${datetime}] ${levelName} (${this.name}) ${message}\n`; if (logFile === undefined) { console.log(record);