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

mega-nice-log

v3.1.0

Published

A mega nice log

Downloads

5

Readme

Mega Nice Log

A mega nice log library. Works in Node and in browsers.

Install

npm install mega-nice-log

Overview

Instantiate a logger

Instantiate a new logger per file. The constructor takes its filename as the parameter. When you are in Node simply use __filename.

import Log from 'mega-nice-log'

let log = new Log(__filename)

When you are in a browser depict the filename.

import Log from 'mega-nice-log'

let log = new Log('HttpServer.ts')

Log

Now you can log. Here are the five log levels that you can use.

  • log.error: For errors
  • log.warning: For warnings
  • log.info: For information that you always want to see in your log. May help the admin.
  • log.debug: For very fine grained information about the execution of the code.
  • log.insane: For very detailed and lengthy output that you only want to see if it is really relevant. When you are debugging exactly that file.

Like in any other logging library error will only print errors while warning will print errors and warnings and so on.

Prepended log information

The logger will prepend the filename without its extension assuming it is equal to a class name.

HttpServer$ Starting service...
HttpServer$ Running on port 80

If your file contains several classes you can depict a class name.

let l = log.cls('Request')
l.debug('this.url =', this.url)
HttpServer.ts > Request$ this.url = 'http://mega-nice.com/json'

Additionally you can and you always should depict the name of the function the logger is logging in.

let l = log.fn('handler')
l.debug('Handling incoming request...')
l.debug('request =', request)
HttpServer.ts > HttpServer$ Entering HttpServer.handler
HttpServer.ts > HttpServer.handler$ Handling incoming request...
HttpServer.ts > HttpServer.handler$ request = Request { url: 'http://mega-nice.com/json' }

When instantiating the function specific logger it will print a Entering ... message which is very useful when trying to follow the flow of the program.

Different color per log level

The prepended information (filename, class name, function name) will be printed in different colors corresponding to the used log level.

  • error: red
  • warning: yellow
  • info: white
  • debug: cyan
  • insane: cyan

Set the log level

You can set the log level directly in the constructor of the logger.

let log = new Log(__filename, 'insane')

Or you can set it on a static property on the Log class.

Log.levels = {
  'HttpServer.ts': 'info',
  'HttpServer': 'debug',
  'HttpServer.handler': 'insane'
}

You can either depict the filename, the class name or the function name in conjunction with its class name.

Set a global log level

You can set a global log level which will be used if there is no other declaration.

Log.globalLevel = 'warning'

When you run your tests it may be useful to silence all the output.

Log.gobalLevel = 'silent'

Use colors in the first message parameter

The first given message parameter may contain color definitions.

log.debug('The value was color(magenta)undefined')

This will output the word undefined with a magenta color.

The following colors are supported. Those are the standard console colors: reset, bright, dim, underscore, blink, reverse, hidden, black, red, green, yellow, blue, magenta, cyan, white, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite