instead of relying on a function (enableLogging) that depends on a kite being an EventEmitter instance, create a new KiteLogger class and allow logger option to be passed while creating a kite:
a logger will use console.error, console.warn, console.info as its handlers if any of them is not being passed
const logger = new Logger({name: 'foo'})
logger.critical('message is here, hello world')
// => [foo] CRITICAL message is here, hello world
a logger will expose 6 methods in which the passed handlers are being used:
logger.critical(...args): void -> handlers.error
logger.error(...args): void -> handlers.error
logger.warning(...args): void -> handlers.warn
logger.notice(...args): void -> handlers.info
logger.info(...args): void -> handlers.info
logger.debug(...args): void -> handlers.info
a logger will accept a level option while it's being created which will be used to decide when one of the methods are gonna produce logs (each method has its own DebugLevel associated with it)
instead of relying on a function (
enableLogging
) that depends on a kite being anEventEmitter
instance, create a newKiteLogger
class and allowlogger
option to be passed while creating a kite:a logger will use
console.error
,console.warn
,console.info
as its handlers if any of them is not being passeda logger will expose 6 methods in which the passed
handlers
are being used:logger.critical(...args): void
-> handlers.errorlogger.error(...args): void
-> handlers.errorlogger.warning(...args): void
-> handlers.warnlogger.notice(...args): void
-> handlers.infologger.info(...args): void
-> handlers.infologger.debug(...args): void
-> handlers.infoa logger will accept a
level
option while it's being created which will be used to decide when one of the methods are gonna produce logs (each method has its ownDebugLevel
associated with it)DebugLevel
s available:DebugLevel.DEBUG
which is0
:DebugLevel.CRITICAL
is lower or equal to 0.logger.debug('Hello world - debug') // DebugLevel.DEBUG == 5 logger.warn('Hello world - warn') // DebugLevel.WARNING == 2 logger.critical('Hello world - critical') // DebugLevel.CRITICAL == 0 // => [kite] CRITICAL Hello world - critical