Revision 13742 of HTTP logging

  • Revision slug: HTTP_Logging
  • Revision title: HTTP Logging
  • Revision id: 13742
  • Created:
  • Creator: Sid0
  • Is current revision? No
  • Comment 50 words added, 7 words removed

Revision Content

Ok, so you suspect that Mozilla's HTTP layer is behaving badly, or perhaps someone asked you to capture a HTTP log. What do you do? You can set some environment variables before running Firefox to capture a log of HTTP activity. Follow these steps for your particular platform:

Enabling HTTP logging

Windows

Make sure Firefox is not running. Then open a command prompt, and type the following (this example assumes that you have installed Firefox in the default location on 32-bit Windows. The default location is C:\Program Files (x86)\Mozilla Firefox on 64-bit Windows):

C:\> set NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
C:\> set NSPR_LOG_FILE=%TEMP%\log.txt

C:\> cd "Program Files\Mozilla Firefox"
C:\Program Files\Mozilla Firefox\> .\firefox.exe

Now reproduce whatever problem you're trying to debug, and when you are done exit Firefox and look for the generated log file: log.txt in your temp directory (you can type %TEMP% directly into Explorer to get to your temp directory).

Linux

Make sure Firefox is not running. Then open a new shell (example assumes bash compatible), and type the following:

bash$ export NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
bash$ export NSPR_LOG_FILE=/tmp/log.txt

bash$ cd /path/to/firefox
bash$ ./firefox

Now reproduce whatever problem you're trying to debug, and when you are done exit Firefox and look for the generated log file: /tmp/log.txt

Mac OS X

Make sure Firefox is not running. Then run the Terminal application (found under the Utilities application group), and type the following commands (this example assumes that you have installed Firefox on your desktop and that you are using the default OS X command shell, bash):

hellomac:~ John$ export NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
hellomac:~ John$ export NSPR_LOG_FILE=~/log.txt

hellomac:~ John$ cd /Applications/Firefox.app/Contents/MacOS
hellomac:/Applications/Firefox.app/Contents/MacOS John$ ./firefox-bin

Now reproduce whatever problem you're trying to debug, and when you are done exit Firefox and look for the generated log file log.txt in your home directory. 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.

Other options

  • If you were only interested in logging HTTP request/response headers, then set NSPR_LOG_MODULES=nsHttp:3 only.
  • nsSocketTransport:5 can be removed if you are not interested in socket level log output (there can be a lot of noise from logging at this level depending on what you are trying to debug).
  • nsHostResolver:5 can be removed if you are not interested in host resolver log output (i.e., DNS queries).
  • There is also a handy extension for Firefox called Live HTTP Headers 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.
  • Finally, there are times when the builtin logging facility of Mozilla is simply not sufficient, and one must resort to a full fledged packet tracing tool. Ethereal and ngrep are two excellent tools available for Windows and most flavors of UNIX (not including OSX last I checked). Commercially available packet tracers may offer better features, but for the most part these freely available tracers are rock solid and offer enough features to help uncover any Mozilla networking problem.

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).

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>Ok, so you suspect that Mozilla's HTTP layer is behaving badly, or perhaps someone asked you to capture a HTTP log. What do you do? You can set some environment variables before running Firefox to capture a log of HTTP activity. Follow these steps for your particular platform:
</p>
<h3 name="Enabling_HTTP_logging">Enabling HTTP logging</h3>
<h4 name="Windows">Windows</h4>
<p>Make sure Firefox is not running. Then open a command prompt, and type the following (this example assumes that you have installed Firefox in the default location on 32-bit Windows. The default location is <code>C:\Program Files (x86)\Mozilla Firefox</code> on 64-bit Windows):</p>
<pre>C:\&gt; set NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
C:\&gt; set NSPR_LOG_FILE=%TEMP%\log.txt

C:\&gt; cd "Program Files\Mozilla Firefox"
C:\Program Files\Mozilla Firefox\&gt; .\firefox.exe
</pre>
<p>Now reproduce whatever problem you're trying to debug, and when you are done 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 to get to your temp directory).</p>
<h4 name="Linux">Linux</h4>
<p>Make sure Firefox is not running. Then open a new shell (example assumes bash compatible), and type the following:</p>
<pre>bash$ export NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
bash$ export NSPR_LOG_FILE=/tmp/log.txt

bash$ cd /path/to/firefox
bash$ ./firefox
</pre>
<p>Now reproduce whatever problem you're trying to debug, and when you are done exit Firefox and look for the generated log file: <code>/tmp/log.txt</code></p>
<h4 name="Mac_OS_X">Mac OS X</h4>
<p>Make sure Firefox is not running. Then run the Terminal application (found under the Utilities application group), and type the following commands (this example assumes that you have installed Firefox on your desktop and that you are using the default OS X command shell, bash):</p>
<pre>hellomac:~ John$ export NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
hellomac:~ John$ export NSPR_LOG_FILE=~/log.txt

hellomac:~ John$ cd /Applications/Firefox.app/Contents/MacOS
hellomac:/Applications/Firefox.app/Contents/MacOS John$ ./firefox-bin
</pre>
<p>Now reproduce whatever problem you're trying to debug, and when you are done exit Firefox and look for the generated log file <code>log.txt</code> in your home directory. 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.</p><h3 name="Other_options"> Other options </h3>
<ul><li> If you were only interested in logging HTTP request/response headers, then set <code>NSPR_LOG_MODULES=nsHttp:3</code> only.
</li><li> <code>nsSocketTransport:5</code> can be removed if you are not interested in socket level log output (there can be a lot of noise from logging at this level depending on what you are trying to debug).
</li><li> <code>nsHostResolver:5</code> can be removed if you are not interested in host resolver log output (i.e., DNS queries).
</li><li> There is also a handy extension for Firefox called <a class="link-https" href="https://addons.mozilla.org/firefox/addon/3829">Live HTTP Headers</a> 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><li> Finally, there are times when the builtin logging facility of Mozilla is simply not sufficient, and one must resort to a full fledged packet tracing tool. <a class="external" href="http://www.ethereal.com/">Ethereal</a> and <a class="external" href="http://ngrep.sourceforge.net/">ngrep</a> are two excellent tools available for Windows and most flavors of UNIX (not including OSX last I checked). Commercially available packet tracers may offer better features, but for the most part these freely available tracers are rock solid and offer enough features to help uncover any Mozilla networking problem.
</li></ul>
<h3 name="See_also"> See also </h3>
<ul><li> There are similar options available to debug mailnews protocols. See <a class="external" href="http://www.mozilla.org/quality/mailnews/mail-troubleshoot.html">this document</a> for more info about mailnews troubleshooting.
</li><li> 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 <code>NSPR_LOG_MODULES=nsFtp:5</code> (in older versions of Mozilla, you need to use <code>nsFTPProtocol</code> instead of <code>nsFtp</code>).
</li></ul>
<div class="originaldocinfo">
<h2 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>
<div class="noinclude">
</div>
{{ languages( { "ja": "ja/HTTP_Logging" } ) }}
Revert to this revision