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

ex-logger

v1.1.1

Published

Scalable multifunctional tunable logger created to resolve issues of logging any processes in a large projects

Downloads

5

Readme

NodeJS extended logger

Scalable multifunctional tunable logger created to resolve issues of logging any processes in a large projects.

Installation

$ npm install --save ex-logger

Usage

To begin usage need to create instance of Logger.

var exLogger = require("ex-logger");
var log = new exLogger.Logger({
        singleLine: true
    });
log.debug("Hello world");

Output example:

[2016/11/11][13:10:31][D][test.js][18] Hello world

Format review:

[DATE][TIME][LOG_LEVEL][MODULE][LINE:COLUMN] log string

Logger constructor require (of course if you want to change default view configuration) config object. Here is default configuration for Logger:

{
        module: "", 
        showDate: true,
        showTime: true,
        showLogLevel: true,
        showModule: true,
        showLine: true,
        showColumn: false,
        dispatcher: "",
        logLevel: LOG_LEVELS.trace,
        isModuleFullPath: false,
        singleLine: false
    };
  • module 'string' - custom module name. By default uses the name of js file
  • showDate 'boolean' - show [year/month/day]
  • showTime 'boolean' - show [hours/minutes/seconds]
  • showLogLevel 'boolean' - show [T] | [D] | [I] | [W] | [E] | [F] log level
  • showModule 'boolean' - show module name
  • showLine 'boolean' - show line number where log called
  • showColumn 'boolean' - show column on a string where log called
  • dispatcher 'string'-
  • logLevel 'number' (LOG_LEVELS.*) - minimum log level to show
  • isModuleFullPath 'boolean' - as module name show full file path name where log called
  • singleLine 'boolean' - log without \n symbol (in one line)

Hierarchy of log levels:

  • trace
  • debug
  • info
  • warning
  • error
  • fatal

Example of usage all log levels (for example let it be file logtest.js):

var exLogger = require("ex-logger");
var log = new exLogger.Logger({});

log.t("trace");
// log.trace("trace");

log.d("debug");
// log.debug("debug");

log.i("info");
// log.info("info");

log.w("warning");
// log.warning("warning");
// log.warn("warning");

log.e("error");
// log.error("error");
// log.err("error");

log.f("fatal");
// log.fatal("fatal");

Output example (one for each log level):

example console output

Global log level settings

Here is ability to set minimum log level for all Logger instances.

var exLogger = require("ex-logger");
exLogger.config.logLevel = exLogger.LOG_LEVELS.warning;

// All available log levels:
// exLogger.LOG_LEVELS.trace
// exLogger.LOG_LEVELS.debug
// exLogger.LOG_LEVELS.info
// exLogger.LOG_LEVELS.warning
// exLogger.LOG_LEVELS.error
// exLogger.LOG_LEVELS.fatal

Events

Each Logger instance has a method to register callback function to call it when something is logged.

var exLogger = require("ex-logger");
var log = new exLogger.Logger({});
log.on(function(logObject){
    // ...
});

log.debug("Something");
log.info("More...");

Here is logObject fields:

{ 
    date: '2016/11/11',
    time: '14:37:12',
    logLevel: 'D',
    module: 'logtest.js',
    line: '7',
    column: '5',
    log: 'Something',
    dispatcher: '' 
}

Dispatcher

Each new logger instance add to dispatcher and you can subscribe to dispatcher for all loggers events or with filtered only by some dispatcher name. By default all new instances of Logger has empty dispatcher name and automatic registered to dispatcher with an empty name "".

Example dispatcher usage:

var exLogger = require("ex-logger");

// subscribe on all any logger events
exLogger.Dispatcher.on(function(logObject){
    // ...
});

// subscribe on all Logger instances with empty dispatcher name
exLogger.Dispatcher.on("", function(logObject){
    // ...
});

// subscribe on all Logger instances with "requests" dispatcher name
exLogger.Dispatcher.on("requests", function(logObject){
    // ...
});

var log1 = new exLogger.Logger({dispatcher: "requests"});
var log2 = new exLogger.Logger({});

Tips

You can log any javascript type and mix variable types in one log time.

var exLogger = require("ex-logger");
var log = new exLogger.Logger({singleLine: true});

var auth = {user: "user", pass: "pass"};
var names = ["John", "Jimmy", "Joe"];
var anyString = "Hello. I'm a string";
var year = 2016;
var isare = true;
var func = function() {
    // any function
    return {auth: true};
}
var nan = NaN;
var und = undefined;
var nil = null;

log.debug(auth, names, anyString, year, isare, func, nan, und, nil);

Output:

[2016/11/11][15:03:17][D][test.js][21] {"user":"user","pass":"pass"} ["John","Jimmy","Joe"] Hello. I'm a string 2016 true function () {    // any function    return {auth: true};} NaN undefined null

Support/Contacts

Ihor Levchenko [email protected]