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

winston-format-debug

v1.4.0

Published

Debug formatter for Winston

Downloads

3,503

Readme

winston-format-debug

NPM version Build Status Coverage Status semantic-release Greenkeeper badge

What is it?

This is a format for console logging for winston > 3.x.x. It's based loosely on bunyan-debug-stream.

Usage

import winston from 'winston';
import debugFormat from 'winston-format-debug';

const logger = winston.createLogger({
  levels: winston.config.syslog.levels,
  level: 'info',
  transports: [
    new winston.transports.Console({
      format: winston.format.combine(
        debugFormat({
          levels: winston.config.syslog.levels,
          colors: winston.config.syslog.colors,
        })
      ),
    }),
  ],
});

Options

processName

The name of the process. If not specified, winston-format-debugger will attempt to figure this out from process.argv. If specified as an empty string, the process name will be hidden in the output.

levels

A hash where keys are level names, and values are level numbers. This is the same levels you pass to winston.createLogger({levels}). If not specified, defaults to winston.config.npm.levels.

colors

Colors to use to colorize things. You can also set colors to false to disable all colors. If not specified, defaults to winston.config.npm.colors. You can specify any color from the Winston colors, or any of the standard colors or modifiers from chalk, as well as hex codes.

showPID

Defaults to true. If false, the PID will not be shown in the output.

skip

By default, winston-format-debug will print all values in your Winston log as JSON objects (except Errors, which will be transformed into stack traces). If there are specific values you do not want to print, you can skip them with skip. This can be either an array of property names, or a fn(key, value): boolean that returns true if a property name should be skipped.

For example, the object {message: "Hello World", foo: {bar: 7}} would normally be printed as:

Nov 3 14:42:12 test[69138] INFO:    Hello world!
    foo: {bar: 7}

If you pass skip: ["foo"], then the "foo" field would not be printed. Note that 'level', 'message', '@timestamp', and 'name' are always skipped.

colorizePrefix, colorizeMessage, colorizeValues

winston-format-debug logs a message that looks something like this:

Jun 28 20:55:16 process[7998] INFO: Hello world
    otherValue: "hello"

colorizePrefix controls whether or not the date, process name, and PID are colorized (defaults to false). colorizeMessage controls the text of the message (defaults to true). colorizeValues controls wether non-message values are colorized (defaults to true).

These options are all ignored unless the colors option is passed in.

basePath

This is the root of your project. This is used to strip prefixes from filenames, in stack traces, and to decide which files are part of "your code" and which are not.

indent

Set the indent size. Defaults to 4.

maxExceptionLines

The maximum number of lines to show in a stack trace. If not specified, defaults to unlimited.

terminalWidth

The maximum width to print for values (other than message).

Any "extra values" in the info object from winston will be printed, but each (aside from errors) are truncated to a single line. If specified, this is the width to truncate to. In a TTY, defaults to process.stdout.columns. Otherwise, defaults to 80.

Special fields

  • level, message - Defined by winston.
  • @timestamp - If present, this will be ignored.
  • name - Assumed to be the logger name. This will be printed along with the process name.

Prefixers and Stringifiers

bunyan-debug-stream has support for "prefixers" and "stringifiers" which can be used to customize the log output. These are not required in Winston, though, as you can easily write a format which edits your data. For example, if you had an accountName field, you could do the same as a prefixer with:

import winston from 'winston';

const accountPrefixer = winston.format((info) => {
  info.message = `[${info.account}] ${info.message}`;
  return info;
});

const logger = winston.createLogger({
  transports: [
    new winston.transports.Console({
      format: winston.format.combine(accountPrefixer(), debugFormat({ skip: ['account'] })),
    }),
  ],
});