node-trailer

Logger built with middlewares.

Usage no npm install needed!

<script type="module">
  import nodeTrailer from 'https://cdn.skypack.dev/node-trailer';
</script>

README

node-trailer

npm

A logger built with middleware, based on trough.

  • Create a logger without middlewares will use the default theme;
  • Create a customize logger with middlewares.
    • There are 3 types middleware:
      • Filter decide what can be handle by next middleware;
      • Appender render different part of message as a log;
      • Output use appenders generating the log and send it to different place.

Preview

Installation

Install using npm:

npm i -P node-trailer

Usage

Basic usage:

import createLogger from "node-trailer"

const logger = createLogger({ level: 'info' })
logger.log('log message.') // No output
logger.info('info message.') //=> info message.

Customize:

const pipeline = trough()
  // Filter
  .use(filter(({ options, level }: LoggerContext) =>
    levelWeight[options.level] <= levelWeight[level]
  ))
  // Appender
  .use(level(levelColor))
  .use(message())
  .use(error())
  // Output
  .use(colorConsole())

const logger = createLogger({}, pipeline)

API Reference

Tests

Run tests using npm test.

Contributing

Please submit all issues and pull requests to the plylrnsdy/node-trailer repository!

Support

If you have any problem or suggestion please open an issue here.