Skip to content
Jirka Dell'Oro-Friedl edited this page Sep 7, 2022 · 3 revisions

DebugTargets

A common tool for observing the internal function of a web application is to print information to the console. This functionality can be helpful with other targets than the console like the alert box, a textarea on the screen or sending the information over the network to another device or store it in a file. FUDGE implements a class Debug that can route information to these targets. Subclasses of DebugTarget serve the different targets, implemented are at this time DebugConsole, DebugAlert, DebugTextArea. Other target may be implemented in the future.

Setup

Instead of using console.log(...), console.error(...) etc., use Debug.log(...), Debug.error(...). In the standard use case, this routes output to the console. To activate other targets, set filters on the target for the output methods. So a filter for error on DebugAlert, will additionally open the alert box and display the message there, when Debug.error(...) gets called.
To setup multiple filters at once, you can add them with a bitwise or, e.g. Debug.setFilter(DebugAlert, DEBUG_FILTER.WARN | DEBUG_FILTER.ERROR). Single filters can also be added or removed using the corresponding methods.

Drawback

Browsers add a link to output messages in the console, that take the built-in debugger to the line of code that called the console method. Using Debug, these links always point to the class Debug, since this did the call. In order to get interactive links again, set the filter DEBUG_FILTER.WARN on the target DebugConsole. This will print a link to the line that called the method on the class Debug just above the output.

Clone this wiki locally