@code-like-a-carpenter/logger
TypeScript icon, indicating that this package has built-in type declarations

2.4.0 • Public • Published

@code-like-a-carpenter/logger

standard-readme compliant

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

  1. always writes JSON
  2. 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

Ian Remmel

Contributing

Please see contributing guidelines at the project homepage.

License

MIT © Ian Remmel 2023 until at least now

Readme

Keywords

none

Package Sidebar

Install

npm i @code-like-a-carpenter/logger

Weekly Downloads

76

Version

2.4.0

License

MIT

Unpacked Size

77.9 kB

Total Files

35

Last publish

Collaborators

  • ianwremmel