PuTTY doesn’t seem to have a command-line way of turning on logging and specifying a log file in which to output session data. That’s rather annoying, but there is a workaround. This information is stored in the Windows Registry for the Default Session. So if you edit the LogFileName string and LogFileType DWORD values for the Default Session key, you can specify the log file without having to use the GUI. This is helpful in unattended scenarios.
The path to the key is:
The best part is: If you only create the LogFileName string and LogFileType DWORD values, PuTTY will create the rest later. This means you don’t have to create the complete key which contains dozens of different values.
You can use the Windows Registry Editor (the regedit command) to navigate your way to the proper key and create the values. Note that none of the keys will exist if PuTTY has not been run before.
If you want to do it in a completely unattended manner, you can save the values to a .reg file and use the reg import command. Save the text below to a text file named, for example, putty_settings.reg
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings] "LogFileName"="..\\up\\and\\over\\to\\mylogfile.log" "LogType"=dword:00000002
Then import it using the command below.
reg import putty_settings.reg
- The reg import command is very picky about formatting. Make sure the first line of the .reg file is exactly as shown above.
- Backslashes need to be doubled. For example, ..\up\and\over needs to be typed as ..\\up\\and\\over
- I found that All session output is 2, so I set LogType to 2 in the registry. I did not test any other values.
Below is a screenshot of PuTTY before the registry key
Below is a screenshot of PuTTY after the registry key