nest-logger 1.0.0-pr254.8
Install from the command line:
Learn more about npm packages
$ npm install @shiftcode/nest-logger@1.0.0-pr254.8
Install via package.json:
"@shiftcode/nest-logger": "1.0.0-pr254.8"
About this version
🎯 Target runtime: es2023 (Node >= 20)
This package provides @shiftcode/logger support for NestJS, allowing you to inject loggers with context-aware naming and configure log transports using the NestJS DI system.
- Auto-named logger instances per class
- Supports multiple log transports
- Logger service injection for custom logger creation
import { Module } from '@nestjs/common'
import { LoggerModule } from '@shiftcode/nest-logger'
import { LogLevel, NodeConsoleLogTransport, NodeConsoleLogTransportConfig } from '@shiftcode/logger'
@Module({
imports: [
// Bind transports (you can bind multiple)
LoggerModule.withTransports([
{
transportClass: NodeConsoleLogTransport,
config: { logLevel: LogLevel.DEBUG },
},
]),
],
})
export class AppModule {}Option A: Directly inject the logger (auto-named)
import { Injectable, Inject } from '@nestjs/common'
import { Logger } from '@shiftcode/logger'
@Injectable()
class MyService {
constructor(@Inject(Logger) private logger: Logger) {
this.logger.info('Initialized!')
}
}Option B: Inject the logger service for custom naming
import { Injectable, Inject } from '@nestjs/common'
import { LoggerService } from '@shiftcode/nest-logger'
@Injectable()
class MyService {
constructor(@Inject(LoggerService) private loggerService: LoggerService) {
const logger = this.loggerService.getInstance('CustomService')
logger.debug('Custom-named logger')
}
}You can also pass a NestLogger to the NestApplication in a bootstrap function
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { LoggerService } from '@shiftcode/nest-logger'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const loggerService = app.get(LoggerService)
app.useLogger(loggerService.getInstanceNest('MyService'))
await app.listen(3000)
}Details
- nest-logger
-
shiftcode
- 3 months ago
- MIT
- 5 dependencies
Assets
- nest-logger-1.0.0-pr254.8.tgz
Download activity
- Total downloads 0
- Last 30 days 0
- Last week 0
- Today 0