@tim
i tried to do what you suggested, but somehow it bugged me all along :)
i now ended up in the following situation:
i have two options for my debugging (debugging with popup only):
1.: you can add an url param "debug=true" which initially opens the popupappender window and logs messages.
2.: you can also open/close the popupappender from a menu option.
the problem was:
the popupappender opens cleaned up if closed/opened dynamically.
what i needed:
the popupappender shall not re-open cleaned up, but re-open with all the old logging events.
the solution:
i added a second appender which always logs everything silently (or also appends to the popupappender if it is opened), and thus i can push all silently logged messages to the popupappender manually when it is re-opened by the ui.
the popupappender related stuff:
var popupAppender = new log4javascript.PopUpAppender(),
layout = new log4javascript.PatternLayout('%d{yyyy MMM dd HH:mm:ss,SSS} %-5p %m');
popupAppender.setLayout(layout);
popupAppender.setThreshold(log4javascript.Level.TRACE);
... and later:
toggleAppender: function () {
var appender = log.getEffectiveAppenders();
if (!appender.length || appender.length <= 1) {
// just to make sure...
log.addAppender(popupAppender);
}
if (!popupAppender.isVisible()) {
// got some "old" logging events?!
for (var index = 0; index < loggingEvents.length; index++) {
popupAppender.append(loggingEvents[index]);
}
popupAppender.show();
} else {
popupAppender.hide();
}
},
isPopupAppenderVisible: function () {
return popupAppender.isVisible();
},
registerHeaderEventListener: function () {
// just some angularing stuff for changing the "open"/"close" string
var headerScope = angular.element('#headerBar').scope();
popupAppender.addEventListener("unload", function() {
headerScope.popupAppenderIsVisible = false;
});
popupAppender.addEventListener("load", function() {
headerScope.popupAppenderIsVisible = true;
});
}
the custom appender related stuff:
function CustomAppender() {}
CustomAppender.prototype = new log4javascript.PopUpAppender();
CustomAppender.prototype.layout = new log4javascript.PatternLayout('%d{yyyy MMM dd HH:mm:ss,SSS} %-5p %m');
CustomAppender.prototype.threshold = log4javascript.Level.TRACE;
CustomAppender.prototype.toString = function () {
return 'silent custom appender';
};
CustomAppender.prototype.append = function (loggingEvent) {
if (loggingEvent.length > 1) {
for (var index = 0; index < loggingEvent.length; index++) {
loggingEvents.push(loggingEvent[index]);
// update the popup appender if it is visible
if (popupAppender.isVisible()) {
popupAppender.append(loggingEvent[index]);
}
}
} else {
loggingEvents.push(loggingEvent);
// update the popup appender if it is visible
if (popupAppender.isVisible()) {
popupAppender.append(loggingEvent);
}
}
};
and some initialization:
log4javascript.CustomAppender = CustomAppender;
var log = new log4javascript.getLogger('myLogger');
log.setLevel(log4javascript.Level.TRACE);
var customAppender = new log4javascript.CustomAppender();
log.addAppender(customAppender);
// the DEBUG var is true if the url wants it to be true
if (DEBUG) {
log.addAppender(popupAppender);
}