logminer
An object oriented logger for more organised log tracking.
var Log = ; var log = 'Parent'; log; log; log; var child = log; child
With a Dark Terminal the above code becomes:
With a Light 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
The source code that produced the above logs:
var Log = ; var log = 'Event'; log;log; var child = log; child; child; var grandchild = child; grandchild; grandchild; { var child = log; child; child;} { var child = log; child; child;} ;;
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
orfalse
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 : eventid // Scope Title title : eventtitle // the current time in ISO Date time : currentTime // this event event : event // this event's direct parent parent : eventparent // 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 = ;
Initialize a Log Scope
var parent = 'Parent' parent;
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;
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.
{ var child = parent; child;}
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 = ;log;
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 = 'Parent';parent;
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.