Nestjs module for logging based on winston
Following packages should be installed before
yarn add @qiwi/nestjs-enterprise-logger
Import
import {
LoggerModule,
createMetaPipe,
maskerLoggerPipeFactory,
} from '@qiwi/nestjs-enterprise-logger'
@Module({
imports: [
ConfigModule,
LoggerModule.register(createMetaPipe(), maskerLoggerPipeFactory()),
// and so on
]
})
export class AppModule {}
@Injectable()
class MyService {
constructor(@Inject('ILogger') private logger: ILogger) {}
myError() {
this.logger.error('foo')
}
myInfo() {
this.logger.info('foo')
}
}
For createMetaPipe
import {
logger as log,
} from '@qiwi/nestjs-enterprise-logger'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const logger = app.get('ILogger')
app
.use(log({ logger }))
.useLogger(logger)
//...
logger.info()
You can inject functions of type TLoggerPipe
as your own pipes when create LoggerService
or register LoggerModule
.
Your pipes will be inserted in the following order:
mdc
pipe from @qiwi/logwrap
;app
pipe (adds app name, app version and os info to log entry);logger
pipe (prints log entry).Exports LoggerService
with token ILogger
field | type | description |
---|---|---|
LogEntry.meta | Record<string, any> | Metadata |
LogEntry.level | ERROR | WARN | INFO | DEBUG | TRACE | Log level |
LogEntry.input | any[] | Data |
Creates pipe for metadata injection, used with @qiwi-private/js-platform-mdc-nestjs
Creates pipe for pan masking
Masks pans