lz.DebugService
The Laszlo debugger

JavaScript: lz.DebugService
extends LzBootstrapDebugService (private) »

Debug is the single instance of the class lz.DebugService.

There are three ways to enable the debugger, as described in the Debugging chapter of the Developer's Guide.

The debugger can be useful in debugging your own code, but you should also use debugging to report bugs. The debugger method LzDebugService.bugReport() will output information that can be cut and pasted into a bug report to aid in diagnosing the bug.

The debugger has a range of methods for formatting output to the debugger console: LzDebugService.debug(), LzDebugService.info(), LzDebugService.warn(), and LzDebugService.error(). Each of these is based upon the basic formatted output method LzDebugService.format(). The variants prefix their message with a label (DEBUG, INFO, WARNING, or ERROR) and will print in a distinct color. When backtraces are enabled, these debug messages will also give a source location.

The debug messages can be silenced by setting Debug.messageLevel.

Debugger messages are inspectable, as the example below demonstrates. Clicking on the printed representation of the object (in blue) will show the details of the object. The message itself can also be inspected. When backtraces are enabled, one component of the message will be a backtrace that can be inspected to see the call chain and function arguments that resulted in the message.

Example 3. Debug output methods

<canvas debug="true" height="150">
   <debug y="5%" height="90%"/>
   <script><![CDATA[
     Debug.format("Hello %s!\n", 'world');
     Debug.debug("Click there -> %w to inspect the object", {a: 1, b: 2});
   ]]></script>
 </canvas>

By default, the debugger will intercept runtime errors (instances of Error that are thrown by the runtime or program) and report them. These reports can be silenced by throwing values that are not instances of Error, or by adding #pragma "throwsErrors=true" to the function or method containing the throw.

The optional <debug> tag controls the appearance of the debugger console window when debugging is on.

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
inspectPrintDepth   Number 1 read/write
  LzDebugService.inspect() will abbreviate the printed representation of any properties whose depth is greater than Debug.inspectPrintDepth.
inspectPrintLength   Number 128 read/write
  LzDebugService.inspect() will truncate the printed representation of any properties whose length is greater than Debug.inspectPrintLength.
lastError       read/write
  The last error that was reported. Used as a default for `bugReport`
messageLevel   String 'ALL' read/write
  Debug messages are enabled/disabled by the setting of Debug.messageLevel. The valid levels are one of the keys of lz.DebugService.messageLevels. All messages of a lower level than the current setting will be suppressed
printDepth   Number 8 read/write
  LzDebugService.write() will abbreviate the printed representation of any object whose depth is greater than Debug.printDepth.
printLength   Number 1024 read/write
  LzDebugService.write() will truncate the printed representation of any object whose length is greater than Debug.printLength.
showInternalProperties   Boolean false read/write
  LzDebugService.inspect() will show internal properties if this is true.
LzBootstrapDebugService (private) »

Class Attributes

Name (CSS property) Type (tag) Type (js) Default Category
messageLevels   Object   readonly
  Possible values of Debug.messageLevel (q.v.)

Methods

bugReport()
lz.DebugService.bugReport(error : *, verbose : Boolean);
Format information about an error, warning, or other debugger message suitably for reporting a bug. This method can be used to create a report suitable for copy/pasting into a bug report. To use it, enable backtraces and debugging, inspect the debugger message that you believe reveals a bug, then invoke `Debug.bugReport()` in the debugger. Copy and paste the output of that call into your bug report.
Parameter Name Type Description
error * An debugger message or message ID. Defaults to the last message that was inspected or the last error that was reported.
verbose Boolean If true, each frame argument in the backtrace will be inspected. Defaults to the value of Debug.showInternalProperties.

debug()
lz.DebugService.debug(args : [*]);
Display a debugging message on the console. Formats its arguments using LzFormatter.formatToString(). May be silenced by setting Debug.messageLevel.
Parameter Name Type Description
args [*] Any number of arguments to be formatted according to the control string

ensureVisible()
lz.DebugService.ensureVisible();
Ensure the debugger console is visible. Any debugger output will implicitly call this, but may be needed if you just want to ensure the debugger console is visible without creating any ouput.

error()
lz.DebugService.error(args : [*]);
Display an error message on the console. Formats its arguments using LzFormatter.formatToString(). May be silenced by setting Debug.messageLevel.
Parameter Name Type Description
args [*] Any number of arguments to be formatted according to the control string

explainStyleBindings()
lz.DebugService.explainStyleBindings(node : lz.node, showInherited);
Explain the style bindings of the attributes of a node For each attribute of the node that has a style, the CSS rules that apply to the node that could affect that binding are displayed. The rules are displayed (with their source) from the most-specific to the least specific, and the style names and values of the rule that apply to this node are displayed. Values that are superceded by more specific rules are displayed in italics.
Parameter Name Type Description
node lz.node the node of interest
showInherited   whether to show inherited bindings

format()
lz.DebugService.format(control : String, args : [*]);
Display formatted output to the debug console. Formats its arguments using LzFormatter.formatToString().
Parameter Name Type Description
control String A control string where % indicates the conversion of the corresponding argument
args [*] Any number of arguments to be formatted according to the control string

info()
lz.DebugService.info(args : [*]);
Display an informational message on the console. Formats its arguments using LzFormatter.formatToString(). May be silenced by setting Debug.messageLevel.
Parameter Name Type Description
args [*] Any number of arguments to be formatted according to the control string

inspect()
lz.DebugService.inspect(obj : Object);
Display the properties of an object on the debug console. Debug.inspect() displays each of the properties of its argument object using LzDebugService.write(). Long representations (and long Strings) are abbreviated if they are longer than Debug.inspectPrintLength, or deeper than Debug.inspectPrintDepth. Properties that are abbreviated are displayed as links. Clicking on the link will invoke Debug.inspect() on that object.
Parameter Name Type Description
obj Object the object to inspect
Returns Type Description
  Object the inspected object

showParent()
lz.DebugService.showParent(view);
Display the parent of a view on the debug console. Debug.showParent() displays the parent view of its argument object using LzDebugService.write().
Parameter Name Type Description
view    
Returns Type Description
  Array the view's parent

showSubviews()
lz.DebugService.showSubviews(view);
Display the subviews of a view on the debug console. Debug.showSubviews() displays each of the subviews of its argument object using LzDebugService.write().
Parameter Name Type Description
view    
Returns Type Description
  Array the view's subview array

versionInfo()
lz.DebugService.versionInfo();
Display version info. Displays various version information about the running application such as the URL it was loaded from, the version of the LPS that is running and the underlying runtime version.

warn()
lz.DebugService.warn(args : [*]);
Display a warning message on the console. Formats its arguments using LzFormatter.formatToString(). May be silenced by setting Debug.messageLevel.
Parameter Name Type Description
args [*] Any number of arguments to be formatted according to the control string

write()
lz.DebugService.write(any : [*]);
Display one or more objects on the debug console. Note: LzDebugService.format() allows more control over displaying multiple objects. Use it instead of Debug.write. Debug.write() displays objects on the debug console in an informative format. Simple objects are represented as themselves. Complex objects are represented by their type and a concise description. Long representations (and long Strings) are abbreviated if they are longer than Debug.printLength, or deeper than Debug.printDepth. Complex objects and abbreviated objects are presented as links. Clicking on the link will invoke LzDebugService.inspect() on the object, giving more detail.
Parameter Name Type Description
any [*] One or more values to display. Multiple values are separated by spaces, so Debug.write("The answer is:", 39+3) will display: The answer is: 42

Methods inherited from <formatter>

abbreviate, formatToString, pad

LzBootstrapDebugService (private) »

Events

LzBootstrapDebugService (private) »