mozilla

Revision 13739 of HTTP logging

  • Revision slug: HTTP_Logging
  • Revision title: HTTP Logging
  • Revision id: 13739
  • Created:
  • Creator: Kohei
  • Is current revision? No
  • Comment [[HTTP Debugging (Capturing a HTTP log)]] moved to [[HTTP Logging]]

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? Well, if you have a nightly trunk build of Mozilla, then you can set some environment variables before running Mozilla to capture a log of HTTP activity. Follow these steps for your particular platform:

Enabling HTTP logging

Windows

Make sure Mozilla is not running (be sure that Quick Launch is disabled). Then open a DOS prompt, and type the following (this example assumes that you have installed Mozilla in the default location):

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

C:\> cd "Program Files\mozilla.org\Mozilla"
C:\Program Files\mozilla.org\Mozilla\> .\mozilla.exe

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

Linux

Make sure Mozilla 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$ /path/to/mozilla/mozilla

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

Mac OS X

Make sure Mozilla 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 Mozilla on your desktop and that you are using the default OSX command shell, tcsh):

[mybox:~] user% setenv NSPR_LOG_MODULES nsHttp:5,nsSocketTransport:5,nsHostResolver:5
[mybox:~] user% setenv NSPR_LOG_FILE    ~/log.txt

[mybox:~] user% cd Desktop/Mozilla.app/Contents/MacOS
[mybox:Mozilla.app/Contents/MacOS] user% ./mozilla-bin

If you are using Mac OSX 10.3 or later, then you're most likely using the bash shell instead of tcsh. In that case replace setenv with export.

Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla 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 Mozilla called livehttpheaders 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 mozilla 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.

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?  Well, if you have a <a class="external" href="http://ftp.mozilla.org/pub/mozilla/nightly/latest-trunk">nightly trunk build</a> of Mozilla, then you can set some environment variables before running Mozilla 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 Mozilla is not running (be sure that <a class="external" href="http://www.mozilla.org/projects/ui/communicator/framework/quicklaunch/">Quick Launch</a> is disabled).  Then open a DOS prompt, and type the following (this example assumes that you have installed Mozilla in the default location): 
</p>
<pre>C:\&gt; set NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
C:\&gt; set NSPR_LOG_FILE=C:\log.txt

C:\&gt; cd "Program Files\mozilla.org\Mozilla"
C:\Program Files\mozilla.org\Mozilla\&gt; .\mozilla.exe
</pre>
<p>Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla and look for the generated log file: <code>C:\log.txt</code>
</p>
<h4 name="Linux"> Linux </h4>
<p>Make sure Mozilla 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$ /path/to/mozilla/mozilla
</pre>
<p>Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla 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 Mozilla 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 Mozilla on your desktop and that you are using the default OSX command shell, tcsh):
</p>
<pre>[mybox:~] user% setenv NSPR_LOG_MODULES nsHttp:5,nsSocketTransport:5,nsHostResolver:5
[mybox:~] user% setenv NSPR_LOG_FILE    ~/log.txt

[mybox:~] user% cd Desktop/Mozilla.app/Contents/MacOS
[mybox:Mozilla.app/Contents/MacOS] user% ./mozilla-bin
</pre>
<div class="note">
<p>If you are using Mac OSX 10.3 or later, then you're most likely using the bash shell instead of tcsh.  In that case replace <code>setenv</code> with <code>export</code>.
</p>
</div>
<p>Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla 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 Mozilla called <a class="external" href="http://livehttpheaders.mozdev.org/">livehttpheaders</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 mozilla 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 "nsFTPProtocol" instead of "nsFtp").
</li></ul>
<div class="originaldocinfo">
<h2 name="Original_Document_Information"> Original Document Information </h2>
<ul><li> Author(s): <a class="external" 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>
Revert to this revision