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

log2

v0.1.1

Published

Customisable logger where most things are optional.

Downloads

140

Readme

Log2 - Customisable logger where most things are optional.

Log2

Unfortunately loggers are very personal and people like what they like. I like this one. You might too.

Log Creation

var log2 = require('log2');

# options
var log = log2();
var logWithFilename = log2({ filename : __filename });
var logWithProcessInfo = log2({ title : true, pid : true, hostname : true });
var logToStream = log2({ stream : fs.createWriteStream('filename.log') });

Log Functions

# log() is the same as log.info()
log('This is a log message, which defaults to info');

# levels
log.debug('Used for Debugging');
log.info('Regularly info messages');
log.warn('Let the user know that something needs looking at');
log.error('Interestingly, somewhere went wrong');
log.fatal('Something went badly wrong');

Example Outputs

# simple line, just log.info()
2013-03-29T03:15:32.458Z -  INFO: This is a log message, which defaults to info

# this line has an ID
2013-03-29T03:15:32.458Z - (259)  INFO: This is a log message, which defaults to info

# this line shows the program title, pid and hostname
2013-03-29T03:45:23.811Z -  INFO: {test-log2/16982@cheetah} Same level as the line above

# this shows the filename and method
2013-03-29T03:45:23.812Z -  INFO: [/home/chilts/src/chilts-log2/examples/t2.js::start] Same level as the line above

# this shows an id, program title, pid, hostname, filename and method
2013-03-29T03:45:23.812Z - (804)  INFO: {test-log2/20795@cheetah} [/home/chilts/src/chilts-log2/examples/t2.js::start] Same level as the line above

General Format

timestamp - (id) LEVEL: {title/pid@hostname} [filename::method] Message

If anything in the group is not wanted, then the rest of the group still shows. e.g. {title@hostname} even if the pid isn't required. However, if none of title, pid and hostname is required, the braces also get left out.

Options

timestamp

Default: true

Whether to show or not show the timestamp of the log.

stream

Default: process.stdout

The stream to output messages to. Must have a .write() method.

filename

Pass in the current filename so you can log it too. e.g.

var log = log2({ filename : __filename });

method

Pass in the current method so you can log it too. e.g.

var log = log2({ method : 'makeServer' });

id

Pass in an 'id' so we can see which log lines relate to others. e.g. usually used with things like connect-flake or connect-uuid to attach an ID to a request.

app.use(connectFlake());
app.use(function(req, res, next) {
    req.log = log2({ id : req.flake });
    req.log('This is an info message with a unique ID for this request');
    next();
});

title

Default: false

Shows the process.title.

pid

Default: false

Shows the process.pid.

hostname

Default: false

Shows the hostname the program is running on.

Author

Written by Andrew Chilton - Blog - Twitter.

License

(Ends)