JSPM

  • Created
  • Published
  • Downloads 77
  • Score
    100M100P100Q76794F
  • License MIT

A very small, simple, opinionated, and structured logger for Typescript and Javascript.

Package Exports

  • jsout
  • jsout/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsout) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Logo

build status semantic-release Conventional Commits SemVer

A DevOps friendly, small, and simple logger for Typescript/Javascript projects. Sponsored by Aeroview.

🔒 Structured Logs

  • Supports both human-readable CLI output and JSON output for log aggregation into services like sumologic, New Relic, DataDog, etc.

🛡 Defensive & Devops Friendly

  • Logs are enabled in production mode by default
  • Transport should be handled outside of the process via STDOUT and STDERR
  • Configuration should also be handled outside of the code
  • Simple configurations make it hard to mess up
  • Minimal dependencies

😃 Simple & Easy to Use

  • Automatic Error serialization
  • Out-of-the-box Typescript support
  • Nice human readable output

💪 Flexible & Powerful

  • Easily set configuration using simple CLI overrides
  • Simple and well-defined enough to build custom tooling around, such as custom error handling and logging pipelines.

Installation

npm i jsout

Example Usage

import {logger} from 'jsout';

logger.info('test message');
logger.fatal('oops!', new Error(), {foo: 'bar'})
logger.error('', new Error('test')); //infers "test" as message

Plugins

Configuration

Configuration is set through the CLI environment variables. By default, the logger is set to info level, json format, and verbose verbosity, which is recommended for production.

You can override these settings by setting the following environment variables before running your application.

For example, here is the recommended way to run your application locally:

LOG=debug LOG_FORMAT=human LOG_VERBOSITY=terse node /path/to/yourApp.js

LOG

Sets the log level. Any logs lower than this log level are ignored.

Possible values: "trace", "debug", "info", "warn", "error", "fatal"

Default: "info" (recommended for production)

LOG_FORMAT

Set the format for the output to either be human-readable (great for local development in the console), or JSON formatted (great for data aggregation on a server).

Possible values: "human", "json"

Default: "json" (recommended for production)

LOG_VERBOSITY

If verbose, extra metadata is appended to log.context. Example:

{
  "date": "2021-12-19T06:17:38.147Z",
  "pid": 71971,
  "ppid": 71970,
  "nodeVersion": "v16.13.0"
}

Possible values: "terse", "verbose"

Default: "verbose" (recommended for production)

API

For all of the following, please note:

  • error should be an actual Error object with stack traces. This is not enforced.
  • context should by any information not necessarily directly related to the error, ie. server request information, app component, configurations, etc. This is where the verbose metadata is appended (this will override anything in the context object).
  • data any object that might be useful to debug the error, or any pertinant information relating to the log message

logger.trace(message?: string, data?: any, context?: any)

Emits a log to stdout with a level of TRACE (10)

logger.debug(message?: string, data?: any, context?: any)

Emits a log to stdout with a level of DEBUG (20)

logger.info(message?: string, data?: any, context?: any)

Emits a log to stdout with a level of INFO (30)

logger.warn(message?: string, error?: any, data?: any, context?: any)

Emits a log to stderr with a level of WARN (40)

logger.error(message?: string, error?: any, data?: any, context?: any)

Emits a log to stderr with a level of ERROR (50)

logger.fatal(message?: string, error?: any, data?: any, context?: any)

Emits a log to stderr with a level of FATAL (60)

Support, Feedback, and Contributions

  • Star this repo if you like it!
  • Submit an issue with your problem, feature request or bug report
  • Issue a PR against main and request review. Make sure all tests pass and coverage is good.
  • Write about jsout in your blog, tweet about it, or share it with your friends!

Together we can make software more reliable and easier to maintain!

Sponsors

Logo

Aeroview is a developer-friendly, AI-powered observability platform that helps you monitor, troubleshoot, and optimize your applications. Get started for free at https://aeroview.io.