new Debugger( key )

A debug utility class that can be enabled across sessions using the given key by storing its state in localStorage.

Description

This class allows you to write additional debug info to the console within your code which by default is not actually output. You can then enable the debugger and it will start to output the results to the console.

This most useful feature of this is the ability to store the debug state across page sessions by using localStorage. This allows you enable the debugger and then refresh the page to view any debugger output that occurs on page load.

Parameters
Name Type Description
key string

The key to use to store the debug state in localStorage.

Members


key :string

The key used to store the debug state in localStorage.

Details
string

<readonly> enabled :boolean

Whether or not the debugger is currently enabled.

Description

The value for this property is synced with the current state stored in localStorage and should never set from outside of this class.

Details
boolean

Methods


enable()

Enable the debugger causing additional info to be logged to the console.

Examples
var d = new FooGallery.utils.Debugger( "FOO_DEBUG" );
d.log( "Never logged" );
d.enabled();
d.log( "I am logged!" );

disable()

Disable the debugger stopping additional info being logged to the console.

Examples
var d = new FooGallery.utils.Debugger( "FOO_DEBUG" );
d.log( "Never logged" );
d.enabled();
d.log( "I am logged!" );
d.disable();
d.log( "Never logged" );

log( message [, argN ] )

Logs the supplied message and additional arguments to the console when enabled.

Description

This method basically wraps the console.log method and simply checks the enabled state of the debugger before passing along any supplied arguments.

Parameters
Name Type Attributes Description
message string

The message to log to the console.

argN * <optional>

Any number of additional arguments to supply after the message.


logf( message, replacements [, argN ] )

Logs the formatted message and additional arguments to the console when enabled.

Parameters
Name Type Attributes Description
message string

The message containing named replacements to log to the console.

replacements Object.<string, *>

An object containing key value pairs used to perform a named format on the message.

argN * <optional>

Any number of additional arguments to supply after the message.

Details

FooGallery.utils.str.format for more information on supplying the replacements object.