Difference between revisions of "Monitor"

From FirebugWiki
Jump to: navigation, search
(Added description of syntax, hint for needing help and linked back to Command Line API)
(Added note that logged functions are listed within the Breakpoints side panel)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{needsHelp}}
 
 
 
Turns on logging for all calls to a function.
 
Turns on logging for all calls to a function.
 +
 +
This means whenever that function is called, a log message will be created inside the [[Console Panel]] showing the function name, the parameters and their values.
 +
 +
[[Image:LoggedFunctions.png|thumb|400px|Logged functions listed within the Breakpoints side panel]]
 +
 +
When <code>monitor()</code> is called on a function, the monitor is listed within the [[Breakpoints Side Panel]].
  
 
== Syntax ==
 
== Syntax ==
 
<source lang="javascript">
 
<source lang="javascript">
 
monitor(fn)
 
monitor(fn)
 +
</source>
 +
 +
== Parameters ==
 +
=== fn ===
 +
Function to log calls for. '''(required)'''
 +
 +
== Examples ==
 +
Having the following function:
 +
 +
<source lang="javascript" line="true">
 +
function faculty(n)
 +
{
 +
    if (n==1 || n==0)
 +
        return 1;
 +
 +
    var facNumber = 1;
 +
    for (i = 1; i <= n; i++)
 +
        facNumber *= i;
 +
 +
    return facNumber;
 +
}
 +
</source>
 +
 +
<source lang="javascript">
 +
monitor(faculty)
 +
</source>
 +
 +
This enables logging of calls to the function <code>faculty()</code>. So calling this function like <code>faculty(5)</code>, a log message like the following will be created:
 +
 +
<source lang="javascript">
 +
faculty(n=5)
 
</source>
 
</source>
  
 
== See also ==
 
== See also ==
 +
* [[unmonitor]]
 
* [[Command Line API]]
 
* [[Command Line API]]
 +
 +
[[Category:Firebug]]
 +
[[Category:UI]]
 +
[[Category:API]]

Latest revision as of 00:06, 23 November 2015

Turns on logging for all calls to a function.

This means whenever that function is called, a log message will be created inside the Console Panel showing the function name, the parameters and their values.

Logged functions listed within the Breakpoints side panel

When monitor() is called on a function, the monitor is listed within the Breakpoints Side Panel.

Syntax[edit]

monitor(fn)

Parameters[edit]

fn[edit]

Function to log calls for. (required)

Examples[edit]

Having the following function:

 1 function faculty(n)
 2 {
 3     if (n==1 || n==0)
 4         return 1;
 5 
 6     var facNumber = 1;
 7     for (i = 1; i <= n; i++)
 8         facNumber *= i;
 9 
10     return facNumber;
11 }
monitor(faculty)

This enables logging of calls to the function faculty(). So calling this function like faculty(5), a log message like the following will be created:

faculty(n=5)

See also[edit]