@seas-computing/nestjs-logging
v0.1.0
Published
A log module that exports a log service, middleware, and interceptor.
Keywords
Readme
NestJS Logging
The nestjs-logging package provides a NestJS logging module that logs a reasonable set of messages by default but also provides a number of methods for logging in common use cases. The package uses the Winston logging library under the hood.
Usage
We must configure the log module by specifying a log level. To do this, we pass
in an argument of type WINSTON_LOG_LEVEL to the module's register method.
The register method also supports an object-based configuration.
In addition to the logLevel, you can optionally provide a loggerOptions field to
customize the underlying Winston logger for example, to enable structured JSON logging.
To set the log level to WINSTON_LOG_LEVEL.INFO, the AppModule, a consuming module,
would have an imports property in which the log level is passed in to the register
method like so:
@Module({
imports: [
LogModule.register({
logLevel: WINSTON_LOG_LEVEL.INFO,
loggerOptions: {
format: format.combine(
format.timestamp(),
format.json()
),
transports: [new transports.Console()],
}
})
],
controllers: [
UserController,
HealthCheckController,
],
providers: [],
})