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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsclass-logger

v0.1.7

Published

Logger which works perfectly both in production/debug environment.

Readme

Build Status

jsclass-logger

Logger which works perfectly both in production/debug environment.

What Makes "jsclass-logger" Unique

While there are many proven logging libraries, including famous "Winston", "jsclass-logger" focuses on ease of use. Check out the code below.

let logger;

// setup logger for production output
logger = require("jsclass-logger")();

// setup logger to output log with module name
logger = require("jsclass-logger")({}, "your_module_name");

// setup logger for development output
logger = require("jsclass-logger")({"debug":true});

// setup logger for file output
logger = require("jsclass-logger")({"toFile":true});

Here is an output sample.

// normal message
logger.info("log message");

> 2018-10-16 00:17:17.008 INFO  (test.js:34:20) log message

// object dump
logger.debug(object);

> 2018-10-16 00:17:17.011 DEBUG (test.js:34:21) *** OBJECT DUMP ***
>   TestClass {
>     "a": 1,
>     "b": 2,
>     "c": 3
>   }

// function dump
logger.debug(function);

> 2018-10-16 00:17:17.014 DEBUG (test.js:34:22) *** FUNCTION DUMP ***
>   function(a, b, c){return a+b+c};

Supports Log Rotation

You can specify when to rotate log and how many generations you want to keep easily.

// setup logger to rotate log file when file size exceed 100K
// And keep 3 generations on disk.
logger = require("jsclass-logger")({
  "toFile": true,
  "rotate": (file) => fs.statSync(file).size > 100000,
  "generation": 3
  });

Supports Timestamp Format Customize

You can customize timestamp format to meet your locale.

// setup logger to output customized timestamp
logger = require("jsclass-logger")({
  "ts": "DD/MM/YYYY hh:mm:ss"
});
logger.info("log message");

> 16/10/2018 00:17:17 INFO  (test.js:34:20) log message

Supports Stack Trace Dump

To print out stack trace, use "error()" or "trace()" to output log.

logger.error("log message");

> 16/10/2018 10:54:40 ERROR (test.js:32:20) log message
> at Context.<anonymous> (/Volumes/SDDrive/Google Drive/lib/jsclass-logger/test/test.js:32:20)
>     at callFn (/Volumes/SDDrive/Google Drive/lib/jsclass-logger/node_modules/mocha/lib/runnable.js:372:21)
>     at Test.Runnable.run (/Volumes/SDDrive/Google Drive/lib/jsclass-logger/node_modules/mocha/lib/runnable.js:364:7)

Supports Multi Log Level

Log Level for Debug Mode

"debug()" and "trace()" are log level for debug mode, so there will be no output when you don't set "debug: true" option to get logger instance.

Log Level For Production Mode

"info()", "warn()", "error()" are log lebel for production mode, so they will output log anytime.

Usage

API

Modules

Classes

Functions

jsclass-logger

Simple and easy to use logger.

Logger

Logger class.

Kind: global class

logger.debug(msg)

Output log at DEBUG level, which is a debug level.

Kind: instance method of Logger

| Param | Type | Description | | --- | --- | --- | | msg | any | Log message. |

logger.info(msg)

Output log at INFO level, which is a production level.

Kind: instance method of Logger

| Param | Type | Description | | --- | --- | --- | | msg | any | Log message. |

logger.warn(msg)

Output log at WARN level, which is a production level.

Kind: instance method of Logger

| Param | Type | Description | | --- | --- | --- | | msg | any | Log message. |

logger.trace(msg)

Output log at TRACE level, which is a debug level.

Kind: instance method of Logger

| Param | Type | Description | | --- | --- | --- | | msg | any | Log message. |

logger.error(msg)

Output log at ERROR level, which is a production level.

Kind: instance method of Logger

| Param | Type | Description | | --- | --- | --- | | msg | any | Log message. |

getLogger(desc, mod) ⇒ Logger

Get logger instance. supprted options are as below. -debug: true / false -toFile: true / false -outDir: directory to output log file, by default it is "./log/" -rotate: function to check when to rotate log file, should return true / false -generation: log files to keep on disk -ts: timestamp format in YYYYMMDDhhmmsszzz format

Kind: global function
Returns: Logger - Logger instance

| Param | Type | Description | | --- | --- | --- | | desc | option | Logger option | | mod | option | modulename to output |