This commit is contained in:
2026-01-24 14:00:49 -03:00
parent 7a4d94fbc4
commit 275a7600a3
6 changed files with 108 additions and 1 deletions

37
src/logger.ts Normal file
View File

@@ -0,0 +1,37 @@
import { appendFileSync, existsSync } from 'fs';
import { createWriteStream } from 'fs';
const filename = 'logs.csv',
exist = existsSync(filename);
console.log(filename, exist);
if (!exist) {
appendFileSync(filename, ['Date', 'Method', 'Url', 'Status'].join(',') + '\n', 'utf8');
}
export const log = (method: string, url: string, status: number) => {
appendFileSync(filename, [isoDateInTimeZone(), method, url, status].join(',') + '\n', 'utf8');
}
function isoDateInTimeZone(timeZone = 'America/Buenos_Aires', date = new Date()) {
const parts = new Intl.DateTimeFormat("en-CA", {
timeZone,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 3,
hour12: false,
timeZoneName: "shortOffset",
}).formatToParts(date),
map = Object.fromEntries(parts.map(p => [p.type, p.value])),
offset = map.timeZoneName.replace("GMT", "");
return `${map.year}-${map.month}-${map.day}T` +
`${map.hour}:${map.minute}:${map.second}.` +
`${map.fractionalSecond}${offset}`;
}