Add fluentd

This commit is contained in:
Fernando Gabriel Sarmiento Diaz 2022-11-09 14:59:04 +09:00
parent 3bca3ef072
commit f4d52fcd98
4 changed files with 26 additions and 1 deletions

11
lib/logger.js Normal file
View file

@ -0,0 +1,11 @@
import { FluentClient } from '@fluent-org/logger';
const logger = new FluentClient(process.env.FLUENT_TAG_PREFIX, {
socket: {
host: process.env.FLUENTD_HOST,
port: process.env.FLUENTD_PORT,
timeout: 3000, // 3 seconds
},
});
export default logger;

View file

@ -12,6 +12,7 @@ import {
LAPTOP_SCREEN_WIDTH,
MOBILE_SCREEN_WIDTH,
} from './constants';
import logger from './logger';
let lookup;
@ -75,7 +76,7 @@ export async function getCountry(req, ip) {
const result = lookup.get(ip);
console.log(JSON.stringify(result));
logger.emit('getCountry', { result });
return result?.country?.iso_code;
}