diff --git a/README.md b/README.md index 3c1a6eb..9134bcd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # trace.js -Javascript logging library + +Javascript logging library better than use ordinary `console.log(...)` logging, partially compatible with my C++ TRACE macros/module. diff --git a/src/trace.js b/src/trace.js index 982be6e..5fa0e1b 100644 --- a/src/trace.js +++ b/src/trace.js @@ -29,7 +29,11 @@ const ENABLED_MODULES = window.ENABLED_MODULES || []; function getTimestamp() { - return new Date().toISOString(); + const now = new Date(); + const offset = -now.getTimezoneOffset(); + const pad = num => String(num).padStart(2, '0'); + + return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}T${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}.${String(now.getMilliseconds()).padStart(3, '0')}${offset >= 0 ? '+' : '-'}${pad(Math.floor(Math.abs(offset) / 60))}:${pad(Math.abs(offset) % 60)}`; } function getCurrentScriptName() {