forked from nathydre21/nepa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
30 lines (26 loc) · 906 Bytes
/
logger.ts
File metadata and controls
30 lines (26 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Request, Response, NextFunction } from 'express';
export const requestLogger = (req: Request, res: Response, next: NextFunction) => {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
console.log(
`[${new Date().toISOString()}] ${req.method} ${req.originalUrl} ${res.statusCode} - ${duration}ms - IP: ${req.ip}`
);
});
next();
};
// Simple logger instance for application logging
export const logger = {
info: (message: string) => {
console.log(`[${new Date().toISOString()}] INFO: ${message}`);
},
error: (message: string) => {
console.error(`[${new Date().toISOString()}] ERROR: ${message}`);
},
warn: (message: string) => {
console.warn(`[${new Date().toISOString()}] WARN: ${message}`);
},
debug: (message: string) => {
console.debug(`[${new Date().toISOString()}] DEBUG: ${message}`);
},
};