How do I redirect all printed text to a file instead of the FrontEnd? This question was answered in Temporarily redirect the output of Print[ ] to a second file, except that this does not capture text printed in subkernels as I encountered when I replaced a Do with a ParellelDo. These prints are not saved in my log and are outputted in the FrontEnd. How do I fix this?
P.S.: The text that is printed by the subkernels does not necessarily have to be printed to the same file (might be problematic with kernels that want to write to the same file simultaneously), as long as it is logged somewhere.
Possible relevant posts are: Local logfiles for remote kernels and How to Export from ParallelDo?, but they are not enough for me to help me construct a solution to this problem.
The texts printed are diagnostics on what computations are being done: e.g. what is the computation, how much time is it taking and how much memory is it using. Not all the code is even written by myself. Thus replacing Print with some other function to collect and export the data is not really feasible. (Except if you mean to do something like Block[{Print=NewPrint}...], or another way where I don't actually need to alter the code. )
Why is it useful to Print to file instead of to the frontend? Firstly, a large amount of printed text output will slow down or freeze the frontend. Dedicated text editors are much better suited for dealing with thousands of lines of text. In addition this makes it much easier to save and efficiently archive (semi-permanent) logs of everything you have run.
Printis not terribly useful: it's almost always easier to collect your results in aListandExportthat. – John Doty Jun 06 '18 at 15:12Print'ed by my codes. – Kvothe Jun 06 '18 at 15:14$Outputdefinition to the other kernels? Also, @JohnDoty is right, why does it have to bePrint? If it's really debug information, it should bePrinted in the first place, right? You can always define your owndebugPrintand swap out it's definition depending on the circumstances – Lukas Lang Jun 06 '18 at 15:32$Output. For the second part I don't really understand. You actually agree that it should be Printed right? Do you mean why I don't want it to be Printed in the FrontEnd, yes maybe I should have answered that (note that the previous asker of the similar question also assumed that the intent would be clear). (cont'ed) – Kvothe Jun 06 '18 at 15:39Printed in ..." - my point (and @JohnDoty's, if I understood correctly) is the following: Why do you usePrintat all? As you said yourself, it's mostly annoying to work with what it produces. If you use your own logging function, you do not need to modify the behavior of a built-in function, which saves you a lot of hassle. Regarding the distribution of$Output: I was suggesting to useDistributeDefinitions, but as I've said, that's probably not the way to go. – Lukas Lang Jun 06 '18 at 15:48debugPrintmight be nice to separate from aEndUserPrintexcept that the programs are never supposed to print anything but diagnostics. So this would just leave Print unused and would achieve the same thing. – Kvothe Jun 06 '18 at 15:58