@dise/logger
v0.0.2
Published
A TypeScript logging utility based on the "debug" package, meant to replace "console.log"
Downloads
56
Keywords
Readme
README
@dise/logger is a small library and interface that wraps the debug package and provides a clean, standard logging API.
The interface
This library exposes a Logger interface that could be implemented for a variety of logging utils. At its core are the standard log levels:
- trace
- debug
- info
- warn
- error
- fatal
There's a scope method that allows you to specify which module you're in.
The implementation
The default implementation is available as DebugLogger, and wraps the debug package. Aside from the expressive API, the main feature is that it wires the outputs to stdout and stderr using console.info(), console.debug(), and console.warn().
How do I get set up?
1. Install the package as normal.
npm install @dise/logger2. Import the Logger instance and scope it to your module/function
import { Logger } from '@dise/logger';
const logger = Logger.scope('my-module');
function performTask() {
const localLogger = logger.scope('performTask');
}3. Go ahead and write some logs like you would with debug.
import { Logger } from '@dise/logger';
const logger = Logger.scope('my-module');
logger.info('Starting up...');
function performTask() {
const localLogger = logger.scope('performTask');
/* ... */
localLogger.fatal('Lethal dose of stage fright: %O', error);
}4. Run your app with a DEBUG env
$ export DEBUG=dise:*
$ tsc
$ node src/index.js
> dise:my-module:info "Starting up..."
> dise:my-module:performTask:fatal "Lethal dose of stage fright: { statusCode: 404 }"
TBA: Contribution guidelines
- Writing tests
- Code review
- Other guidelines
