A logger module for Nest.
Wrap standard nestjs logger and add API for set level to runtime globally or for each logger
$ npm install @hhnest/logger --save
import {LoggerModule} from '@hhnest/logger';
import { LogLevel } from '@nestjs/common';
const initialLevels: LogLevel[] = ['error', 'warn', 'log', 'debug'];
...
@Module({
imports: [
HttpModule,
LoggerModule.forRoot(initialLevels),
// or
LoggerModule.forRoot(), // ['error', 'warn', 'log']
...
],
controllers: [...],
providers: [...],
})
export class AppModule {
...
}
import { Log } from '@hhnest/logger';
@Injectable()
export class MyService {
constructor(
@Log(MyService.name) private readonly logger
) {
}
method() {
this.logger.error(`message`)
}
...
}
/logger
/logger/level/(error|warn|log|debug|verbose|reset)
If specific logger has been set to another level, level of it doesn't change.
/logger/context/SpecificLogger
/logger/context/SpecificLogger/level/(error|warn|log|debug|verbose|reset)
If reset, remove specific and use global levels for it.
@hhnest/logger is MIT licensed.