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

temp_js_logger

v0.7.8

Published

Temporary backend/frontend logging library that patches console.

Downloads

27

Readme

temp js logger

Patch and enhance console logging methods.

cli colors screenshot

webpage screenshot

Install

Available for download at npmjs/package/temp_js_logger.

npm install temp_js_logger

Sound familiar?

The default scheme for logging in JS is to use the console object. If you're not using to a more complete logging library, the default solution is pretty limited. Basically:

  1. console.log to print undecorated messages to the terminal or browser console.
  2. If you're fancy, categorize messages with alternative method names, though in a backend terminal the messages won't appear any different: log info warn error.
  3. If you're not fancy, maybe you just put a prefix string in the message to show what log level it is, and always use console.log.

If you want message metadata, you have to include that yourself. And you don't configure console to only print messages at a certain level.

Then try this!

temp_js_logger looks to improve on this common early implementation of logging before a project migrates to a more complete logging library. This means you shouldn't have to change any code in order for temp_js_logger to work with your project.

const temp_logger = require('./temp_js_logger')

temp_logger.imports_promise
.then(() => {
	// I'm only nesting in promise resolve so optional imports (chalk for message coloring) are guaranteed ready
	console.log('DEBUG oh, that was easy')

	console.log('warn but can I configure the level?')

	temp_logger.set_level('info')

	console.log('info of course!')
	console.log('debug ignored')
})

Works for frontend and backend

When in a backend (nodejs) environment, log messages are printed to the cli. When in a frontend (browser) environment, they are printed to the browser debugging console, as well as in the webpage gui!

Configuration options

Below is a list of available options, which are passed members of an object to temp_logger.config.

level

The logging level at or above which a message must be in order to appear in the console/terminal.

level_gui

The logging level at or above which a message must be in order to appear in the webpage gui.

with_timestamp

Whether to include a timestamp in the message.

name

A name for the logger, which will be included in the message.

with_lineno

Whether to include the source code line number in the message.

parse_level_prefix

Whether to determine the level of the logged message using the first word of its content. For example, console.log('DEBUG hello') becomes DEBUG:hello and console.log('warning good bye') becomes WARNING:good bye.

with_level

Whether to include the level string/label in the output message.

with_always_level_name

Whether to include the ALWAYS level string in messages determined to be at this level, which is the default for any message that doesn't indicate the level and has parse_level_prefix set to true.

with_cli_colors

Whether to color the cli messages by level. Note this uses the optional chalk dependency, the import of which isn't ready until temp_logger.imports_promise resolves.

log_to_file

Whether to log to a file, located at TempLogger.LOG_FILE_PATH. Note file logging will not be ready until temp_logger.imports_promise resolves.

Implementation details

This only overrides the target console methods: log info warn error. Other console methods are unaffected.

All identifiers defined by this library are scoped as members of the contained TempLogger class, from which key methods are exposed via exports.