Logger

logger module for appolo build with pino

Installation#

npm i @appolo/logger

Options#

keyDescriptionTypeDefault
idlogger idstringlogger
levelbase log levelLog.Levelinfo
transportsoptional ICustomTransport arrayarraynull

in config/modules/all.ts

import {LoggerModule} from '@appolo/logger';
export = async function (app: App) {
await app.module.use(LoggerModule);
// or with custom transport
await app.module.load(LoggerModule.for({transports:[MyCustomTransport]}));
}
export class MyCustomTransport {
initialize(): Promise<void>{
}
log(level: Level, msg: string, args: PlainObject){
console.log(level,msg,args)
}
}

Usage#

now logger instance can be inject

import {ILogger} from '@appolo/logger';
@define()
export class SomeManager{
@inject() logger:Ilogger
someMethod(){
try{
this.logger.info("log something")
}catch(e){
this.logger.error("some error",{e,someParam:"aa"})
}
}
}

static logger

import {Logger} from '@appolo/logger';
@define()
export class SomeManager{
someMethod(){
try{
Logger.logger.info("log something")
}catch(e){
Logger.logger.error("some error",{e})
}
}
}

API#

error( msg: string, args: PlainObject)#

warn( msg: string, args: PlainObject)#

fatal( msg: string, args: PlainObject)#

info( msg: string, args: PlainObject)#

debug( msg: string, args: PlainObject)#