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

manowar

v1.0.1

Published

visually differentiate request logs via indentation, coloring, and namespacing via cls-hooked

Downloads

10

Readme

Man O' War Logger

Have difficulty matching concurrent request event logs?

logging example

This module provides a live logger that indents each request's logs a uniform amount, connecting them all along a line. (or tendril on a Portugese Man O' War!)

This helps visualize a few things:

  1. in what order async events occur ...in sync (so this isn't applicable to true parallelism in, say, web workers)
  2. which requests generated which logs in concurrent-traffic scenarios, supplemented by a correlation_id for records
  3. how long requests take
  4. file line references generating logs
  5. also it is colorful

This requires a few things to work:

  • that you use the provided cc() logger, which is a terse, icon-able, chalk-colorable, extendable way to log things
    • (this also provides cc.sql, a log format ideal to plug into dbq, should you use that)
  • that you include the requestLogger express middleware atop your router (or above all the routes you want logs for), which itself does a few things:
    • initiate the request's indentation, which is maintained until it replies or dies
    • log out some req info
    • kill requests that take longer than forceRequestKillAfter milliseconds (defaults to 10 seconds)
    • times requests for reference

Usage & Options

var {cc,requestLogger}=require("manowar")({
        //option:default
        ellipsize:true //cut off log lines once they exceed window width
        ,forceRequestKillAfter:10000//kill requests that take longer than this many milliseconds. Falsy = never.
        ,logEachReq:(req,res)=>false //a fxn for you to customize the incoming request log. Return false to defer to plugin default
        ,overrideIconsWith:"" //some displays don't correctly space icons & break the line display. Override them here
		,logBody:true //whether to log request bodies
		,fileNameSize:20 //max width to allow for file names on the left
		,fileLineFilter:false //if you need a custom stacktrace filter to get the file name
		,maxIdLength:11 //length of id col
		,idMaker:require('shortid').generate //if you want to supply IDs your own way
		,widthFudgeFactor:0//maybe process.stdout.columns lies on your box
		,logSync:false//fs.writeSync vs console.log
        ,cc:{//any custom logging shortcuts you'd like.
            //coming soon
        }
    })
    ,app=express()
    ,router=express.Router()

router.use(requestLogger)
    //[then add your routes, use logging wherever...like:]
    .get("/*",(req,res)=>{
        cc(`logging a special message!`)
        res.send("howdy")
    })


app.use(router)

Logging defaults

cc('text') logging works, but extra colors & icons are available at cc.* (if you leave icons on):

logging defaults

Additionally:

  • cc.chalk exists for you to stylize additional logs locally with chalk
  • cc.namespace will give you access to the current cls-hooked namespace manowar set up to manage indentation, should you like to use it or attach more info in a local scope.