@prommoto/execution-trace-logger
v0.1.6
Published
<h2>install</h2> <p>npm i @prommoto/execution-trace-logger</p>
Downloads
9
Keywords
Readme
- import LoggerModule into app module and provide winston transport instance in LoggerModule configuration using forRootAsync method to add LoggerService into nest IoC system.
import * as CloudWatchTransport from 'winston-cloudwatch';
import { CloudWatchLogs } from 'aws-sdk';
import { LoggerModule } from '../logger';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
LoggerModule.forRootAsync({
inject: [],
imports: [],
useFactory: () => {
return new CloudWatchTransport({
cloudWatchLogs: new CloudWatchLogs({
apiVersion: '2014-03-28',
region: 'aws-region',
credentials: {
accessKeyId: 'aws-access-key-id',
secretAccessKey: 'aws-secret-key-id',
},
}),
logGroupName: 'myLoggerGroup',
logStreamName: 'myLoggerStream',
});
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
- connect traceMiddleware to application module for request tracing.
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(traceMiddleware).forRoutes('*');
}
}
use LogFunctionIO decorator on class methods where you want to log function arguments and return values.
import { Controller, Post } from '@nestjs/common';
import { ApiResponse } from '@nestjs/swagger';
import { AppService } from './app.service';
import { LogFunctionIO } from '../logger';
import { CreateResourceDto } from './dto/create-resource.dto';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@LogFunctionIO()
@Post()
@ApiResponse({ type: CreateResourceDto })
public async getHello(): Promise<CreateResourceDto> {
return new CreateResourceDto();
}
}