@rjavlonn/custom-logger
v1.0.1
Published
Custom logger for Nest.js service
Readme
Nest Logger
Implicity flavored logger for Nest.js service
Install
npm install --save @rjavlonn/custom-logger
Usage
Nest.js logger: main.ts
import { Logger } from '@rjavlonn/custom-logger';
const serviceLogger = new Logger();
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: serviceLogger
});
await app.listen(process.env.SERVICE_PORT);
}
bootstrap()
.catch((e) => {
serviceLogger.handleError(e);
process.exit(1);
});
Route logger: app.module.ts
import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggingInterceptor } from '@rjavlonn/custom-logger';
@Module({
imports: [],
controllers: [],
providers: [{
provide: APP_INTERCEPTOR,
useClass: LoggingInterceptor }]
})
export class AppModule {}
Using the static instance:
import { Logger } from '@rjavlonn/custom-logger';
Logger.info('This is a log message');
Logger.info({
message: 'This is a log message with meta !',
meta: 'toto',
context: 'MyController'
});
Instancing a logger instance:
import { Logger } from '@rjavlonn/custom-logger';
const myLoggerWithMeta = new Logger({
myMeta: 'lol'
});
myLoggerWithMeta.info('This is a log message');
myLoggerWithMeta.info({
message: 'This is a log message with meta !',
meta: 'toto',
context: 'MyController'
});