@code-like-a-carpenter/logger
v2.4.0
Published
Light-weight, bunyan-inspired JavaScript logger
Downloads
107
Readme
@code-like-a-carpenter/logger
Light-weight, bunyan-inspired JavaScript logger
This is yet another logger. It takes inspiration from
bunyan and
lambda-log, but it's much
simpler. Where those libraries are designed to be used in a few different
scenarios with pluggable, configurable behaviors, this is mostly just a wrapper
around Console
that
- always writes JSON
- has a child` method inspired by bunyan to create sub-loggers.
To be clear, bunyan is an excellent library, but a significant portion of its code is dedicated to writing log output somewhere other than STDOUT, which is all we really care about in most cases and especially in Lambda deployments.
LambdaLog has some nice ideas about targeting just Lambda, but it's got an awful lot of complex customization options and its leveled log methods don't appear to be discoverable by TypeScript.
Table of Contents
Install
npm i @code-like-a-carpenter/logger
Usage
Get the default logger
import {logger} from '@code-like-a-carpenter/logger';
Log a message
import {logger} from '@code-like-a-carpenter/logger';
logger.info('hello world');
Log a message with additional info
import {logger} from '@code-like-a-carpenter/logger';
logger.info('hello world', {foo: 'bar'});
Create a new logger instance
import {ConsoleLogger} from '@code-like-a-carpenter/logger';
const logger = new ConsoleLogger();
Create a new logger instance in dev mode
dev mode implies pretty-printed JSON.
import {ConsoleLogger} from '@code-like-a-carpenter/logger';
const logger = new ConsoleLogger({dev: true});
Create a new logger instance in prod mode
prod mode implies single-line JSON.
import {ConsoleLogger} from '@code-like-a-carpenter/logger';
const logger = new ConsoleLogger({dev: false});
Maintainer
Contributing
Please see contributing guidelines at the project homepage.
License
MIT © Ian Remmel 2023 until at least now