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

logminer

v1.0.0

Published

An object oriented logger for more organised log tracking.

Downloads

15

Readme

logminer

An object oriented logger for more organised log tracking.

var Log = require('logminer');

var log = new Log('Parent');
    log.message('hello');
    log.warn('world');
    log.info('in 2015');
    
var child = log.child('Child');
	child.error('exit')

With a Dark Terminal the above code becomes: logs in dark terminal

With a Light Terminal: logs in white terminal

Features

  • Unlimited Object Nesting
  • Complete Silence Function
  • Limited Silence Function
  • Listen for Events (they come with id, time, stack traces etc) ready for integration into GUI's and external services

Complex Hierarchy Example

complex logs

The source code that produced the above logs:

var Log = require('logminer');

var log = new Log('Event');

log.message('initializing map');
log.message('loading kids from the database');

var child = log.child('Child');
    child.info('more kids are coming');
    child.warn('something smells');
    
var grandchild = child.child('GrandChild');
    grandchild.error('the poo is happening');
    grandchild.info('false alarm');

function phoneCall(){
    var child = log.function(arguments);
    child.message('incoming phone call ', {
        name: 'George Lucas',
        phone: '001.124.412.511',
        location: 'Earth',
        id: 80022
    });
    child.message('transmission terminated');
}

function smsReceived(){
    var child = log.function(arguments);
    child.message('sms received from santa claus');
    child.message('sms stored');
}

phoneCall();
smsReceived();

Global Scope API's

The Log refers to the Function Object returned by the logminer module

var Log = require('logminer')

new Log(string title, boolean silence)

Description: Creates a new Local Scope Log Object.

Arguments:

  • title: Log Scope Title
  • silence: Hides all messages coming from this scope - true or false

Returns:

  • A Log Scope Object

Log.onEvent(function eventCallback(event))

Description: Global Log Event Listener

Arguments:

  • callback: a function that runs when an event occured

Callback Arguments:

  • event: An Event Object

Local Scope API's

The log here referes to a Local Scope Log Object:

log.message(arguments [...])

  • Logs regular messages (+), normal color

log.info(arguments [...])

  • Logs informations (i), blue color

log.warn(arguments [...])

  • Logs warning (!), yellow color

log.error(arguments [...])

  • Logs errors (!!), red color

log.onEvent(function eventCallback)

Description: Local Log Event Listener

Arguments:

  • callback: a function that runs when an event occured

Callback Arguments:

  • event: An Event Object

Objects

An Event Object:

{
    // Scope ID
	id         : event.id,
	
	// Scope Title
	title      : event.title,
	
	// the current time in ISO Date
	time       : currentTime,
	
	// this event
	event      : event,
	
	// this event's direct parent
	parent     : event.parent,
	
	// array of arguments from a Local Scope Log API 
	arguments  : entryArguments, 
	
	// string array of parents
	parents    : eventParents, 
	
	// Stack trace generated by stacktrace-js
	stacktrace : strackStrace
};

Usage

Setup Module

var Log = require('logminer');

Initialize a Log Scope

var parent = new Log('Parent')
	parent.message('hello');

Will display:

# ig0l4o2g Oct 21 15 5:16:00: Parent 
+ ig0l4o2g Oct 21 15 5:16:01:  at Parent: hello

Initialize a Child

This creates a child logger which inherits the Parent in every log produced with childlog.

var child = parent.child('Child');
	child.message('hello');

Will display:

# ig0l4o3g Oct 21 15 5:16:00: Child 
+ ig0l4o3g Oct 21 15 5:16:01:  at Parent.Child: hello

Initialize a Child in Function

This grabs the name of the function.

function hello(){
	var child = parent.function(arguments);
	child.message('world');
}

Will display:

# ig0l4o4g Oct 21 15 5:16:00: hello 
+ ig0l4o4g Oct 21 15 5:16:01:  at Parent.hello: world

Event Listeners

Listen for All Events

The onEvent method can be used to listen for all events when used on Top-Most Logminer function returned by the module itself.

var Log = require('logminer');
log.onEvent(function(event){
	// ...send event to GUI or external service...
	console.log(event.title, event.arguments);
});

Listen for Local Events

The onEvent method can be used on any Logminer Instance to listen for only direct logs from that Instance. (children of the instance will not be catched)

var parent = new Log('Parent');
parent.onEvent(function(event){
	// ...
});

Todo

  • enable disable log entry elements
  • more color schemes configuration

Contribution

Contribtution is very welcomed!

License

(The MIT License)

Copyright (c) 2014 Halász Ádám

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.