HTTP logging

  • Revision slug: HTTP_Logging
  • Revision title: HTTP Logging
  • Revision id: 345239
  • Created:
  • Creator: jduell
  • Is current revision? No
  • Comment

Revision Content

Jump down to the "Logging HTTP Activity" section for instructions on using Mozilla's built-in logging facility to capture HTTP activity in Firefox, written for people who are unfamiliar with Mozilla (or computers in general).

For more experienced users, see the "Excluding specific portions of HTTP activity" section ↓ for instructions on focusing the log on specific portions of HTTP activity (e.g. HTTP request/response headers, socket level log output, or host resolver log output).  If you are referring a novice to this page, please make clear to them where you want them to perform these variations on the generic instructions. 

The "See also" section ↓ contains non-novice information on HTTP debugging. 

Logging HTTP Activity

Windows

1. Make sure Firefox is not running.

2. Open a command prompt, i.e. the "run" program. (Instructions for XP, Instructions for Vista.)

3. Copy-paste each of the following boldlines into the "run" prompt, hitting enter between them (Make sure the Command Prompt is on the root of the Windows Drive, use "CD C:\" to switch):

  • set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  • set NSPR_LOG_FILE=%TEMP%\log.txt
  • cd "Program Files\Mozilla Firefox"
  • Type the location of Firefox into the run line.  By default, Firefox installs to the following location:
    • For 32-bit Windows, "C:\Program Files\Mozilla Firefox\ .\firefox.exe"
    • For 64-bit Windows, "C:\Program Files (x86)\Mozilla Firefox\ .\firefox.exe"

4. Reproduce whatever problem you're trying to debug.

5. When the problem appears, exit Firefox and look for the generated log file: log.txt in your temp directory (you can type %TEMP% directly into Explorer's location bar to get to your temp directory).

Linux

1. Make sure Firefox is not running.

2. Open a new shell (example assumes bash compatible)

3. Copy-paste, into the shell, each of the following bold lines, hitting enter between each:

  • export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  • export NSPR_LOG_FILE=/tmp/log.txt
  • cd /path/to/firefox
  • ./firefox

4. Reproduce whatever problem you're trying to debug.

5. When the problem appears, exit Firefox and look for the generated log file: /tmp/log.txt

Mac OS X

1. Make sure Firefox is not running.

2. Run the Terminal application (open the Applications folder, then the Utilities folder)

3. Copy-paste each of the following bold lines into Terminal, hitting enter between each:

  • export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  • export NSPR_LOG_FILE=~/Desktop/log.txt
  • Type the location of Firefox.
    • If it's on your Desktop, cd ~/Desktop/Firefox.app/Contents/MacOS
    • If it's in the Applications folder, cd /Applications/Firefox.app/Contents/MacOS
  • ./firefox-bin

4. Reproduce whatever problem you're trying to debug.

5. When the problem appears, quit Firefox and look for the generated log file log.txt on your Desktop.

  • NOTE: the generated log file will have UNIX style line endings, so if you want to view it you will need to use an editor that can handled a UNIX style text file.

Boot2Gecko (B2G) phones

1. open a root shell on the device:

adb shell

#export NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5

#export NSPR_LOG_FILE=/data/local/tmp/myLogFile

2. Restart Boot to Gecko:

#stop b2g

#/system/bin/b2g.sh

Creating separate logs for child processes (electrolysis-only)

Note: You don't need to read this unless you are running Firefox OS, debugging plug-in usage of HTTP on regular Firefox, or are otherwise running Mozilla software using separate child/parent processes (aka electrolysis-"e10s").   When multiple processes are used, output may be lost or garbled on some OSes/filesystems.  In that case, you may set  GECKO_SEPARATE_NSPR_LOGS=1 (do it the same way you set NSPR_LOG_MODULES in the above instructions).  If set, this will make the child process log to a different file (with the same name as your NSPR_LOG_FILE, but with ".child-1", 2, 3, etc.  attached to the end of the name).   Note that in Firefox OS child processes are only allowed to open files in /data/local/tmp, so you must set NSPR_LOG_FILE to a file in that directory else the child process will not be able to write to the log.

Excluding specific portions of HTTP activity

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 enabled. (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 the builtin logging facility of Mozilla is simply not sufficient, 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 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><a href="/en/HTTP_Logging#Logging_HTTP_Activity" title="https://developer.mozilla.org/en/HTTP_Logging#Logging_HTTP_Activity">Jump down to the&nbsp;"Logging HTTP Activity" section</a><strong><span><a href="/en/HTTP_Logging#Logging_HTTP_Activity" title="https://developer.mozilla.org/en/HTTP_Logging#Logging_HTTP_Activity">↓</a> </span></strong>for instructions on using Mozilla's built-in logging facility to capture <a href="/en/HTTP" title="en/HTTP">HTTP</a> activity in Firefox, written for&nbsp;people who are unfamiliar with Mozilla (or computers in general).</p>
<p>For more experienced users, <a href="/en/HTTP_Logging#Excluding_specific_portions_of_HTTP_activity" title="https://developer.mozilla.org/en/HTTP_Logging#Excluding_specific_portions_of_HTTP_activity">see the "Excluding specific portions of HTTP activity" section ↓</a> for instructions on focusing the log on specific portions of HTTP activity (e.g. HTTP request/response headers,&nbsp;socket level log output, or host resolver log output).&nbsp; If you are referring a novice to this page, please make clear to them where you want them to perform these variations on the generic instructions.&nbsp;</p>
<p>The <a href="/en/HTTP_Logging#See_also" title="https://developer.mozilla.org/en/HTTP_Logging#See_also">"See also" section ↓</a> contains non-novice information on HTTP debugging.&nbsp;</p>
<h2 id="Logging_HTTP_Activity"><a name="Logging_HTTP_Activity">Logging HTTP Activity</a></h2>
<p><a name="Logging_HTTP_Activity"> </a></p>
<h3 id="Windows"><a name="Logging_HTTP_Activity">Windows</a></h3>
<p><a name="Logging_HTTP_Activity">1. Make sure Firefox is not running.</a></p>
<p><a name="Logging_HTTP_Activity">2. Open a command prompt, i.e. the "run" program. (</a><a class="external" href="http://commandwindows.com/runline.htm" title="http://commandwindows.com/runline.htm">Instructions for XP</a>, <a class="external" 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">Instructions for Vista</a>.)</p>
<p>3. Copy-paste each of the following <strong><code><span style="font-family: Verdana,Tahoma,sans-serif;">bold</span></code></strong>lines into the "run" prompt, hitting enter between them (Make sure the Command Prompt is on the root of the Windows Drive, use "CD C:\" to switch):</p>
<ul>
  <li><strong><code>set NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsHostResolver:5</code></strong></li>
  <li><strong><code>set NSPR_LOG_FILE=%TEMP%\log.txt</code></strong></li>
  <li><strong><code>cd "Program Files\Mozilla Firefox"</code></strong></li>
  <li>Type the location of Firefox into the run line. &nbsp;By default, Firefox installs to the following location:
    <ul>
      <li>For&nbsp;32-bit Windows, "<strong><code>C:\Program Files\Mozilla Firefox\ .\firefox.exe"</code></strong></li>
      <li>For 64-bit Windows, "<strong><code>C:\Program Files (x86)\Mozilla Firefox\ .\firefox.exe"</code></strong></li>
    </ul>
  </li>
</ul>
<p>4. Reproduce whatever problem you're trying to debug.</p>
<p>5. When the problem appears, exit Firefox and look for the generated log file: <code>log.txt</code> in your temp directory (you can type <code>%TEMP%</code> directly into Explorer's location bar to get to your temp directory).</p>
<h3 id="Linux">Linux</h3>
<p>1. Make sure Firefox is not running.</p>
<p>2. Open a new shell (example assumes bash compatible)</p>
<p>3.&nbsp;Copy-paste, into the shell, each of the following <strong><code><span style="font-family: Verdana,Tahoma,sans-serif;">bold</span></code></strong> lines, hitting enter between each:</p>
<ul>
  <li><strong><code>export NSPR_LOG_MODULES=</code></strong><strong><code>timestamp,</code></strong><strong><code>nsHttp:5,nsSocketTransport:5,nsHostResolver:5</code></strong></li>
  <li><strong><code>export NSPR_LOG_FILE=/tmp/log.txt</code></strong></li>
  <li><strong><code>cd /path/to/firefox</code></strong></li>
  <li><strong><code>./firefox</code></strong></li>
</ul>
<p>4.&nbsp;Reproduce whatever problem you're trying to debug.</p>
<p>5. When the problem appears, exit Firefox and look for the generated log file:&nbsp;/tmp/log.txt</p>
<h3 id="Mac_OS_X">Mac OS X</h3>
<p>1. Make sure Firefox is not running.</p>
<p>2. Run the Terminal application (open the Applications&nbsp;folder, then the Utilities&nbsp;folder)</p>
<p>3.&nbsp;Copy-paste each of the following <strong><code><span style="font-family: Verdana,Tahoma,sans-serif;">bold</span></code></strong> lines into Terminal, hitting enter between each:</p>
<ul>
  <li><strong><code>export NSPR_LOG_MODULES=</code></strong><strong><code>timestamp,</code></strong><strong><code>nsHttp:5,nsSocketTransport:5,nsHostResolver:5</code></strong></li>
  <li><strong><code>export NSPR_LOG_FILE=~/Desktop/log.txt</code></strong></li>
  <li>Type the location of Firefox.
    <ul>
      <li>If it's on your Desktop,&nbsp;<strong><code>cd ~/Desktop/Firefox.app/Contents/MacOS</code></strong></li>
      <li>If it's in the Applications folder,&nbsp;<strong><code>cd /Applications/Firefox.app/Contents/MacOS</code></strong></li>
    </ul>
  </li>
  <li><strong><code>./firefox-bin</code></strong></li>
</ul>
<p>4.&nbsp;Reproduce whatever problem you're trying to debug.</p>
<p>5. When the problem appears, quit Firefox and look for the&nbsp;generated log file <code>log.txt</code> on your Desktop.</p>
<ul>
  <li>NOTE: the generated log file will have UNIX style line endings, so if you want to view it you will need to use an editor that can handled a UNIX style text file.</li>
</ul>
<h3 id="Mac_OS_X">Boot2Gecko (B2G) phones</h3>
<p>1. open a root shell on the device:</p>
<pre>
<strong><code class="brush: bash">adb shell</code></strong>

<strong><code>#export NSPR_LOG_MODULES=</code></strong><strong><code>timestamp,</code></strong><strong><code>nsHttp:5,nsSocketTransport:5,nsHostResolver:5</code></strong>

<strong><code>#export NSPR_LOG_FILE=/data/local/tmp/myLogFile</code></strong></pre>
<p>2. Restart Boot to Gecko:</p>
<pre>
<strong><code class="brush: bash">#</code>stop b2g

#/system/bin/b2g.sh</strong></pre>
<h3 id="Creating_separate_logs_for_child_processes_(electrolysis-only)">Creating separate logs for child processes (electrolysis-only)</h3>
<p><em>Note: You don't need to read this unless you are running Firefox OS, debugging plug-in usage of HTTP on regular Firefox, or are otherwise running Mozilla software using separate child/parent processes (aka electrolysis-"e10s"). </em>&nbsp; When multiple processes are used, output may be lost or garbled on some OSes/filesystems.&nbsp; In that case, you may set&nbsp; <code><strong>GECKO_SEPARATE_NSPR_LOGS=1</strong></code> (do it the same way you set <code>NSPR_LOG_MODULES</code> in the above instructions).&nbsp; If set, this will make the child process log to a different file (with the same name as your <code>NSPR_LOG_FILE</code>, but with ".child-1", 2, 3, etc.&nbsp; attached to the end of the name).&nbsp;&nbsp; Note that in Firefox OS child processes are only allowed to open files in /data/local/tmp, so you must set NSPR_LOG_FILE to a file in that directory else the child process will not be able to write to the log.</p>
<h2 id="Excluding_specific_portions_of_HTTP_activity"><a name="Excluding_specific_portions_of_HTTP_activity">Excluding specific portions of HTTP activity</a></h2>
<p><a name="Excluding_specific_portions_of_HTTP_activity"> </a></p>
<p><a name="Excluding_specific_portions_of_HTTP_activity"> </a></p>
<ul>
  <li><a name="Excluding_specific_portions_of_HTTP_activity">If you are only interested in logging HTTP request/response headers: </a><a name="Excluding_specific_portions_of_HTTP_activity"> </a>
    <ul>
      <li>
        <ul>
          <li><a name="Excluding_specific_portions_of_HTTP_activity">Option one: replace&nbsp;<strong><code>NSPR_LOG_MODULES=nsHttp:5</code></strong>&nbsp;with&nbsp;<strong><code style="color: rgb(37, 34, 29); font-weight: inherit;">NSPR_LOG_MODULES=nsHttp:3</code></strong></a></li>
          <li><a name="Excluding_specific_portions_of_HTTP_activity">Option two: There is also a handy extension for Firefox called&nbsp;</a><a class="link-https" href="https://addons.mozilla.org/firefox/addon/3829">Live HTTP Headers</a>&nbsp;that can be used to capture only the HTTP request/response headers. It is a very handy tool in cases where you want to just peek at HTTP traffic.</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>If you are not interested in socket level log output (perhaps because you are debugging something that is accompanied by a lot of noise at this level):
    <ul>
      <li><code style="color: rgb(37, 34, 29); font-weight: inherit;">Remove&nbsp;</code><strong><code style="color: rgb(37, 34, 29); font-weight: inherit;">nsSocketTransport:5</code>&nbsp;</strong></li>
    </ul>
  </li>
  <li>If you are not interested in host resolver log output (i.e., DNS queries):
    <ul>
      <li><code style="color: rgb(37, 34, 29); font-weight: inherit;">Remove&nbsp;</code><strong><code style="color: rgb(37, 34, 29); font-weight: inherit;">nsHostResolver:5</code></strong></li>
    </ul>
  </li>
</ul>
<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 enabled. (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 the builtin logging facility of Mozilla is simply not sufficient, 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 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