mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2026-04-21 15:32:40 +02:00
Configure timezone with TZ env var. Resolves #109
This commit is contained in:
21
src/log.ts
21
src/log.ts
@@ -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}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user