Tslog integration for Nestjs
npm install nestjs-tslog tslogImport TsLogModule into the root AppModule and use the forRoot() method to configure it.
import { Module } from '@nestjs/common';
import { TslogModule } from 'nestjs-tslog';
@Module({
imports: [
TslogModule.forRoot({
// options
}),
],
})
export class AppModule {}Or you can choose async configuration and use the forRootAsync() method to configure it.
import { Module } from '@nestjs/common';
import { TslogModule } from 'nestjs-tslog';
@Module({
imports: [
TslogModule.forRootAsync({
useFactory: async () => {
return {
// options
};
},
}),
],
})
export class AppModule {}Afterward, the tslog instance will be available to inject across entire project (and in your feature modules, being TslogModule a global one) using the InjectTsLogger injection decorator:
import { Controller, Inject } from '@nestjs/common';
import { InjectTsLogger } from 'nestjs-tslog';
import type { Logger } from 'tslog';
@Controller('example')
export class ExampleController {
constructor(@InjectTsLogger() private readonly logger: Logger) { }
}Or you can replace default Nest Logger:
import { TslogLogger } from 'nestjs-tslog';
// ...
const app = await NestFactory.create(AppModule, { bufferLogs: true });
app.useLogger(app.get(TslogLogger));
// ...npm run testPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is MIT licensed.