From ab1ff0fbbd0930e262c6fc4e69e48dfe2f0ff021 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sat, 3 Sep 2022 09:49:58 +0700 Subject: [PATCH] add timestamp --- src/index.ts | 12 ++++++++---- src/util/common.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index e31e15b..df3baad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import { Config } from './config'; import process from 'process'; import * as Sentry from '@sentry/node'; import * as Tracing from '@sentry/tracing'; +import * as common from './util/common'; import * as dotenv from "dotenv"; dotenv.config({path: __dirname + '/.env'}); @@ -53,23 +54,26 @@ if (useSentry) { const muchaApp = express(); const allnetApp = express(); +// Get the current timestamp +let timestamp: string = common.getTimeStamp(); + if (useSentry) { app.use(Sentry.Handlers.requestHandler()); app.use(Sentry.Handlers.tracingHandler()); } app.use((req, res, next) => { - console.log(`[ MAIN] ${req.method} ${req.url}`); + console.log(timestamp+` [ MAIN] ${req.method} ${req.url}`); next() }); muchaApp.use((req, res, next) => { - console.log(`[ MUCHA] ${req.method} ${req.url}`); + console.log(timestamp+` [ MUCHA] ${req.method} ${req.url}`); next() }); allnetApp.use((req, res, next) => { - console.log(`[ALLNET] ${req.method} ${req.url}`); + console.log(timestamp+` [ALLNET] ${req.method} ${req.url}`); next() }); @@ -97,7 +101,7 @@ app.use('/', appRouter); app.use('/wmmt6/', appRouter); app.all('*', (req, res) => { - console.log(`[ MAIN] ${req.method} ${req.url} is unhandled`); + console.log(timestamp+` [ MAIN] ${req.method} ${req.url} is unhandled`); res.status(200).end(); }) diff --git a/src/util/common.ts b/src/util/common.ts index 77c19bf..35b5dd9 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -48,6 +48,15 @@ export function sanitizeInput(value: any) return (value == null || value == undefined) ? undefined : value; } -export function sanitizeInputNotZero(value: any){ + +export function sanitizeInputNotZero(value: any) +{ return (value !== null && value !== undefined && value !== 0) ? value : undefined; +} + + +export function getTimeStamp(date: Date = new Date()) +{ + // Return a timestamp string for the current / provided time + return String("[" + date.toLocaleString() + "]"); } \ No newline at end of file