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

munia

v0.0.2

Published

Simple and practical JSON Logger

Downloads

13

Readme

munia

Simple and practical JSON Logger

A JSON logger that can work very well without configuration, though it can be customised for standard logging options.

Installation

npm install munia --save

Usage

  • Basic usage:
const log = require('munia')()
log.info('simple and practical logger')

Output:

{"time":"2000-01-01T05:30:00.000+05:30","level":"info", "message":"simple and practical logger", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123}

  • Pass module name:
const munia = require('munia')
const log = munia('munia')
log.info('i can print module name')

Output:

{"time":"2000-01-01T05:30:00.000+05:30","level":"info", "message":"i can print module name", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123,"module":"munia"}

  • Time in local time zone (default):
const log = munia({timeFormat: 'local'})
log.info('time as local time zone')

Output:

{"time":"2000-01-01T05:30:00.000+05:30", "level":"info", "message":"time as local time zone", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123}

  • Time as ISOString:
const log = munia({timeFormat: 'ISO'})
log.info('time as ISOString format')

Output:

{"time":"2000-01-01T00:00:00.000Z", "level":"info", "message":"time as ISOString format", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123}

  • Time as epoch:
const log = munia({timeFormat: 'epoch'})
log.info('time as epoch')

Output:

{"time": 946684800000, "level":"info", "message":"time as epoch", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123}

  • Log with meta info:
const log = munia()
log.info('log userId also', {userId: 'foo'})

Output:

{"time":"2000-01-01T05:30:00.000+05:30","level":"info", "message":"log userId also", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123, "userId":"foo"}

  • Do not include process id, host name and host ip. Any of these can be set as false.
const log = munia({hostname: false, hostip: false, pid: false})
log.info('lean log')

Output:

{"time":"2000-01-01T05:30:00.000+05:30","level":"info","message":"lean log"}

  • log time taken in execution like console.time and console.timeEnd
const log = munia()
child = log.child(null, {enableTimeTaken:true})

child.info.time('API request')
setTimeout(() => {
  child.info.timeEnd('API request')
}, 1000)

Output:

{"time": "2000-01-01T05:30:00.000+05:30", "level":"info", "message": "API request", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123,"timetaken":"Initiated"}

{"time": "2000-01-01T05:30:00.000+05:30", "level":"info", "message": "API request [time taken: 1004.496987ms]", "hostname":"my-machine", "hostip":"127.0.0.1", "pid":123, "app":"munia", "timetaken":1004.496987}

  • Custom log levels, default levels are ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly'] in priority order.
const log = munia({
  levels: ['error', 'info', 'debug'],
  logLevel: 'debug'  //default log level is info
})
log.error('this is error message')
log.info('this is info message')
log.debug('this is debug message')

Output

{"time":"2000-01-01T05:30:00.000+05:30","level":"error","message":"this is error message","hostname":"my-machine","hostip":"127.0.0.1","pid":123}
{"time":"2000-01-01T05:30:00.000+05:30","level":"info","message":"this is info message","hostname":"my-machine","hostip":"127.0.0.1","pid":123}
{"time":"2000-01-01T05:30:00.000+05:30","level":"debug","message":"this is debug message","hostname":"my-machine","hostip":"127.0.0.1","pid":123}

Test

npm test

To be implemented

  • Logger function after silly "limit" that run only n times. It would be helpful for debugging in for or while loop.

License

Licensed under MIT.