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/terminal

v1.0.0

Published

Terminal transport for Notera

Downloads

5

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.

Notera terminal output

Installation

  • npm install @notera/core @notera/terminal
  • yarn add @notera/core @notera/terminal

Usage

import notera from '@notera/core';
import terminalTransport from '@notera/terminal;

const logger = notera({
    levels: {
        err: 0,
        info: 1,
    },
});

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

logger.ctx('SERVER').info('Something is up', { some: 'meta' });

Options

Terminology

  • Segment - Each logging line can be divided into segments: date, ctx, msg, level and meta.
  • Entry - A logging entry generated by a call to one of the log functions in the Notera package.
type Opts<LevelsT extends string> = {
	// Disable colored/styled output. Defaults to false
	disableStyle?: boolean;

	// 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?: boolean;

	// Colors to use for the different logging levels
	colors?: {
		[K in LevelsT]?: Style;
	};

	stream?: Writable;

	// Configuration used when handling each segment. Please see the
	// section "Configuring segments" for more information on how to
	// configure these.
	segment?: {
		time?: SegmentConfig<LevelsT>;
		ctx?: SegmentConfig<LevelsT>;
		level?: SegmentConfig<LevelsT>;
		msg?: SegmentConfig<LevelsT>;
		meta?: SegmentConfig<LevelsT>;
	};
};

type SegmentConfig<LevelsT extends string> = {
	// How this segment should be ordered amongst the other, defaults to 1
	index?: number;

	// Default false
	disabled?: boolean;

	// Function to format the segment
	format?: ((entry: LogEntry<LevelsT>, opts: Opts<LevelsT>) => string) | null;

	// Function to determine the style of this segment this specific log entry.
	style?:
		| Style
		| ((entry: LogEntry<LevelsT>, opts: Opts<LevelsT>) => Style)
		| null;
};

Configuring segments

Example configuration:

{
    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}`,
        },
        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,
        },
    },
};

Disable a segment

const config = {
    segment: {
        ctx: {
            disabled: true,
        },
    },
};

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.