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

log-defer

v1.0.1

Published

Generate log object compatible with log-defer-viz, https://github.com/hoytech/Log-Defer-Viz

Downloads

741

Readme

log-defer

Unit Tests codecov

Description

Generate log object compatible with log-defer-viz

log-defer is a module that creates structured logs. The log-defer documentation explains structured logging and its benefits over ad-hoc logging.

This is the javascript implementation, full documentation for log-defer can be found at https://metacpan.org/pod/Log::Defer

Installation

npm install log-defer

or

bower install log-defer

Synopsis

'use strict';

var log = require('log-defer');
var process = require('process');

log.timer('Log Messages'); // begin a timer called 'Log Messages'
log.info('Info level logging');
log.warn('Warn level logging');
log.error('Error level logging');
log.debug('Debug level logging');
log.timer('Log Messages'); // end the 'Log Messages' timer
log.data({ bar: 'baz', foo: 'bar' }); // add to the data object in the log-defer

log.warn('Warning with data!', { bar: 'baz', foo: 'bar' }, { barbaz: 'bazfoo', foobar: 'barbaz' });

var output = log.finalizeLog(); // finalize the log, and return a json string of the log-defer

process.stdout.write(output);

The above code should produce the following output:

{"data":{"bar":"baz","foo":"bar"},"logs":[[0.0009999275207519531,30,"Info level logging"],[0.0009999275207519531,20,"Warn level logging"],[0.0009999275207519531,10,"Error level logging"],[0.0009999275207519531,40,"Debug level logging"],[0.0009999275207519531,20,"Warning with data!",{"bar":"baz","foo":"bar","barbaz":"bazfoo","foobar":"barbaz"}]],"start":1457018806.914,"timers":[["Log Messages",0.0009999275207519531,0.0009999275207519531]],"end":0.0019998550415039062}

If viewed using the log-defer-viz cli then it would format as follows:

------ 2016-03-03 Thu 10:26:46.914 EST (1457018806.914) ------
  | 0.001000 [ INFO] Info level logging
  | 0.001000 [ WARN] Warn level logging
  | 0.001000 [ERROR] Error level logging
  | 0.001000 [DEBUG] Debug level logging
  | 0.001000 [ WARN] Warning with data! [{"foo":"bar","bar":"baz","foobar":"barbaz","barbaz":"bazfoo"}]
  |_0.002000 [END]

 Log Messages                                                                                  X
_______________________________________________________________________________________________________
times in ms                                                                                    1.0

  Data:
{
   "bar" : "baz",
   "foo" : "bar"
}