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

logger-switch

v3.0.1

Published

A simple library to turn ON/OFF logging activity, or enable only a few loggers or even enable/disable logging for a particular code etc."

Downloads

14

Readme

logger-switch

Nodejs library to turn ON/OFF logging and also deactivate/activate logging only in a particular peice of code, or use your own logger etc.

Installation

npm install logger-switch --save

Usage

var Logger = require('logger-switch');

var logger = new Logger('Test');

logger.activate();
logger.timestamp('DD MMM YY, HH:mm a');

logger.log('hi' + ' Cavin', "how r u??");
//Test (12 Feb 17, 11:37 am): hi Cavin how r u??  

logger.deactivate();
logger.error('This will not be logger');
// This will not be printed

logger.activate();
logger.timestamp(null);
logger.log('this will not have timstamp')
//Prints: Test: this will not have timstamp

Parser Usage

// file contents(./file.log):
// GET /data
// POST /login
// GET /timestamp

var Parser = require("logger-switch/parser")
var parser = new Parser({method: 0})
var file = "./test.log"
var writer = fs.createWriteStream(file)
writer.write("GET /timestamp\n")
writer.write("GET /data\n")
writer.write("POST /login\n")
writer.end()

function validation (param) {
    return (param == "GET")
}

parser.parse("method", validation, file, function(err, out) {
    var res = []
    out.on('data', function(d) {
        res.push(d)
    })
    out.on('end', function() {
        res.length.should.be.eql(2)
        res[0].should.contain("GET /timestamp")
        res[1].should.contain("GET /data")

        fs.unlink(file)
        done()
    })
})

Constructor

Logger(name, logger)
name - Prefix to be used while logging. default is 'Log :'
logger - Custom logger to be used. default is stdout and stderr

Parser(options) options - Should be in the format key-index, where key is for developer reference and index is the index of the key in each line when seperated by " "(space)

Methods - Logger

activate()
Will Enable logging activity

deactivate() Will disable logging activity

timestamp(format) Will enable/disable timestamp logging.
format - Supports momentjs timestamp format string. if null is passed then timestamp logging will be disabled

Methods - Parser

parse([key], [validation], file, cb)
Will parse the given file
key - the key in the options to be used to find the parameter. Defaults to timestamp with index 0
validation - Validation function to be called for the param. This is used to filter the lines in the result. Defaults to function(){return true}
file - Complete file path that has to be parsed
cb - Callback(err, result), result includes the filtered lines in the file

Testing

npm install
npm test

Similarly you can create many such logger and activate only the required logger from the configuration file, depending on env being used.
For more examples