mozilla

Revision 522537 of On-device console logging

  • Revision slug: Mozilla/Firefox_OS/Debugging/On-device_console_logging
  • Revision title: On-device console logging
  • Revision id: 522537
  • Created:
  • Creator: chrisdavidmills
  • Is current revision? No
  • Comment

Revision Content

In addition to being able to log console output and view it using the remote web console, you can log console output into the device's onboard file store, then retrieve the logs later from your computer using the logcat utility and a USB connection. This article covers how to enable this feature, how to perform the logging, and how to retrieve the logs.

Enabling console logging

On production builds of Firefox OS, console logging (for example {{domxref("console.log()")}}) is disabled by default. In order to enable it, go to your device's Developer settings and enable the Console Enabled preference.

Logging

Once logging has been enabled, it works just like logging on desktop Firefox OS. You simply use the methods on the {{domxref("console")}} object to log text to the console. For example:

console.info("Starting up the foobar hardware!");
var err = foobar.start();
if (err) {
  console.error("--Error %d starting up the foobar hardware!", err);
}

Note: See {{domxref("console")}} for details on logging features available to you.

Using logcat

Because the log output is stored on the Firefox OS device, and there isn't currently any user interface for viewing these logs on the device, you'll need to fetch them to a computer for review. You'll need to use the logcat command from adb, which is part of the Android SDK (see Installing ADB).

Fortunately, using the logcat is simple: once adb is installed and your device is connected to your computer via USB, you can use from the terminal like this:

adb logcat

This should result in the device's log (stored at /dev/log/system/) being output into the terminal. For example

I/Vold    (  107): Vold 2.1 (the revenge) firing up
D/Vold    (  107): Volume sdcard state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    (  107): Volume emmc state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    (  107): Volume sdcard state changing 0 (No-Media) -> 2 (Pending)
D/Vold    (  107): Volume sdcard state changing 2 (Pending) -> 1 (Idle-Unmounted)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
D/Vold    (  107): Volume emmc state changing 0 (No-Media) -> 2 (Pending)
D/Vold    (  107): Volume emmc state changing 2 (Pending) -> 1 (Idle-Unmounted)
D/VoldCmdListener(  107): volume list
D/VoldCmdListener(  107): volume mount sdcard
I/Vold    (  107): /dev/block/vold/179:20 being considered for volume sdcard
D/Vold    (  107): Volume sdcard state changing 1 (Idle-Unmounted) -> 3 (Checking)
W/Vold    (  107): Skipping fs checks
I/Vold    (  107): Device /dev/block/vold/179:20, target /mnt/sdcard mounted @ /mnt/secure/staging
D/Vold    (  107): Volume sdcard state changing 3 (Checking) -> 4 (Mounted)
D/VoldCmdListener(  107): volume mount emmc
I/Vold    (  107): /dev/block/vold/179:33 being considered for volume emmc
D/Vold    (  107): Volume emmc state changing 1 (Idle-Unmounted) -> 3 (Checking)
W/Vold    (  107): Skipping fs checks
I/Vold    (  107): Device /dev/block/vold/179:33, target /mnt/emmc mounted @ /mnt/secure/staging
D/Vold    (  107): Volume emmc state changing 3 (Checking) -> 4 (Mounted)

etc.

Revision Source

<div class="summary">
 <p><span class="seoSummary">In addition to being able to log console output and view it using the <a href="/en-US/docs/Mozilla/Firefox_OS/Debugging/Using_the_Remote_Web_Console" title="/en-US/docs/Mozilla/Firefox_OS/Debugging/Using_the_Remote_Web_Console">remote web console</a>, you can log console output into the device's onboard file store, then retrieve the logs later from your computer using the <a href="http://developer.android.com/tools/help/logcat.html" title="http://developer.android.com/tools/help/logcat.html"><code>logcat</code></a> utility and a USB connection. This article covers how to enable this feature, how to perform the logging, and how to retrieve the logs.</span></p>
</div>
<h2 id="Enabling_console_logging">Enabling console logging</h2>
<p>On production builds of Firefox OS, console logging (for example {{domxref("console.log()")}}) is disabled by default. In order to enable it, go to your device's <a href="/en-US/Firefox_OS/Debugging/Developer_settings">Developer settings</a> and enable the <em>Console Enabled</em> preference.</p>
<h2 id="Logging">Logging</h2>
<p>Once logging has been enabled, it works just like logging on desktop Firefox OS. You simply use the methods on the {{domxref("console")}} object to log text to the console. For example:</p>
<pre class="brush: js">
console.info("Starting up the foobar hardware!");
var err = foobar.start();
if (err) {
  console.error("--Error %d starting up the foobar hardware!", err);
}
</pre>
<div class="note">
 <p><strong>Note</strong>: See {{domxref("console")}} for details on logging features available to you.</p>
</div>
<h2 id="Using_logcat">Using logcat</h2>
<p>Because the log output is stored on the Firefox OS device, and there isn't currently any user interface for viewing these logs on the device, you'll need to fetch them to a computer for review. You'll need to use the <code>logcat</code> command from <code>adb</code>, which is part of the Android SDK (see <a href="/en-US/Firefox_OS/Debugging/Installing_ADB">Installing ADB</a>).</p>
<p>Fortunately, using the <code>logcat</code> is simple: once <code>adb</code> is installed and your device is connected to your computer via USB, you can use from the terminal like this:</p>
<pre class="brush: bash">
adb logcat</pre>
<p>This should result in the device's log (stored at <code>/dev/log/system/</code>) being output into the terminal. For example</p>
<pre class="brush: bash">
I/Vold    (  107): Vold 2.1 (the revenge) firing up
D/Vold    (  107): Volume sdcard state changing -1 (Initializing) -&gt; 0 (No-Media)
D/Vold    (  107): Volume emmc state changing -1 (Initializing) -&gt; 0 (No-Media)
D/Vold    (  107): Volume sdcard state changing 0 (No-Media) -&gt; 2 (Pending)
D/Vold    (  107): Volume sdcard state changing 2 (Pending) -&gt; 1 (Idle-Unmounted)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
W/Vold    (  107): Duplicate state (1)
D/Vold    (  107): Volume emmc state changing 0 (No-Media) -&gt; 2 (Pending)
D/Vold    (  107): Volume emmc state changing 2 (Pending) -&gt; 1 (Idle-Unmounted)
D/VoldCmdListener(  107): volume list
D/VoldCmdListener(  107): volume mount sdcard
I/Vold    (  107): /dev/block/vold/179:20 being considered for volume sdcard
D/Vold    (  107): Volume sdcard state changing 1 (Idle-Unmounted) -&gt; 3 (Checking)
W/Vold    (  107): Skipping fs checks
I/Vold    (  107): Device /dev/block/vold/179:20, target /mnt/sdcard mounted @ /mnt/secure/staging
D/Vold    (  107): Volume sdcard state changing 3 (Checking) -&gt; 4 (Mounted)
D/VoldCmdListener(  107): volume mount emmc
I/Vold    (  107): /dev/block/vold/179:33 being considered for volume emmc
D/Vold    (  107): Volume emmc state changing 1 (Idle-Unmounted) -&gt; 3 (Checking)
W/Vold    (  107): Skipping fs checks
I/Vold    (  107): Device /dev/block/vold/179:33, target /mnt/emmc mounted @ /mnt/secure/staging
D/Vold    (  107): Volume emmc state changing 3 (Checking) -&gt; 4 (Mounted)

etc.
</pre>
Revert to this revision