1
0
mirror of synced 2024-12-04 19:17:58 +01:00

add timestamp

This commit is contained in:
ghkkk090 2022-09-03 09:49:58 +07:00
parent bf568b864d
commit ab1ff0fbbd
2 changed files with 18 additions and 5 deletions

View File

@ -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();
})

View File

@ -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() + "]");
}