Created
November 8, 2012 15:31
-
-
Save mkuklis/4039482 to your computer and use it in GitHub Desktop.
logger.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
var Logger = this.Logger = function ($el) { | |
this.$logger = $el; | |
this.timers = {}; | |
} | |
Logger.prototype.stop = function (label) { | |
this.timers[label].end = new Date().getTime(); | |
this.timers[label].time = this.timers[label].end - this.timers[label].start; | |
this.log(label + ': ' + this.timers[label].time + 'ms'); | |
} | |
Logger.prototype.start = function (label) { | |
this.timers[label] = {}; | |
this.timers[label].start = new Date().getTime(); | |
} | |
Logger.prototype.clear = function () { | |
this.timers = {}; | |
this.$logger.html(''); | |
} | |
Logger.prototype.log = function (message) { | |
this.$logger.append('<p>' + message + '</p>'); | |
} | |
}).call(this); | |
// usage | |
var logger = new Logger($('#logger')); | |
logger.start('label1'); | |
logger.stop('label1'); // prints time taken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment