@tc-libs/http-log
v3.9.0
Published
Logging HTTP middleware/interceptor oriented.
Readme
@tc-libs/http-log
Logging HTTP middleware/interceptor oriented.
Il package copre due cose:
- middleware automatici che loggano richieste/risposte
LoggerServiceper salvare log HTTP strutturati su repository
Registrazione
HttpLogModule.register(
{
http: {
logReqParams: true,
logReqBody: true,
logResBody: false,
logHeaders: false,
writeIntoFile: true,
writeIntoConsole: true,
maxFiles: 14,
maxSize: '10M',
},
},
true,
);Middleware
Il modulo applica globalmente:
HttpLogResponseMiddlewareHttpLogMiddlewareHttpLogWriteIntoConsoleMiddlewareHttpLogWriteIntoFileMiddleware
Quindi basta importarlo per iniziare a raccogliere log HTTP.
Decorator Logger
Per log applicativi o endpoint-specific puoi usare:
@Logger('USER_CREATE')
@Post()
create() {}Il decorator aggancia LoggerInterceptor e salva metadata sull'azione.
LoggerService
Metodi principali:
info(dto)debug(dto)warn(dto)fatal(dto)raw(dto)
Esempio:
await this.loggerService.info({
action: 'USER_LOGIN',
description: 'Login success',
requestId,
method: 'POST',
path: '/auth/login',
statusCode: 200,
});Sviluppo
nx build http-log
nx test http-log