ignore, logs
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
# ---> Node
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs.csv
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ import { log } from "./logger.js"
|
|||||||
|
|
||||||
export async function ubicacion(lugar: string, limit = '1') {
|
export async function ubicacion(lugar: string, limit = '1') {
|
||||||
const response = await fetch(`${process.env.WEATHER_URL}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${process.env.WEATHER_API_KEY}`)
|
const response = await fetch(`${process.env.WEATHER_URL}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${process.env.WEATHER_API_KEY}`)
|
||||||
log('GET', response.url, response.status)
|
log('GET', response)
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,13 @@ const filename = 'logs.csv',
|
|||||||
|
|
||||||
console.log(filename, fileExist);
|
console.log(filename, fileExist);
|
||||||
|
|
||||||
if (!fileExist) appendFileSync(filename, ['Date', 'Method', 'Url', 'Status'].join(',') + '\n', 'utf8');
|
if (!fileExist) appendFileSync(filename, ['Date', 'Method', 'Domain', 'Path', 'Status'].join(',') + '\n', 'utf8');
|
||||||
|
|
||||||
export const log = (method: string, url: string, status: number) => {
|
export const log = (method: string, response: Response) => {
|
||||||
appendFileSync(filename, [isoDateInTimeZone(), method, url, status].join(',') + '\n', 'utf8');
|
const { url, status } = response,
|
||||||
}
|
{ host, pathname } = new URL(url);
|
||||||
|
appendFileSync(filename, [isoDateInTimeZone(), method, host, pathname, status].join(',') + '\n', 'utf8');
|
||||||
|
};
|
||||||
|
|
||||||
function isoDateInTimeZone(timeZone = 'America/Buenos_Aires', date = new Date()) {
|
function isoDateInTimeZone(timeZone = 'America/Buenos_Aires', date = new Date()) {
|
||||||
const parts = new Intl.DateTimeFormat("en-CA", {
|
const parts = new Intl.DateTimeFormat("en-CA", {
|
||||||
|
|||||||
Reference in New Issue
Block a user