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

js-browser-console

v3.0.0

Published

Wraps the javascript console with log levels, formatting and colors.

Downloads

43

Readme

js-console

General

This overwrites the current js console to provide more log flexibility per environment and support for log timestamp and log caller.

Install

yarn add js-browser-console --save
npm install js-browser-console --save
bower install js-console --save

Options

After install the log function, will check the configured log level. You can change the log level by changing the value of console.level. Following values are supported:

  • console.LEVEL_DEBUG
  • console.LEVEL_INFO
  • console.LEVEL_NOTICE
  • console.LEVEL_WARN
  • console.LEVEL_ERROR
  • console.LEVEL_CRITICAL
  • console.LEVEL_ALERT
  • console.LEVEL_EMERGENCY These level are fully mappable to Monolog.

The default log level is console.LEVEL_DEBUG.

Example of changing log level

console.level = console.LEVEL_NOTICE;

If you define another log level then all levels, which are no longer allowed, will be NOT reported to the console.

These console functions are mapped to these log levels:

  • console.emergency ... console.LEVEL_EMERGENCY
  • console.critical ... console.LEVEL_CRITICAL
  • console.alert ... console.LEVEL_ALERT
  • console.error ... console.LEVEL_ERROR
  • console.warn ... console.LEVEL_WARN
  • console.notice ... console.LEVEL_NOTICE
  • console.info ... console.LEVEL_INFO
  • console.debug ... console.LEVEL_DEBUG
  • console.log ... console.LEVEL_DEBUG

Additional Functions

There are some additional function to log your message in beautiful colors. Every log function is available in

  • grey #777777
  • green #00AA00
  • blue #0000CC
  • turquoise #00AAAA
  • yellow #AAAA00
  • pink #CC00CC
  • red #CC0000
  • black #000000

You can choose these colors by calling the name color log function. Here is the example for the log function "debug". You can do this on the same way for all other log functions:

console.debug('Default Browser Color');
console.debugGrey('grey #777777 Color');
console.debugGreen('green #00AA00 Color');
console.debugBlue('blue #0000CC Color');
console.debugTurquoise('turquoise #00AAAA Color');
console.debugYellow('yellow #AAAA00 Color');
console.debugPink('pink #CC00CC Color');
console.debugRed('red #CC0000 Color');
console.debugBlack('black #000000 Color');

Output

Every log will be written in this format: [LEVEL] [DATETIME] [LOG SOURCE] MESSAGE

Example

<html>
<head>
    <script src="console.js"></script>
    <script src="example.js"></script>
</head>
</html>

example.js

'use strict';

console.log('Hello world log');
console.debug('Hello world debug');
console.level = console.LEVEL_ALERT;
console.debug('Hello world debug should not be displayed');
console.alert('Hello world alert');

This will output:

[debug    ] [26.05.2017 07:35:05.301] [/js-console/example] Hello world log
[debug    ] [26.05.2017 07:35:05.310] [/js-console/example] Hello world debug
[alert    ] [26.05.2017 07:35:05.311] [/js-console/example] Hello world alert