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:
- 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
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();
The Log refers to the Function Object returned by the logminer module
var Log = require('logminer')
Description: Creates a new Local Scope Log Object.
Arguments:
- title: Log Scope Title
- silence: Hides all messages coming from this scope -
true
orfalse
Returns:
- A Log Scope Object
Description: Global Log Event Listener
Arguments:
- callback: a function that runs when an event occured
Callback Arguments:
- event: An Event Object
The log here referes to a Local Scope Log Object:
- Logs regular messages (+), normal color
- Logs informations (i), blue color
- Logs warning (!), yellow color
- Logs errors (!!), red color
Description: Local Log Event Listener
Arguments:
- callback: a function that runs when an event occured
Callback Arguments:
- event: An Event Object
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
};
var Log = require('logminer');
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
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
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
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);
});
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){
// ...
});
- enable disable log entry elements
- more color schemes configuration
Contribtution is very welcomed!
(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.