@chatally/logger
v0.0.9
Published
ChatAlly Logger Facade
Downloads
7
Maintainers
Readme
@chatally/logger
ChatAlly Logger Facade that can be used in libraries to use any logging framework without introducing any dependencies.
The facade can be easily implemented with popular frameworks like Pino, Winston or log4js.
The main interface of the facade is Logger
, it supports typical log methods (trace, debug, info, warn, error), logging of messages, format strings and data objects including errors, and creating named child loggers.
The package contains two default implementations: BaseLogger
and NoLogger
.
This package is meant to be used within a ChatAlly chatbot application, but could be used anywhere.
Usage
Install the package
npm install @chatally/logger
Use the logger
// index.js
import { BaseLogger } from '@chatally/logger'
class MyClass {
/** @param {import('@chatally/logger').Logger} log */
constructor(log) {
this.log = log
}
doSomething() {
this.log.debug('I am about to do something')
// do something
this.log.info('Just did something.')
}
}
const log = new BaseLogger({ name: 'foo' })
const foo = new MyClass(log)
// with the default settings from BaseLogger, it logs
// [<timestamp>] INFO (foo): Just did something.
foo.doSomething()
Documentation
Find the full documentation at https://chatally.org/reference/core/logger/.