|
1 | 1 | import { Inject, Injectable, LoggerService, NestMiddleware } from '@nestjs/common';
|
2 |
| -import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; |
| 2 | +import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston'; |
3 | 3 | import { Request, Reply } from './interfaces';
|
| 4 | +import { FastifyRequest } from 'fastify'; |
4 | 5 |
|
5 | 6 | @Injectable()
|
6 | 7 | export class LoggerMiddleware implements NestMiddleware {
|
7 |
| - constructor(@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService) {} |
| 8 | + constructor( |
| 9 | + @Inject(WINSTON_MODULE_NEST_PROVIDER) |
| 10 | + private readonly logger: LoggerService, |
| 11 | + ) {} |
8 | 12 |
|
9 |
| - use(request: Request, reply: Reply, next: () => void) { |
| 13 | + use(request: any, reply: Reply, next: () => void) { |
10 | 14 | const { ip, method, headers, originalUrl } = request;
|
11 | 15 | const userAgent = headers['user-agent'] ?? '';
|
12 | 16 |
|
| 17 | + const ips = request.ips ? request.ips : []; |
| 18 | + |
13 | 19 | reply.on('finish', () => {
|
14 | 20 | const { statusCode } = reply;
|
15 |
| - const log = { method, originalUrl, statusCode, userAgent, ip }; |
| 21 | + const log = { method, originalUrl, statusCode, userAgent, ip, ips }; |
16 | 22 |
|
17 |
| - this.logger.log('Query', log); |
| 23 | + this.logger.log(JSON.stringify(log)); |
18 | 24 | });
|
19 | 25 |
|
20 | 26 | next();
|
|
0 commit comments