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

loglevel-prefix-persist

v1.0.3

Published

Plugin for loglevel with message prefix and persistence

Downloads

12

Readme

loglevel-prefix-persist

loglevel plugin - Support for the following:

  • (Almost) Isomorphic - passes single log config that can be used on both client and server
  • can be used by client or server alone
  • client & server log message prefix with [your/module-name]
  • client & server log persistence
  • additional datetime information, text color to server log

Uses

#Usage Assuming the following simple config

var logCfg = {
    "level":{
        "production": "warn",
        "development": "info"
    },
    "persist":"error",
    "max":2
}

On server side, initialize plugin in server.js


var loglevel = require('loglevel');
var logger = require('loglevel-prefix-persist/server')
var log = logger(process.env.NODE_ENV, loglevel, logCfg);


var app = express();
app
    .use(bodyParser.urlencoded({ extended: false }))
    .use(bodyParser.json())

//...

if (log.writer) {
	// if client log persistence is enabled, this will accept and writes logs coming from client side
    app.use(log.writer);
}

On client side, initialize plugin in client.js entry

var loglevel = require('loglevel');
var logger = require('loglevel-prefix-persist/client');
var log = logger('development', loglevel, logCfg);

All together (for both client and server)


// namespacing modules
var log = require('loglevel').getLogger("my/module-name");

// start logging
log.debug('Debug will not show')
log.info('Info will show under development, but not in production','config',logCfg)
log.warn('Warn will always show')
log.error('Error will always show')

#Result server

alt server

client

alt client

#Config

  • Default environment is 'development'
  • Default log level is 'info'
  • Default persistence for server is same as log level
  • Default persistence for client is disabled
  • If persistence is turned on and max is not set, old files will not be cleaned up

Config examples:


// log level='warn', server persistence only (at 'warn'), log daily forever
var logCfg = {
	"level":"warn"
}

// log level for client+server, no persistence
var logCfg = {
	"level": {"server":"info", "client":"warn"}, // regardless of environment
	"persist":false
}

// log level for production+development, persist for level='error', max 2 days log
var logCfg = {
    "level":{
        "production": "warn",
        "development": "info"
    },
    "persist":"error",
    "max":2
}

// cfg for production+developement, client+server
var logCfg = {
    "level":{
        "production": {"server":"info", "client":"warn"},
        "development": "debug"
    },
    "persist":{
        "client":"error", // only persist client level='error'
        "server":true // persist server 'debug' in development, 'info' in production
    },
    "max":2
}