logging.rst (14053B)
1 HTTP Logging 2 ============ 3 4 5 Sometimes, while debugging your Web app (or client-side code using 6 Necko), it can be useful to log HTTP traffic. This saves a log of HTTP-related 7 information from your browser run into a file that you can examine (or 8 upload to Bugzilla if a developer has asked you for a log). 9 10 .. note:: 11 12 **Note:** The `Web 13 Console <https://developer.mozilla.org/en-US/docs/Tools/Web_Console>`__ 14 also offers the ability to peek at HTTP transactions within Firefox. 15 HTTP logging generally provides more detailed logging. 16 17 .. _using-about-networking: 18 19 Using about:logging 20 ------------------- 21 22 This is the best and easiest way to do HTTP logging. At any point 23 during while your browser is running, you can turn logging on and off. 24 25 .. note:: 26 27 **Note:** Before Firefox 108 the logging UI used to be located at `about:networking#logging` 28 29 This allows you to capture only the "interesting" part of the browser's 30 behavior (i.e. your bug), which makes the HTTP log much smaller and 31 easier to analyze. 32 33 #. Launch the browser and get it into whatever state you need to be in 34 just before your bug occurs. 35 #. Open a new tab and type in "about:logging" into the URL bar. 36 #. Adjust the list of modules that you want to log: this list has the 37 exact same format as the MOZ_LOG environment variable (see below). 38 Generally the default list is OK, unless a Firefox developer has told 39 you to modify it. 40 41 * For cookie issues, use presets ``Cookies`` 42 * For WebSocket issues, use presets ``WebSockets`` 43 * For HTTP/3 or QUIC issues, use presets ``HTTP/3`` 44 * For other networking issues, use presets ``Networking`` 45 46 #. If instructed to do so by a developer, select `Logging to a file` and 47 note the path to the log file. 48 #. Click on Start Logging. 49 #. Reproduce the bug (i.e. go to the web site that is broken for you and 50 make the bug happen in the browser) 51 #. Click on Stop Logging. 52 #. If logging to the profiler, a new tab will open with the profile. 53 Click `Upload Local Profile` and either upload to the cloud and copy 54 the URL, or download the dump to your local device. Note that 55 unchecking the boxes will sanitize the profile to remove some private 56 information, but that could make it more difficult to diagnose the problem. 57 #. Provide the link or dump to the Firefox developer via bugzilla or email. 58 #. If logging to a file, go to the folder containing the specified log file, 59 and gather all the log files. You will see several files that look like: 60 log.txt-main.1806.moz_log, log.txt-child.1954.moz_log, 61 log.txt-child.1970.moz_log, etc. This is because Firefox now uses 62 multiple processes, and each process gets its own log file. 63 #. For many bugs, the "log.txt-main.moz_log" file is the only thing you need to 64 upload as a file attachment to your Bugzilla bug (this is assuming 65 you're logging to help a firefox developer). Other bugs may require 66 all the logs to be uploaded--ask the developer if you're not sure. 67 #. Pat yourself on the back--a job well done! Thanks for helping us 68 debug Firefox. 69 70 .. note:: 71 72 **Note:** The log may include sensitive data such as URLs and cookies. 73 To protect your privacy, we kindly request you to send the log file or 74 the profiler link directly and confidentially to necko@mozilla.com. 75 76 Logging HTTP activity by manually setting environment variables 77 --------------------------------------------------------------- 78 79 Sometimes the about:logging approach won't work, for instance if your 80 bug occurs during startup, or you're running on mobile, etc. In that 81 case you can set environment variables \*before\* you launch Firefox. 82 Note that this approach winds up logging the whole browser history, so 83 files can get rather large (they compress well :) 84 85 Setting environment variables differs by operating system. Don't let the 86 scary-looking command line stuff frighten you off; it's not hard at all! 87 88 Windows 89 ~~~~~~~ 90 91 #. If Firefox is already running, exit out of it. 92 93 #. Open a command prompt by holding down the Windows key and pressing "R". 94 95 #. Type CMD and press enter, a new Command Prompt window with a black 96 background will appear. 97 98 #. | Copy and paste the following lines one at a time into the Command 99 Prompt window. Press the enter key after each one.: 100 | **For 64-bit Windows:** 101 102 :: 103 104 set MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 105 set MOZ_LOG_FILE=%TEMP%\log.txt 106 "c:\Program Files\Mozilla Firefox\firefox.exe" 107 108 **For 32-bit Windows:** 109 110 :: 111 112 set MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 113 set MOZ_LOG_FILE=%TEMP%\log.txt 114 "c:\Program Files (x86)\Mozilla Firefox\firefox.exe" 115 116 (These instructions assume that you installed Firefox to the default 117 location, and that drive C: is your Windows startup disk. Make the 118 appropriate adjustments if those aren't the case.) 119 120 #. Reproduce whatever problem it is that you're having. 121 122 #. Once you've reproduced the problem, exit Firefox and look for the 123 generated log files in your temporary directory. You can type 124 "%TEMP%" directly into the Windows Explorer location bar to get there 125 quickly. 126 127 Linux 128 ~~~~~ 129 130 This section offers information on how to capture HTTP logs for Firefox 131 running on Linux. 132 133 #. Quit out of Firefox if it's running. 134 135 #. Open a new shell. The commands listed here assume a bash-compatible 136 shell. 137 138 #. Copy and paste the following commands into the shell one at a time. 139 Make sure to hit enter after each line. 140 141 :: 142 143 export MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 144 export MOZ_LOG_FILE=/tmp/log.txt 145 cd /path/to/firefox 146 ./firefox 147 148 #. Reproduce the problem you're debugging. 149 150 #. When the problem has been reproduced, exit Firefox and look for the 151 generated log files, which you can find at ``/tmp/log.txt``. 152 153 macOS 154 ~~~~~ 155 156 These instructions show how to log HTTP traffic in Firefox on macOS. 157 158 #. Quit Firefox is if it's currently running, by using the Quit option 159 in the File menu. Keep in mind that simply closing all windows does 160 **not** quit Firefox on macOS (this is standard practice for Mac 161 applications). 162 163 #. Run the Terminal application, which is located in the Utilities 164 subfolder in your startup disk's Applications folder. 165 166 #. Copy and paste the following commands into the Terminal window, 167 hitting the return key after each line. 168 169 :: 170 171 export MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 172 export MOZ_LOG_FILE=~/Desktop/log.txt 173 cd /Applications/Firefox.app/Contents/MacOS 174 ./firefox 175 176 (The instructions assume that you've installed Firefox directly into 177 your startup disk's Applications folder. If you've put it elsewhere, 178 change the path used on the third line appropriately.) 179 180 #. Reproduce whatever problem you're trying to debug. 181 182 #. Quit Firefox and look for the generated ``log.txt`` log files on your 183 desktop. 184 185 .. note:: 186 187 **Note:** The generated log file uses Unix-style line endings. Older 188 editors may have problems with this, but if you're using an even 189 reasonably modern Mac OS X application to view the log, you won't 190 have any problems. 191 192 Start logging using command line arguments 193 ------------------------------------------ 194 195 Since Firefox 61 it's possible to start logging in a bit simpler way 196 than setting environment variables: using command line arguments. Here 197 is an example for the **Windows** platform, on other platforms we accept 198 the same form of the arguments: 199 200 #. If Firefox is already running, exit out of it. 201 202 #. Open a command prompt. On `Windows 203 XP <https://commandwindows.com/runline.htm>`__, you can find the 204 "Run..." command in the Start menu's "All Programs" submenu. On `all 205 newer versions of 206 Windows <http://www.xp-vista.com/other/where-is-run-in-windows-vista>`__, 207 you can hold down the Windows key and press "R". 208 209 #. | Copy and paste the following line into the "Run" command window and 210 then press enter: 211 | **For 32-bit Windows:** 212 213 :: 214 215 "c:\Program Files (x86)\Mozilla Firefox\firefox.exe" -MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 -MOZ_LOG_FILE=%TEMP%\log.txt 216 217 **For 64-bit Windows:** 218 219 :: 220 221 "c:\Program Files\Mozilla Firefox\firefox.exe" -MOZ_LOG=timestamp,rotate:200,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5 -MOZ_LOG_FILE=%TEMP%\log.txt 222 223 (These instructions assume that you installed Firefox to the default 224 location, and that drive C: is your Windows startup disk. Make the 225 appropriate adjustments if those aren't the case.) 226 227 #. Reproduce whatever problem it is that you're having. 228 229 #. Once you've reproduced the problem, exit Firefox and look for the 230 generated log files in your temporary directory. You can type 231 "%TEMP%" directly into the Windows Explorer location bar to get there 232 quickly. 233 234 Advanced techniques 235 ------------------- 236 237 You can adjust some of the settings listed above to change what HTTP 238 information get logged. 239 240 Limiting the size of the logged data 241 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 242 243 By default there is no limit to the size of log file(s), and they 244 capture the logging throughout the time Firefox runs, from start to 245 finish. These files can get quite large (gigabytes)! So we have added 246 a 'rotate:SIZE_IN_MB' option to MOZ_LOG (we use it in the examples 247 above). If you are using Firefox >= 51, setting this option saves only 248 the last N megabytes of logging data, which helps keep them manageable 249 in size. (Unknown modules are ignored, so it's OK to use 'rotate' in 250 your environment even if you're running Firefox <= 50: it will do 251 nothing). 252 253 This is accomplished by splitting the log into up to 4 separate files 254 (their filenames have a numbered extension, .0, .1, .2, .3) The logging 255 back end cycles the files it writes to, while ensuring that the sum of 256 these files’ sizes will never go over the specified limit. 257 258 Note 1: **the file with the largest number is not guaranteed to be the 259 last file written!** We don’t move the files, we only cycle. Using the 260 rotate module automatically adds timestamps to the log, so it’s always 261 easy to recognize which file keeps the most recent data. 262 263 Note 2: **rotate doesn’t support append**. When you specify rotate, on 264 every start all the files (including any previous non-rotated log file) 265 are deleted to avoid any mixture of information. The ``append`` module 266 specified is then ignored. 267 268 Use 'sync' if your browser crashes or hangs 269 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 270 271 By default, HTTP logging buffers messages and only periodically writes 272 them to disk (this is more efficient and also makes logging less likely 273 to interfere with race conditions, etc). However, if you are seeing 274 your browser crash (or hang) you should add ",sync" to the list of 275 logging modules in your MOZ_LOG environment variable. This will cause 276 each log message to be immediately written (and fflush()'d), which is 277 likely to give us more information about your crash. 278 279 Turning on QUIC logging 280 ~~~~~~~~~~~~~~~~~~~~~~~ 281 282 This can be done by setting `MOZ_LOG` to 283 `timestamp,rotate:200,nsHttp:5,neqo_http3::*:5,neqo_transport::*:5`. 284 285 Logging only HTTP request and response headers 286 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 287 288 There are two ways to do this: 289 290 #. Replace MOZ_LOG\ ``=nsHttp:5`` with MOZ_LOG\ ``=nsHttp:3`` in the 291 commands above. 292 #. There's a handy extension for Firefox called `HTTP Header 293 Live <https://addons.mozilla.org/firefox/addon/3829>`__ that you can 294 use to capture just the HTTP request and response headers. This is a 295 useful tool when you want to peek at HTTP traffic. 296 297 Turning off logging of socket-level transactions 298 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 299 300 If you're not interested in socket-level log information, either because 301 it's not relevant to your bug or because you're debugging something that 302 includes a lot of noise that's hard to parse through, you can do that. 303 Simply remove the text ``nsSocketTransport:5`` from the commands above. 304 305 Turning off DNS query logging 306 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 307 308 You can turn off logging of host resolving (that is, DNS queries) by 309 removing the text ``nsHostResolver:5`` from the commands above. 310 311 Enable Logging for try server runs 312 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 313 314 You can enable logging on try by passing the `env` argument via `mach try`. 315 For example: 316 317 .. note:: 318 319 ``./mach try fuzzy --env "MOZ_LOG=nsHttp:5,SSLTokensCache:5"`` 320 321 How to enable QUIC logging 322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 323 The steps to enable QUIC logging (`QLOG <https://datatracker.ietf.org/doc/draft-ietf-quic-qlog-main-schema/>`__) are: 324 325 #. Go to ``about:config``, search for ``network.http.http3.enable_qlog`` and set it to true. 326 #. Restart Firefox. 327 #. QLOG files will be saved in the ``qlog_$PID`` directory located within your system's temporary directory. 328 #. To visualize the QLOG data, visit https://qvis.quictools.info/. You can upload the QLOG files there to see the visual representation of the flows. 329 330 See also 331 -------- 332 333 - There are similar options available to debug mailnews protocols. 334 See `this 335 document <https://www-archive.mozilla.org/quality/mailnews/mail-troubleshoot.html>`__ for 336 more info about mailnews troubleshooting. 337 - On the Windows platform, nightly Firefox builds have FTP logging 338 built-in (don't ask why this is only the case for Windows!). To 339 enable FTP logging, just set ``MOZ_LOG=nsFtp:5`` (in older versions 340 of Mozilla, you need to use ``nsFTPProtocol`` instead of ``nsFtp``). 341 - When Mozilla's built-in logging capabilities aren't good enough, and 342 you need a full-fledged packet tracing tool, two free products are 343 `Wireshark <https://www.wireshark.org/>`__ 344 and `ngrep <https://github.com/jpr5/ngrep/>`__. They are available 345 for Windows and most flavors of UNIX (including Linux and Mac OS 346 X), are rock solid, and offer enough features to help uncover any 347 Mozilla networking problem.