Configure timezone with TZ env var. Resolves #109

This commit is contained in:
ngosang
2021-05-30 11:28:43 +02:00
parent 10f8b83e83
commit 05f8ef95d9
3 changed files with 23 additions and 2 deletions

View File

@@ -2,6 +2,25 @@ let requests = 0
const LOG_HTML: boolean = process.env.LOG_HTML == 'true';
function toIsoString(date: Date) {
// this function fixes Date.toISOString() adding timezone
let tzo = -date.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function(num: number) {
let norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};
return date.getFullYear() +
'-' + pad(date.getMonth() + 1) +
'-' + pad(date.getDate()) +
'T' + pad(date.getHours()) +
':' + pad(date.getMinutes()) +
':' + pad(date.getSeconds()) +
dif + pad(tzo / 60) +
':' + pad(tzo % 60);
}
export default {
incRequests: () => { requests++ },
html(html: string) {
@@ -12,7 +31,7 @@ export default {
{level: process.env.LOG_LEVEL || 'info',
prefix(level: string) {
const req = (requests > 0) ? ` REQ-${requests}` : '';
return `${new Date().toISOString()} ${level.toUpperCase()}${req}`
return `${toIsoString(new Date())} ${level.toUpperCase()}${req}`
}
}
)