HTTP logging

  • Revision slug: HTTP_Logging
  • Revision title: HTTP Logging
  • Revision id: 345307
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment copy-edit, rewrite of parts, and clean-up

Revision Content

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 {{anch("Logging HTTP activity")}} provides basic instructions that can be used by non-technical users.

More advanced users may want to refer to {{anch("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.

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.

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.

Windows

Figure 1—Windows commands to begin HTTP logging (32-bit Windows).
cd c:\
set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
set NSPR_LOG_FILE=%TEMP%\log.txt
cd "Program Files\Mozilla Firefox"
C:\Program Files\Mozilla Firefox\ .\firefox.exe
Figure 2—Windows commands to begin HTTP logging (64-bit Windows).
cd c:\
set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
set NSPR_LOG_FILE=%TEMP%\log.txt
cd "Program Files\Mozilla Firefox"
C:\Program Files (x86)\Mozilla Firefox\ .\firefox.exe
  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 each line of text from the box in Figure 1 (for 32-bit Windows) or Figure 2 (for 64-bit Windows) into the "Run" command window. Press the enter key after each one. 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.

Figure 3—Linux commands to begin HTTP logging.
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=/tmp/log.txt
cd /path/to/firefox
./firefox
  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 commands in Figure 3 into the shell. Make sure to hit enter after each line.
  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.

Figure 4—Mac OS X commands to begin HTTP logging.
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=~/Desktop/log.txt
cd /Applications/Firefox.app/Contents/MacOS
./firefox-bin
  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 each line from Figure 4 into the Terminal window, hitting the return key after each line. 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.

Figure 5—Commands to begin logging on a Firefox OS device.
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=/data/local/tmp/myLogFile
stop b2g
/system/bin/b2g.sh
  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 commands in Figure 5 into the phone's shell. This will enable logging, then restart the b2g service.
  5. You may want to use separate log files for each process; this is covered in {{anch("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

When multiple processes are used, output may be garbled or lost on some operating systems or file systems. You might also be interested only in the log output for specific processes. This section covers how to do that.

Note: You don't need to read this unless you're running Firefox OS, debugging HTTP usage by plug-ins on standard Firefox, or are otherwise using separate child/parent processes in your Mozilla-based software (in Mozilla terminology, if you're using electrolysis, which is also referred to as "e10s").

To get a separate log file for each process, set GECKO_SEPARATE_NSPR_LOGS to 1.

On Mac OS X and Linux:

export GECKO_SEPARATE_NSPR_LOGS=1

On Windows:

set GECKO_SEPARATE_NSPR_LOGS=1

If you set this option, each child process gets logged to its own file; each file has the same name you specify in the NSPR_LOG_FILE option, but with the string ".child-X" appended to it, where X is a different number for each child process.

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

Exclusing specific portions of HTTP activity

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

Logging only HTTP request and response headers

There are two ways to do this:

  1. Replace NSPR_LOG_MODULES=nsHttp:5 with NSPR_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.

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 NSPR_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
  • Last Updated Date: January 5, 2007
  • Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | Details.

{{ languages( { "ja": "ja/HTTP_Logging" } ) }}

Revision Source

<p>Sometimes, while debugging your Web app (or client-side code using Necko), it can be useful to log <a href="/en-US/docs/HTTP" title="/en-US/docs/HTTP">HTTP</a> traffic. This article provides useful information on how to do this using the tools built into Firefox. The section {{anch("Logging HTTP activity")}} provides basic instructions that can be used by non-technical users.</p>
<p>More advanced users may want to refer to {{anch("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.</p>
<div class="note">
  <p><strong>Note:</strong> 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.</p>
</div>
<h2>Logging HTTP activity</h2>
<p>The instructions in this section provide basic information on how to log HTTP activity on each of the major platforms supported by Firefox.</p>
<h3>Windows</h3>
<div class="standardSidebar">
  <strong>Figure 1—Windows commands to begin HTTP logging (32-bit Windows).</strong>
  <pre>
cd c:\
set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
set NSPR_LOG_FILE=%TEMP%\log.txt
cd "Program Files\Mozilla Firefox"
C:\Program Files\Mozilla Firefox\ .\firefox.exe</pre>
</div>
<div class="standardSidebar">
  <strong>Figure 2—Windows commands to begin HTTP logging (64-bit Windows).</strong>
  <pre>
cd c:\
set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
set NSPR_LOG_FILE=%TEMP%\log.txt
cd "Program Files\Mozilla Firefox"
C:\Program Files (x86)\Mozilla Firefox\ .\firefox.exe</pre>
</div>
<ol>
  <li>If Firefox is already running, exit out of it.</li>
  <li>Open a command prompt. On <a href="http://commandwindows.com/runline.htm" title="http://commandwindows.com/runline.htm">Windows XP</a>, you can find the "Run..." command in the Start menu's "All Programs" submenu. On <a href="http://www.xp-vista.com/other/where-is-run-in-windows-vista" title="http://www.xp-vista.com/other/where-is-run-in-windows-vista">all newer versions of Windows</a>, you can hold down the Windows key and press "R".</li>
  <li>Copy and paste each line of text from the box in Figure 1 (for 32-bit Windows) or Figure 2 (for 64-bit Windows) into the "Run" command window. Press the enter key after each one. 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.</li>
  <li>Reproduce whatever problem it is that you're having.</li>
  <li>Once you've reproduced the problem, exit Firefox and look for the generated log file. This file, called <code>log.txt</code>, should be in your temporary directory. You can type "%TEMP%" directly into the Windows Explorer location bar to get there quickly.</li>
</ol>
<h3>Linux</h3>
<p>This section offers information on how to capture HTTP logs for Firefox running on Linux.</p>
<div class="standardSidebar">
  <strong>Figure 3—Linux commands to begin HTTP logging.</strong>
  <pre>
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=/tmp/log.txt
cd /path/to/firefox
./firefox
</pre>
</div>
<ol>
  <li>Quit out of Firefox if it's running.</li>
  <li>Open a new shell. The commands listed here assume a bash-compatible shell.</li>
  <li>Copy and paste the commands in Figure 3 into the shell. Make sure to hit enter after each line.</li>
  <li>Reproduce the problem you're debugging.</li>
  <li>When the problem has been reproduced, exit Firefox and look for the generated log file, which you can find at <code>/tmp/log.txt</code>.</li>
</ol>
<h3>Mac OS X</h3>
<p>These instructions show how to log HTTP traffic in Firefox on Mac OS X.</p>
<div class="standardSidebar">
  <strong>Figure 4—Mac OS X commands to begin HTTP logging.</strong>
  <pre>
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=~/Desktop/log.txt
cd /Applications/Firefox.app/Contents/MacOS
./firefox-bin
</pre>
</div>
<ol>
  <li>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 <strong>not</strong> quit Firefox on Mac OS X (this is standard practice for Mac applications).</li>
  <li>Run the Terminal application, which is located in the Utilities subfolder in your startup disk's Applications folder.</li>
  <li>Copy and paste each line from Figure 4 into the Terminal window, hitting the return key after each line. 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.</li>
  <li>Reproduce whatever problem you're trying to debug.</li>
  <li>Quit Firefox and look for the generated <code>log.txt</code> log file on your desktop.</li>
</ol>
<div class="note">
  <p><strong>Note:</strong> 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.</p>
</div>
<h3>Firefox OS phones</h3>
<p>If you need to log HTTP traffic on a Firefox OS (Boot to Gecko) phone, you can do that too.</p>
<div class="standardSidebar">
  <strong>Figure 5—Commands to begin logging on a Firefox OS device.</strong>
  <pre>
export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
export NSPR_LOG_FILE=/data/local/tmp/myLogFile
stop b2g
/system/bin/b2g.sh
</pre>
</div>
<ol>
  <li><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Firefox_OS_build_prerequisites#Install_adb" title="https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Firefox_OS_build_prerequisites#Install_adb">Install the adb software</a> for your platform if you haven't already done so.</li>
  <li>Connect the phone to your computer using a USB cable.</li>
  <li>Open a root shell on the phone by using the command <code>adb shell</code>.</li>
  <li>Enter the commands in Figure 5 into the phone's shell. This will enable logging, then restart the b2g service.</li>
  <li>You may want to use separate log files for each process; this is covered in {{anch("Creating separate logs for child processes")}}.</li>
</ol>
<div class="note">
  <p><strong>Note:</strong> If you have any problems, see <a href="/en-US/docs/Mozilla/Boot_to_Gecko/Debugging_on_Boot_to_Gecko/Customizing_the_b2g.sh_script" title="/en-US/docs/Mozilla/Boot_to_Gecko/Debugging_on_Boot_to_Gecko/Customizing_the_b2g.sh_script">Customizing the b2g.sh script</a> for more information.</p>
</div>
<h3 id="Creating_separate_logs_for_child_processes_(electrolysis-only)">Creating separate logs for child processes</h3>
<p>When multiple processes are used, output may be garbled or lost on some operating systems or file systems. You might also be interested only in the log output for specific processes. This section covers how to do that.</p>
<div class="note">
  <p><strong>Note:</strong> You don't need to read this unless you're running Firefox OS, debugging HTTP usage by plug-ins on standard Firefox, or are otherwise using separate child/parent processes in your Mozilla-based software (in Mozilla terminology, if you're using <strong>electrolysis</strong>, which is also referred to as "e10s").</p>
</div>
<p>To get a separate log file for each process, set <code>GECKO_SEPARATE_NSPR_LOGS</code> to 1.</p>
<p>On Mac OS X and Linux:</p>
<pre>
export GECKO_SEPARATE_NSPR_LOGS=1</pre>
<p>On Windows:</p>
<pre>
set GECKO_SEPARATE_NSPR_LOGS=1</pre>
<p>If you set this option, each child process gets logged to its own file; each file has the same name you specify in the <code>NSPR_LOG_FILE</code> option, but with the string ".child-X" appended to it, where X is a different number for each child process.</p>
<div class="note">
  <p><strong>Note:</strong> On Firefox OS, child processes are only allowed to open files in <code>/data/local/tmp</code>, so you must be sure to set <code>NSPR_LOG_FILE</code> to a file in that directory; otherwise, the child processes won't be able to write their log files.</p>
</div>
<h2>Exclusing specific portions of HTTP activity</h2>
<p>You can adjust some of the settings listed above to change what parts of HTTP transactions get logged.</p>
<h4>Logging only HTTP request and response headers</h4>
<p>There are two ways to do this:</p>
<ol>
  <li>Replace <code>NSPR_LOG_MODULES=nsHttp:5</code> with <code>NSPR_LOG_MODULES=nsHttp:3</code> in the commands above.</li>
  <li>There's a handy extension for Firefox called <a href="https://addons.mozilla.org/firefox/addon/3829" title="https://addons.mozilla.org/firefox/addon/3829">Live HTTP Headers</a> 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.</li>
</ol>
<h4>Turning off logging of socket-level transactions</h4>
<p>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 <code>nsSocketTransport:5</code> from the commands above.</p>
<h4>Turning off DNS query logging</h4>
<p>You can turn off logging of host resolving (that is, DNS queries) by removing the text <code>nsHostResolver:5</code> from the commands above.</p>
<h2 id="See_also">See also</h2>
<ul style="margin: 0px 0px 1.7em 25px; padding: 0px;">
  <li style="margin-bottom: 0.25em; ">There are similar options available to debug mailnews protocols. See&nbsp;<a class="external" href="http://www.mozilla.org/quality/mailnews/mail-troubleshoot.html">this document</a>&nbsp;for more info about mailnews troubleshooting.</li>
  <li style="margin-bottom: 0.25em; ">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&nbsp;<code style="color: rgb(37, 34, 29); font-weight: inherit; ">NSPR_LOG_MODULES=nsFtp:5</code>&nbsp;(in older versions of Mozilla, you need to use&nbsp;<code style="color: rgb(37, 34, 29); font-weight: inherit;">nsFTPProtocol</code>&nbsp;instead of&nbsp;<code style="color: rgb(37, 34, 29); font-weight: inherit;">nsFtp</code>).</li>
  <li style="margin-bottom: 0.25em; ">When Mozilla's built-in logging capabilities aren't good enough, and you need a full-fledged packet tracing tool,&nbsp;two free products are <a class="external" href="http://www.wireshark.org/" title="http://www.wireshark.org/">Wireshark</a> and&nbsp;<a class="external" href="http://ngrep.sourceforge.net/">ngrep</a>. They are available for Windows and most flavors of UNIX (including Linux and Mac OS X),&nbsp;are rock solid, and offer enough features to help uncover any Mozilla networking problem.</li>
</ul>
<div class="originaldocinfo">
  <h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2>
  <ul>
    <li>Author(s): <a class="link-mailto" href="mailto:darin@meer.net">Darin Fisher</a></li>
    <li>Last Updated Date: January 5, 2007</li>
    <li>Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | <a class="external" href="http://www.mozilla.org/foundation/licensing/website-content.html">Details</a>.</li>
  </ul>
</div>
<p>{{ languages( { "ja": "ja/HTTP_Logging" } ) }}</p>
Revert to this revision