How to log each G-code line read from the SD card to serial on marlin firmware
If you have the hardware at hand, you can use OctoPrint to collect the data you require. It's common for users to create an OctoPrint server on a Raspberry Pi, but it can be installed easily on a Windows or Linux machine as well. Once in place, logging is available for various types of information.
From the OctoPrint blog:
The logs are crucial instruments of analysis and debugging, so it's usually in your best interest to provide them when asking for help or reporting a bug, even if not explicitly prompted for them:

octoprint.log: OctoPrint's main application log file. Contains a
general log of everything that happens while OctoPrint is running.
Includes version information, installed plugins and a myriad of more
data points.
This must always be included when reporting a bug 47 to allow for
further analysis and reproduction. It is also a very good idea to
provide this when asking for help :wink:
serial.log: A log of all of the communication going on between
OctoPrint and your printer. Usually disabled for performance reasons,
enable it through Settings &gt; Serial Connection.
Either that or at the very least the output in OctoPrint's Terminal
tab is crucial for analysis of any kind of communication issues or
misbehaviours observed with your printer, so it's important to include
it when discussing such issues.
plugin_pluginmanager_console.log: A log of the command line activity
of the plugin manager. Very important for analysis of such questions
like &quot;Why can't I install plugin $xyz?&quot;, so if you have such a
problem, best include this.
plugin_softwareupdate_console.log: A log of the command line activity
of the software updater. Very important for analysis of such questions
like &quot;Updating OctoPrint always fails, why?&quot;, so if you have such a
problem, best include this.

Third party plugins might also have special log files here. If a plugin author asks you to provide a special log created by their plugin for further analysis, this should be where you can find it.
The above selection is from the linked site, which also includes embedded links for more information regarding the log files. Note that serial.log is specifically referenced to collect data between OctoPrint and your printer, although it defaults to disabled on install.