@we-are-singular/logger
v1.0.1
Published
A simple pinojs wrapper
Downloads
65
Readme
@we-are-singular/logger
This package provides a shared ESLint configuration for Singular projects.
Installation
npm install --save-dev @we-are-singular/logger
Usage
import { LoggerClass } from "@we-are-singular/logger"
const logger = new LoggerClass("MyApp", "Module", "Context")
logger.info("Hello, world!")
logger.error("Something went wrong!")
logger.withModule("AnotherModule").info("Hello, world!")
NestJS
override default logger:
import { LoggerService } from "@we-are-singular/logger"
// use forRoot() In main.ts
const app = await NestFactory.createApplicationContext(AppModule, {
logger: new LoggerService().withModule("AppModule").forRoot(),
})
auto context from module provider:
// use forFeature() In other modules
@Module({
imports: [],
controllers: [],
providers: [
//
LoggerService.forFeature("Services"),
],
exports: [
//
LoggerService,
],
})
export class ServicesModule {}
auto context:
// as a base class, adding a logger to all classes with a context of the class name
@Injectable()
export abstract class BaseClass {
readonly logger: LoggerService
constructor(
//
@Inject(LoggerService) logger: LoggerService
) {
this.logger = logger.withContext(this.constructor.name.toString())
}
}