How to log each G-code line read from the SD card to serial on marlin firmware I would like to log each line of G-code to the serial port as it is processed.
Steps to achieve:

the printer reads a file from the SD card
each line it reads will be serial logged (this I can't figure out)
those lines can then read via the serial monitor on a laptop

So by the end of the print, on my laptop I would have the reconstructed G-code file (plus whatever other logs the printer outputs).
The printer runs the Prusa Firmware. Ideally I would like to achieve the logging from altering the firmware rather than adding an extra plugin/server (For understanding and experimenting purposes).
What I tried
I have looked in code and found the print functions and examples of them in use in the code. This line is the &quot;command, which is to be excecuted right now&quot;, but I think that would be the just one command not the full line.
The cardreader or SdBaseFile are where I would expect a G-code line to be read such that I could add a print statement after it but I did not see where.
Would it be as easy as setting this card.logging bool to true?
I imagine this is quite an easy thing to do and that I have just overcomplicated it by trying to understand the firmware. Any advice would be great!
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.