Thanks to Chris Lovett for developing various tools for PX4/MavLink logging mentioned on this page!
The following command will connect MavLinkTest app to the Simulator and enable logging of all mavlink commands to and from the PX4.
MavLinkTest -server:127.0.0.1:14550 -logdir:d:\temp
Sometimes you will also want to log the "output" from the Simulator that is being sent to the PX4. Specifically this will capture the "hilgps" and "hilsensor" messages that are generated by the Simulator. To do that run this as well:
MavLinkTest -server:127.0.0.1:14389 -logdir:d:\temp\output
You will then see log files organized by date in d:\temp\logs, specifically *input.mavlink and *output.mavlink files.
For MavLink enabled drones, you can also use our Log Viewer to visualize the streams of data.
In SITL mode, please a log file is produced when drone is armed. The SITL terminal will contain the path to the log file, it should look something like this
INFO [logger] Opened log file: rootfs/fs/microsd/log/2017-03-27/20_02_49.ulg
If you are using Pixhawk hardware in HIL mode, then set parameter SYS_LOGGER=1
using QGroundControl. PX4 will write log file on device which you can download at later date using QGroundControl.