HTTP Logging
From MDC
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:
Contents |
[edit] Enabling HTTP logging
[edit] Windows
Make sure Firefox is not running. Then open a DOS prompt, and type the following (this example assumes that you have installed Firefox 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 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: C:\log.txt
[edit] 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
[edit] 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.
[edit] Other options
- If you were only interested in logging HTTP request/response headers, then set
NSPR_LOG_MODULES=nsHttp:3only. -
nsSocketTransport:5can 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:5can 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.
[edit] 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 usensFTPProtocolinstead ofnsFtp).
[edit] 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.