On-device console logging

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 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 console object to log text to the console. For example:

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 it 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:

Shake to save system log

On Firefox OS 2.2+ there is a developer setting called Shake to save system log. When enabled this allows you to shake your phone to dump the contents of the system log/logcat to the device's SD card, at logs/<datetime>.

Hardware buttons (VolumeUp+sleep) to save system log

For v3.0+ bug 1136777 has added the ability to trigger saving logs by pressing the "volume up" hardware button and sleep button at the same time. (And the somewhat similar "volume down" and sleep will take a screenshot.) This does not require the "shake to save system log" preference to be enabled.