Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Sometimes, while debugging your Web app (or client-side code using Necko), it can be useful to log HTTP traffic. This article provides useful information on how to do this using the tools built into Firefox. The section Logging HTTP activity provides basic instructions that can be used by non-technical users.

More advanced users may want to refer to Advanced techniques. This section provides instructions that focus on logging specific portions of HTTP activity, such as request/response headers, socket level logging, or host resolver log output. It also covers how to disable logging of information you don't need, to reduce the "noise" level in your log files.

Note: If you're a developer asking a non-technical user to follow instructions on this page to provide you with debugging information, please be sure to guide them to the right part of the page, and to make it clear when and where to perform any of the more advanced steps if necessary.

The See also section provides links to some additional tools and utilities you may find helpful if the built-in logging features aren't good enough. Also, keep in mind that the Web Console offers the ability to peek at HTTP transactions.

Logging HTTP activity

The instructions in this section provide basic information on how to log HTTP activity on each of the major platforms supported by Firefox. Don't let the scary-looking command line stuff frighten you off; it's not hard at all!

Windows

  1. If Firefox is already running, exit out of it.
  2. Open a command prompt. On Windows XP, you can find the "Run..." command in the Start menu's "All Programs" submenu. On all newer versions of Windows, you can hold down the Windows key and press "R".
  3. Copy and paste the following lines one at a time into the "Run" command window. Press the enter key after each one.:
    For 32-bit Windows:
    cd c:\
    set MOZ_LOG=timestamp,rotate:200,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5 
    set MOZ_LOG_FILE=%TEMP%\log.txt 
    cd "Program Files\Mozilla Firefox"
    .\firefox.exe
    
    For 64-bit Windows:
    cd c:\
    set MOZ_LOG=timestamp,rotate:200,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5
    set MOZ_LOG_FILE=%TEMP%\log.txt
    cd "Program Files (x86)\Mozilla Firefox"
    .\firefox.exe
    (These instructions assume that you installed Firefox to the default location, and that drive C: is your Windows startup disk. Make the appropriate adjustments if those aren't the case.)
  4. Reproduce whatever problem it is that you're having.
  5. Once you've reproduced the problem, exit Firefox and look for the generated log file. This file, called log.txt, should be in your temporary directory. You can type "%TEMP%" directly into the Windows Explorer location bar to get there quickly.

Linux

This section offers information on how to capture HTTP logs for Firefox running on Linux.

  1. Quit out of Firefox if it's running.
  2. Open a new shell. The commands listed here assume a bash-compatible shell.
  3. Copy and paste the following commands into the shell one at a time. Make sure to hit enter after each line.
    export MOZ_LOG=timestamp,rotate:200,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5
    export MOZ_LOG_FILE=/tmp/log.txt
    cd /path/to/firefox
    ./firefox
    
  4. Reproduce the problem you're debugging.
  5. When the problem has been reproduced, exit Firefox and look for the generated log file, which you can find at /tmp/log.txt.

Mac OS X

These instructions show how to log HTTP traffic in Firefox on Mac OS X.

  1. Quit Firefox is if it's currently running, by using the Quit option in the File menu. Keep in mind that simply closing all windows does not quit Firefox on Mac OS X (this is standard practice for Mac applications).
  2. Run the Terminal application, which is located in the Utilities subfolder in your startup disk's Applications folder.
  3. Copy and paste the following commands into the Terminal window, hitting the return key after each line.
    export MOZ_LOG=timestamp,rotate:200,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5
    export MOZ_LOG_FILE=~/Desktop/log.txt
    cd /Applications/Firefox.app/Contents/MacOS
    ./firefox-bin
    
    (The instructions assume that you've installed Firefox directly into your startup disk's Applications folder. If you've put it elsewhere, change the path used on the third line appropriately.)
  4. Reproduce whatever problem you're trying to debug.
  5. Quit Firefox and look for the generated log.txt log file on your desktop.

Note: The generated log file uses Unix-style line endings. Older editors may have problems with this, but if you're using an even reasonably modern Mac OS X application to view the log, you won't have any problems.

Firefox OS phones

If you need to log HTTP traffic on a Firefox OS (Boot to Gecko) phone, you can do that too.

  1. Install the adb software for your platform if you haven't already done so.
  2. Connect the phone to your computer using a USB cable.
  3. Open a root shell on the phone by using the command adb shell.
  4. Enter the following commands into the phone's shell one at a time. This will enable logging, then restart the b2g service.
    export MOZ_LOG=timestamp,rotate:50,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5
    export MOZ_LOG_FILE=/data/local/tmp/myLogFile
    stop b2g
    /system/bin/b2g.sh
    
  5. You may want to use separate log files for each process; this is covered in Creating separate logs for child processes.

Note: If you have any problems, see Customizing the b2g.sh script for more information.

Creating separate logs for child processes

There is no need to do anything special, we do this automatically now.

Note: On Firefox OS, child processes are only allowed to open files in /data/local/tmp, so you must be sure to set MOZ_LOG_FILE to a file in that directory; otherwise, the child processes won't be able to write their log files.

Advanced techniques

You can adjust some of the settings listed above to change what parts of HTTP transactions get logged.

Limiting the size of the logged data

By default there is no limit to the size of log file(s), and they capture the logging throughout the time Firefox runs, from start to finish.  These files can get quite large (gigabytes)!  So we have added a 'rotate:SIZE_IN_MB' option to MOZ_LOG_FILE (we use it in the examples above).  If you are using Firefox >= 51, setting this option saves only the last N megabytes of logging data, which helps keep them manageable in size.  (Unknown modules are ignored, so it's OK to use 'rotate' in your environment even if you're running Firefox <= 50: it will do nothing).

This is accomplished by splitting the log into up to 4 separate files (their filenames have a numbered extension, .0, .1, .2, .3)  The logging back end cycles the files it writes to, while ensuring that the sum of these files’ sizes will never go over the specified limit. 

Note 1: the file with the largest number is not guarantied to be the last file written!  We don’t move the files, we only cycle.  Using the rotate module automatically adds timestamps to the log, so it’s always easy to recognize which file keeps the most recent data.

Note 2: rotate doesn’t support append.  When you specify rotate, on every start all the files (including any previous non-rotated log file) are deleted to avoid any mixture of information.  The append module specified is then ignored.

Use 'sync' if your browser crashes or hangs

By default, HTTP logging buffers messages and only periodically writes them to disk (this is more efficient and also makes logging less likely to interfere with race conditions, etc).  However, if you are seeing your browser crash (or hang) you should add ",sync" to the list of logging modules in your MOZ_LOG_MODULES environment variable.  This will cause each log message to be immediately written (and fflush()'d), which is likely to give us more information about your crash.

Logging only HTTP request and response headers

There are two ways to do this:

  1. Replace MOZ_LOG_MODULES=nsHttp:5 with MOZ_LOG_MODULES=nsHttp:3 in the commands above.
  2. There's a handy extension for Firefox called Live HTTP Headers that you can use to capture just the HTTP request and response headers. This is a useful tool when you want to peek at HTTP traffic.

Turning off logging of socket-level transactions

If you're not interested in socket-level log information, either because it's not relevant to your bug or because you're debugging something that includes a lot of noise that's hard to parse through, you can do that. Simply remove the text nsSocketTransport:5 from the commands above.

Turning off DNS query logging

You can turn off logging of host resolving (that is, DNS queries) by removing the text nsHostResolver:5 from the commands above.

Enable Logging for try server runs

You can enable PR_LOGGING on try by hacking build/automation.py.in, in 'def environment'. For example:

def environment(...

  env['MOZ_LOG_FILE'] = 'nsHttp:5'
  return env

See also

  • There are similar options available to debug mailnews protocols. See this document for more info about mailnews troubleshooting.
  • On the Windows platform, nightly Firefox builds have FTP logging built-in (don't ask why this is only the case for Windows!). To enable FTP logging, just set MOZ_LOG_MODULES=nsFtp:5 (in older versions of Mozilla, you need to use nsFTPProtocol instead of nsFtp).
  • When Mozilla's built-in logging capabilities aren't good enough, and you need a full-fledged packet tracing tool, two free products are Wireshark and ngrep. They are available for Windows and most flavors of UNIX (including Linux and Mac OS X), are rock solid, and offer enough features to help uncover any Mozilla networking problem.

Original Document Information

  • Author(s): Darin Fisher
  • Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | Details.