npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notera-transport-terminal

v0.1.2

Published

Terminal transport for Notera

Downloads

4

Readme

Notera Terminal Transport

This package provides a customizable terminal transport for the Notera package. This transport atomically writes to stdout like console.log, which makes it ideal for development purposes.

Build Status Coverage Status

Notera terminal output

Usage

Example usage with Notera:

const Notera = require('notera')
const noteraTransportTerminal = require('notera-transport-terminal')

const logger = new Notera()

logger.addTransport(noteraTransportTerminal({
  // Options
}))

// Use logger as usual
logger.ctx('SERVER').info('Something is up', { some: 'meta' })

Options

Terminology

  • Segment - Each logging line can be divided into segments, for example time, ctx, msg, level, meta, err.
  • Entry - A logging entry generated by a call to one of the log functions in the Notera package.
interface Options {
  // Disable colored/styled output. Defaults to false
  disableStyle?: bool;

  // Never use more than one line for one log entry. This will hide stack traces
  // when logging errors, and only show the message instead. Defaults to false
  singleLine?: bool;

  // Colors that the default style functions use. Please refer to the "Colors"
  // section for more info. Defaults to:
  // emerg:   red
  // alert:   magenta
  // crit:    red
  // err:     red
  // warning: yellow
  // notice:  white
  // info:    green
  // debug:   cyan
  colors?: [level: string]: Color;

  // Configuration used when handling each segment. Please see the section
  // "Configuring segments" for more information on how to configure these.
  segments?: [segmentName: string]: SegmentConfig;
}

interface SegmentConfig {
  // How this segment should be ordered amongst the other
  index: number;

  // Function to format the segment
  format?: (entry: NoteraLogEntry, opts: Options) => string;

  // Function to determine the color of this segment this specific log entry.
  // Use a simple string (Color) if you don't need dynamic coloring.
  style?: Color | (entry: NoteraLogEntry, opts: Options) => Color;
}

Configuring segments

The default print format and style like the image in the top of this readme, is accomplished with a configuration that looks like this:

{
  disableStyle: false,
  singleLine: false,
  colors: {
    emerg: 'red',
    alert: 'magenta',
    crit: 'red',
    err: 'red',
    warning: 'yellow',
    notice: 'white',
    info: 'green',
    debug: 'cyan'
  },
  segment: {
    time: {
      index: 10,
      format: _ => new Date().toISOString(),
      style: 'gray'
    },
    ctx: {
      index: 20,
      format: ({ ctx }) => ` [${ctx}]`
    },
    level: {
      index: 30,
      style: ({ level }, opts) => opts.colors[level],
      format: ({ level }) => ' ' + level.toUpperCase()
    },
    msg: {
      index: 40,
      format: ({ msg }) => `: ${msg}`
    },
    err: {
      index: 50,
      format: ({ err }, opts) => ` | ${opts.singleLine ? err.message : err.stack}`,
      style: 'red'
    },
    meta: {
      index: 60,
      format: ({ meta }, opts) =>
        ` | ${JSON.stringify(meta, ...(opts.singleLine ? [] : [null, 2]))}`,
      style: 'gray'
    }
  }
}

Changing a segment

To change segment settings, you can simply overwrite them. Note that the settings will be merged with the default settings at feature-level. See the configuration examples below.

const config = {
  // ...
  segment: {
    ctx: {
      // Turns off formatting for the 'ctx' segment. Resulting in a simple
      // append from the previous segment.
      format: null,

      // Reset the default style of the 'ctx' segment
      style: null,

      // Reorder the 'ctx' segment to be placed after all other segments
      index: 100
    },
  }
}

Adding a custom segment

You can add totally custom segment that are evaluated on every log entry. Example:

const config = {
  // ...
  segment: {
    // Include the current memory usage in each log entry
    memory: {
      index: 15,
      format: () => ` MEM ${Math.round(os.freemem() / 1024 / 1024)} MiB`
    }
  }
}

Disable a segment

To disable a segment you can set the segment config to null:

const config = {
  // ...
  segment: {
    ctx: null
  }
}

Colors

This package is using ansi-styles under the hood to colorize the terminal output. Please refer to their readme to see what colors are available.

Installation

  • npm install notera-transport-terminal
  • yarn add notera-transport-terminal