log4javascript - Can you load the PopupAppender on demand? -
i trying use log4javascript , wondering if there way load popupappender on demand.
i seeking functionality in-browser tools, there icon in application indicates has been logged , when click it, popupappender opens , allows me view logs.
i'm thinking write own simple appender show icon if there errors, i'm not sure how load popupappender , show historic messages?
you'd have have kind of proxy appender, suggest, stores logging messages , creates popupappender on demand. this:
demo: http://jsfiddle.net/hdrpt/
code:
function ondemandpopupappender() { this.popupappender = new log4javascript.popupappender(); this.poppedup = false; this.popperupperdisplayed = false; this.queuedloggingevents = []; } var proto = new log4javascript.appender(); ondemandpopupappender.prototype = proto; proto.appendqueued = function() { (var = 0, loggingevent; loggingevent = this.queuedloggingevents[i++]; ) { this.popupappender.append(loggingevent); } this.queuedloggingevents.length = 0; }; proto.popup = function() { this.poppedup = true; this.appendqueued(); }; proto.append = function(loggingevent) { var appender = this; this.queuedloggingevents.push(loggingevent); if (this.poppedup) { this.appendqueued(); } else if (!this.popperupperdisplayed && loggingevent.level.isgreaterorequal(log4javascript.level.error)) { var popperupper = document.createelement("div"); popperupper.style.border = "solid red 2px"; popperupper.innerhtml = "there error messages in log. click open."; popperupper.onclick = function() { appender.popup(); } document.body.appendchild(popperupper); this.popperupperdisplayed = true; } }; var log = log4javascript.getlogger("main"); log.addappender(new ondemandpopupappender()); log.debug("a debug message"); log.error("a horrible error!");
Comments
Post a Comment