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

winstonson

v2.1.0

Published

Simple logging wrapper around Winston - for Node.js

Downloads

5

Readme

winstonson (v1.0.0)

Simple logging wrapper around Winston for Node.js with support for Morgan middleware in Express.

npm install winstonson

Winstonson is an very simple, opinionated logging wrapper around the Winston logging library. It defines three different logs:

  • Console - prints output to the console
  • Error - writes error messages to an error.log file
  • Out - writes all logging messages to an out.log file

Usage

const logger = require('winstonson')(module);

Note the module in parentheses after requiring this library. This allows the resulting logger to output logging messages unique to the file in which it is required. Currently this means printing the filename of the JavaScript file that includes the logger, but additional metadata could be included in later versions.

Logging severities are shown below, in increasing order of severity:

  • debug
  • trace
  • info
  • warn
  • error You can set the level of the logger globally by using the logger.level('<level>') function.

You can utilize any one of the five common logging functions to output log messages:

logger.debug('I am a debug message!');
logger.trace('I am a trace message!');
logger.info('I am an informative message!');
logger.warn('I am a warning!');
logger.error('I am an error message! Something really bad happened!');

Use with Express and Morgan

Winstonson allows you to capture the output of the Morgan middleware in Express thorugh the use of the stream() function.

const express = require('express');
const morgan = require('morgan');
const logger = require('winstonson')(module);
const app = express();

app.use(morgan('tiny', { stream: logger.stream('trace')}));

// Additional Express code |
// ...                     V

The provided level determines at what level the messages should be logged and corresponds to the Winstonson level set using level(). The output from Morgan will be located in the message portion of the log output (see below).

You can trace an HTTP request when it comes in and leaves by using Morgan in the following way:

app.use(morgan('---> :remote-addr :remote-user ":method :url HTTP/:http-version"', { 
    immediate: true, 
    stream: logger.stream('trace')
}));
app.use(morgan('<--- :method :url :status :res[content-length]', { 
    immediate: false, 
    stream: logger.stream('trace')
}));

Log Message Format

Currently the log message format is static, but this will change in future versions. An example of the default format is provided below:

# level: timestamp [file] (code) message
verbose: 1545878224449 [example.js]  (100) Hello, world!

The code is defined on the Error object passed to the logger.error() function. If no code is defined, the code will simply be omitted from the output.

You can also mute/unmute output to the console with the logger.mute() and logger.unmute() functions respectively.