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

12factor-log

v0.1.2

Published

Simple log infrastructure.

Downloads

23

Readme

12factor-log

A log module which only outputs to stdout. For Node.js that means using console.log().

This logger does not do hierarchical logging. It does not log to files, it doesn't log to external services. You should do that yourself.

However, this logger does log in JSON so you can log whatever you want in a structured way, and filter and format your logs yourself at a later date.

Synopsis

var log = require('12factor-log')({ name : 'example' })

log.info('Hello, World!')
log.info({ 'an': 'object' }, 'Some Data')

This outputs:

{"ts":"2014-06-04T00:40:35.842Z","msg":"Hello, World!","name":"example","type":"info","level":3,"hostname":"tiger","pid":12942}
{"ts":"2014-06-04T00:40:35.844Z","msg":"Some Data","name":"example","type":"info","level":3,"hostname":"tiger","pid":12942,"data":{"an":"object"}}

API

Firstly, create your logger object:

var Log = require('12factor-log')

// a regular logger at level 'info' and above
var logger = new Log({ name : 'mylog' })

// a logger at level 'debug'
var logger = new Log({ name : 'mylog', level : Log.debug })

// a logger which logs all levels
var logger = new Log({ name : 'an-all-logger', level : Log.all })

// a logger which logs nothing at all
var logger = new Log({ name : 'no-log', level : Log.none })

Once you have your logger, you can log at any level:

log.trace('This is a Trace Message')
log.debug('This is a Debug Message')
log.info('This is an Info Message')
log.warn('This is a Warn Message')
log.error('This is an Error Message')
log.fatal('This is a Fatal Message')

And you can log with a data object (which must come first):

log.trace({ a : 1 }, 'Trace')
log.debug({ a : 1 }, 'Debug')
log.info({ a : 1 }, 'Info')
log.warn({ a : 1 }, 'Warn')
log.error({ a : 1 }, 'Error')
log.fatal({ a : 1 }, 'Fatal')

Fields

+----------+----------------------------+--------------------------------------+
| Field    | Description                | From                                 |
+----------+----------------------------+--------------------------------------+
| hostname | hostname of this machine   | generated at startup                 |
| pid      | process id of this process | generated at startup                 |
| name     | the name of this logger    | provided at logger instance creation |
| type     | message type (see below)   | set for each log line                |
| level    | numeric level (1-6)        | set for each log line                |
| ts       | the timestamp              | generated each log line              |
| msg      | the message iteself        | provided for each log line           |
| data     | any data to log            | for each log line (if provided)      |
+----------+----------------------------+--------------------------------------+

Log Levels

+-------+-------+
| Type  | Level |
+-------+-------+
| trace |   1   |
| debug |   2   |
| info  |   3   |
| warn  |   4   |
| error |   5   |
| fatal |   6   |
+-------+-------+

Note: In each log line both type and level are output and always correspond to each other.

Author

Written by Andrew Chilton - Blog - Twitter.

License

MIT - http://chilts.mit-license.org/2014/

(Ends)