Paul Daniell - Debug.Logger-0.01
NAME
Debug.Logger - A Debugging Logger
SYNOPSIS
Creating a simple debugging window which maintains focus
<script>
var logger = new Debug.Logger("debug_level_focus");
logger.debugMode();
logger.makeFocus();
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
Turning off a logger so it doesn't bother you
<script>
var logger = new Debug.Logger("off");
logger.off();
...
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
Make the logger only popup when there are warnings
<script>
var logger = new Debug.Logger("warn_level_no_focus");
logger.warnMode();
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
DESCRIPTION
A logger which sends output to a new window.
The logger has four modes:
(1) C<OFF>
(2) C<WARN>
(3) C<INFO>
(4) C<DEBUG>
Setting an instance of a logger to one of these
modes will cause messages tagged as such to be logged
and every logging level above it. Therefore, setting
a logger to C<INFO> mode will cause all
informational and warning statements to be logged.
Call the C<takeFocus()> and C<loseFocus()> methods if you
want the debugging window to stay on top or fall below
the parent window, respectively.
By default, new loggers are set to C<OFF>.
Constructor
var logger = new Debug.Logger("window_name");
Create a new Debug.Logger object. Each unique name defines a single logging window.
Methods
off()
Stops the logger from creating a popup or producing any further log output.
warnMode()
Logs WARNING statements.
infoMode()
Logs INFO and WARNING statements.
debugMode()
Logs DEBUG, INFO, and WARNING statements.
debug(msg)
Sends a DEBUG message to the logger.
warn(msg)
Sends a WARN message to the logger.
info(msg)
Sends an INFO message to the logger.
EXPORTS
Nothing.
AUTHOR
Paul Daniell <paul.daniell@gmail.com>
if(!Debug) var Debug = {};
Debug.Logger = function Logger(name){
this.name = name;
this.debugConsole = null;
this.level = 0;
this.focus = false;
}
Debug.Logger.VERSION = '1.0';
Debug.Logger.DEBUG = 300;
Debug.Logger.INFO = 200;
Debug.Logger.WARN = 100;
Debug.Logger.OFF = 0;
Debug.Logger.prototype.log = function(msg){
if(this.debugConsole == null || (this.debugConsole.closed)){
this.debugConsole = window.open("", this.name, "height=300,width=600,scrollbars=yes");
this.debugConsole.document.open("text/html");
this.debugConsole.document.writeln("<html><body>");
}
this.debugConsole.document.writeln("<div style=\"font-family:monospace\">" + msg + "</div>");
if(this.focus == true)
this.debugConsole.focus();
}
Debug.Logger.prototype.debug = function(msg) {
if(this.level >= Debug.Logger.DEBUG) {
this.log("DEBG[" + new Date().getTime() +"]: " + msg);
}
}
Debug.Logger.prototype.warn = function(msg) {
if(this.level >= Debug.Logger.WARN){
this.log("<span style=\"color:red;\">WARN[" + new Date().getTime() + "]: " + msg + "</span>");
}
}
Debug.Logger.prototype.info = function(msg) {
if(this.level >= Debug.Logger.INFO) {
this.log("INFO[" + new Date().getTime() + "]: " + msg);
}
}
Debug.Logger.prototype.debugMode = function(){
this.level = Debug.Logger.DEBUG;
}
Debug.Logger.prototype.warnMode = function(){
this.level = Debug.Logger.WARN;
}
Debug.Logger.prototype.infoMode = function() {
this.level = Debug.Logger.INFO;
}
Debug.Logger.prototype.off = function() {
this.level = Debug.Logger.OFF;
}
Debug.Logger.prototype.makeFocus = function() {
this.focus = true;
}
Debug.Logger.prototype.loseFocus = function() {
this.focus = false;
}
/*
=head1 NAME
Debug.Logger - A Debugging Logger
=head1 SYNOPSIS
=head2 Creating a simple debugging window which maintains focus
<script>
var logger = new Debug.Logger("debug_level_focus");
logger.debugMode();
logger.makeFocus();
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
=head2 Turning off a logger so it doesn't bother you
<script>
var logger = new Debug.Logger("off");
logger.off();
...
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
=head2 Make the logger only popup when there are warnings
<script>
var logger = new Debug.Logger("warn_level_no_focus");
logger.warnMode();
logger.debug("Debugging info");
logger.debug("Some more debugging info");
logger.info("Informational level debugging");
logger.warn("Uh ok");
</script>
=head1 DESCRIPTION
A logger which sends output to a new window.
The logger has four modes:
(1) C<OFF>
(2) C<WARN>
(3) C<INFO>
(4) C<DEBUG>
Setting an instance of a logger to one of these
modes will cause messages tagged as such to be logged
and every logging level above it. Therefore, setting
a logger to C<INFO> mode will cause all
informational and warning statements to be logged.
Call the C<takeFocus()> and C<loseFocus()> methods if you
want the debugging window to stay on top or fall below
the parent window, respectively.
By default, new loggers are set to C<OFF>.
=head2 Constructor
var logger = new Debug.Logger("window_name");
Create a new C<Debug.Logger> object. Each unique name
defines a single logging window.
=head2 Methods
=head3 off()
Stops the logger from creating a popup or producing
any further log output.
=head3 warnMode()
Logs WARNING statements.
=head3 infoMode()
Logs INFO and WARNING statements.
=head3 debugMode()
Logs DEBUG, INFO, and WARNING statements.
=head3 debug(msg)
Sends a DEBUG message to the logger.
=head3 warn(msg)
Sends a WARN message to the logger.
=head3 info(msg)
Sends an INFO message to the logger.
=head2 EXPORTS
Nothing.
=head1 AUTHOR
Paul Daniell <paul.daniell@gmail.com>
=cut
*/