diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/mozilla/add-ons/sdk/tools/console/index.html | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/ru/mozilla/add-ons/sdk/tools/console/index.html')
-rw-r--r-- | files/ru/mozilla/add-ons/sdk/tools/console/index.html | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/files/ru/mozilla/add-ons/sdk/tools/console/index.html b/files/ru/mozilla/add-ons/sdk/tools/console/index.html new file mode 100644 index 0000000000..d28b31d127 --- /dev/null +++ b/files/ru/mozilla/add-ons/sdk/tools/console/index.html @@ -0,0 +1,110 @@ +--- +title: console +slug: Mozilla/Add-ons/SDK/Tools/console +translation_of: Archive/Add-ons/Add-on_SDK/Tools/console +--- +<p><span class="seoSummary">Enables your add-on to log error, warning or informational messages.</span> If you have started Firefox for your add-on from the command line with <code>cfx run</code> or <code>cfx test</code> then these messages appear in the command shell you used. If the add-on has been installed in Firefox, then the messages appear in the <a href="/en-US/docs/Tools/Browser_Console">Browser Console</a>.</p> +<p>If you're developing your add-on using the <a href="https://addons.mozilla.org/en-US/firefox/addon/autoinstaller/">Extension Auto-installer</a>, then the add-on is installed in Firefox, meaning that messages will appear in the Browser Console. But see the discussion of <a href="/en-US/Add-ons/SDK/Tools/console#Logging_Levels">logging levels</a>: by default, messages logged using <code>log()</code>, <code>info()</code>, <code>trace()</code>, or <code>warn()</code> won't be logged in these situations.</p> +<h2 id="Console_Methods">Console Methods</h2> +<p>All console methods except <code>exception()</code> and <code>trace()</code> accept one or more JavaScript objects as arguments and log them to the console. Depending on the console's underlying implementation and user interface, you may be able to examine the properties of non-primitive objects that are logged.</p> +<h3 id="console.debug(object_object_...)"><code>console.debug(<em>object</em>[, <em>object</em>, ...])</code></h3> +<p>Logs the arguments to the console, preceded by "debug:" and the name of your add-on:</p> +<pre class="brush: js">console.debug("This is a debug message");</pre> +<pre>debug: my-addon: This is a debug message +</pre> +<h3 id="console.error(object_object_...)"><code>console.error(<em>object</em>[, <em>object</em>, ...])</code></h3> +<p>Logs the arguments to the console, preceded by "error:" and the name of your add-on:<code> </code></p> +<pre class="brush: js">console.error("This is an error message");</pre> +<pre>error: my-addon: This is an error message +</pre> +<h3 id="console.exception(exception)"><code>console.exception(<em>exception</em>)</code></h3> +<p>Logs the given exception instance as an error, outputting information about the exception's stack traceback if one is available.</p> +<pre class="brush: js">try { + doThing(); +} catch (e) { + console.exception(e); +} + +function UserException(message) { + this.message = message; + this.name = "UserException"; +} + +function doThing() { + throw new UserException("Thing could not be done!"); +}</pre> +<pre>error: my-addon: An exception occurred. +UserException: Thing could not be done! +</pre> +<h3 id="console.info(object_object_...)"><code>console.info(<em>object</em>[, <em>object</em>, ...])</code></h3> +<p>A synonym for <code>console.log()</code>.</p> +<h3 id="console.log(object_object_...)"><code>console.log(<em>object</em>[, <em>object</em>, ...])</code></h3> +<p>Logs the arguments to the console, preceded by "info:" and the name of your add-on:</p> +<pre class="brush: js">console.log("This is an informational message");</pre> +<pre>info: my-addon: This is an informational message +</pre> +<h3 id="console.time(name)"><code>console.time(name)</code></h3> +<p>Starts a timer with a name specified as an input parameter. Up to 10,000 simultaneous timers can run on a given page.</p> +<h3 id="console.timeEnd(name)"><code>console.timeEnd(name)</code></h3> +<p>Stops the specified timer and logs the elapsed time in seconds since its start. See <a href="https://developer.mozilla.org/en-US/docs/Web/API/console#Timers">Timers</a>.</p> +<h3 id="console.trace()"><code>console.trace()</code></h3> +<p>Logs a stack trace at the point the function is called.</p> +<h3 id="console.warn(object_object_...)"><code>console.warn(<em>object</em>[, <em>object</em>, ...])</code></h3> +<p>Logs the arguments to the console, preceded by "warn:" and the name of your add-on:<code> </code></p> +<pre class="brush: js"><code>console.warn("This is a warning message");</code></pre> +<pre>warn: my-addon: This is a warning message +</pre> +<h2 id="Logging_Levels">Logging Levels</h2> +<p>Logging's useful, of course, especially during development. But the more logging there is, the more noise you see in the console output. Especially when debug logging shows up in a production environment, the noise can make it harder, not easier, to debug issues.</p> +<p>This is the problem that logging levels are designed to fix. The console defines a number of logging levels, from "more verbose" to "less verbose", and a number of different logging functions that correspond to these levels, which are arranged in order of "severity" from informational messages, through warnings, to errors.</p> +<p>At a given logging level, only calls to the corresponding functions and functions with a higher severity will have any effect.</p> +<p>For example, if the logging level is set to "info", then calls to <code>info()</code>, <code>log()</code>, <code>warn()</code>, and <code>error()</code> will all result in output being written. But if the logging level is "warn" then only calls to <code>warn()</code> and <code>error()</code> have any effect, and calls to <code>info()</code> and <code>log()</code> are simply discarded.</p> +<p>This means that the same code can be more verbose in a development environment than in a production environment - you just need to arrange for the appropriate logging level to be set.</p> +<p>The complete set of logging levels is given in the table below, along with the set of functions that will result in output at each level:</p> +<table class="standard-table"> + <tbody> + <tr> + <th>Level</th> + <th>Will log calls to:</th> + </tr> + <tr> + <td>all</td> + <td>Any console method</td> + </tr> + <tr> + <td>debug</td> + <td><code>debug(), error(), exception(), info(), log(), time(), timeEnd(), trace(), warn()</code></td> + </tr> + <tr> + <td>info</td> + <td><code>error(), exception(), info(), log(), time(), timeEnd(), trace(), warn()</code></td> + </tr> + <tr> + <td>warn</td> + <td><code>error(), exception(), warn()</code></td> + </tr> + <tr> + <td>error</td> + <td><code>error(), exception()</code></td> + </tr> + <tr> + <td>off</td> + <td>Nothing</td> + </tr> + </tbody> +</table> +<h3 id="Setting_the_Logging_Level">Setting the Logging Level</h3> +<p>The logging level defaults to "error".</p> +<p>There are two system preferences that can be used to override this default:</p> +<ul> + <li> + <p><strong>extensions.sdk.console.logLevel</strong>: if set, this determines the logging level for all installed SDK-based add-ons.</p> + </li> + <li> + <p><strong>extensions.</strong><em>extensionID</em><strong>.sdk.console.logLevel</strong>, where <em>extensionID</em> is an add-on's <a href="/en-US/Add-ons/SDK/Guides/Program_ID">Program ID</a>. If set, this determines the logging level for the specified add-on. This overrides the global preference if both preferences are set.</p> + </li> +</ul> +<p>Both these preferences can be set programmatically using the <a href="/en-US/Add-ons/SDK/Low-Level_APIs/preferences_service"><code>preferences/service</code></a> API, or manually using <a href="http://kb.mozillazine.org/About:config">about:config</a>. The value for each preference is the desired logging level, given as a string.</p> +<p>When you run your add-on using <code>cfx run</code> or <code>cfx test</code>, the global <strong>extensions.sdk.console.logLevel</strong> preference is automatically set to "info". This means that calls to <code>console.log()</code> will appear in the console output.</p> +<p>When you install an add-on into Firefox, the logging level will be "error" by default (that is, unless you have set one of the two preferences). This means that messages written using <code>debug()</code>, <code>log()</code>, <code>info()</code>, <code>trace()</code>, and <code>warn()</code> will not appear in the console.</p> +<p>This includes add-ons being developed using the <a href="https://addons.mozilla.org/en-US/firefox/addon/autoinstaller/">Extension Auto-installer</a>.</p> |