Created
September 26, 2011 13:56
-
-
Save aerith/1242284 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* harukaze.logger | |
* | |
* @required jQuery | |
* @required harukaze.trigger | |
*/ | |
(function (ns, w, d, $) { | |
var harukaze = ns.harukaze = $.extend({}, ns.harukaze); | |
harukaze.logger = { | |
useNative: true, | |
viewCounter: 0, | |
classPrefix: 'harukaze-logger-log', | |
removeDelay: 1500, | |
info: loggerInfo, | |
notice: loggerNotice, | |
warn: loggerWarn, | |
error: loggerError | |
}; | |
/** | |
* loggerInfo | |
* | |
* @param string message | |
* @return void | |
*/ | |
function loggerInfo (message) { | |
loggerLog.apply(this, ["info", message]); | |
} | |
/** | |
* loggerNotice | |
* | |
* @param string message | |
* @return void | |
*/ | |
function loggerNotice (message) { | |
loggerLog.apply(this, ["notice", message]); | |
} | |
/** | |
* loggerWarn | |
* | |
* @param string message | |
* @return void | |
*/ | |
function loggerWarn (message) { | |
loggerLog.apply(this, ["warn", message]); | |
} | |
/** | |
* loggerError | |
* | |
* @param string message | |
* @return void | |
*/ | |
function loggerError (message) { | |
loggerLog.apply(this, ["error", message]); | |
} | |
/** | |
* loggerLog | |
* | |
* @private | |
* @param string type | |
* @param string message | |
* @return void | |
*/ | |
function loggerLog (type, message) { | |
var context = this; | |
if (harukaze.support.logger && this.useNative) { | |
w.console.log(type); | |
w.console.log(message); | |
} else { | |
var label = '[' + type + ']'; | |
var content = harukaze.support.json ? w.JSON.stringify(message) : message.toString() ; | |
var log_timer = null; | |
var log_area = $('<div />') | |
.addClass(this.classPrefix) | |
.addClass([this.classPrefix, type].join('-')) | |
.css({ | |
position: 'absolute', | |
bottom: '0', | |
right: '0' | |
}) | |
.text([label, content].join(' ')) | |
.hide() | |
.appendTo(d.body); | |
harukaze.trigger.invoke('harukaze.logger.log.after.add', log_area); | |
if (log_area.not(':visible')) { | |
log_area.fadeIn(); | |
this.viewCounter++; | |
} | |
log_timer = setTimeout(function () { | |
clearTimeout(log_timer); | |
harukaze.trigger.invoke('harukaze.logger.log.before.remove', log_area); | |
if (log_area.length) { | |
log_area.remove(); | |
context.viewCounter--; | |
} | |
}, this.removeDelay); | |
} | |
} | |
})(this, window, document, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment