0

I am trying to make a python program that others on my team can use without me having to make a GUI. Thus, it is important that the code they interface is super simple and intuitive to the users. I don't want to put logging code in the main program because I think it would confuse them and I don't know what kind of errors they will produce in the main. Is there a way to route ALL errors and warnings (that would be default be printed to STOUT) to a log file without using python logging module ?

Josiah Coad
  • 325
  • 4
  • 11
  • Any reason you don't want to use the logging module? – lonewaft Aug 10 '16 at 17:13
  • 1
    Your reasons to not use "logging code" do not make sense. You control what kind of errors can happen, and you should handle these errors. If the program does not output warnings/errors to the user, but to a log file - it's not a "super simple and intuitive" interface.. – handle Aug 10 '16 at 17:13
  • I don't think the occasional `info('Doing X, Y, and Z...')` is too mysterious, since the strings almost document themselves. But if you insist... What operating system(s) will this program run on? Some have logging services built-in, and command-line shells that make redirecting `stdout` and `stderr` easy. So create a wrapper script that calls your Python program after redirecting its outputs. (If your program is silent when successful, you could just capture and log _all_ its outputs, on the assumption that anything it reports must be an error.) – Kevin J. Chase Aug 10 '16 at 17:30
  • I don't know what kind of error the user might create when using it. So I want to be able to catch the error/bug in a log whatever it might be for my review. – Josiah Coad Aug 16 '16 at 19:51

1 Answers1

-1

You may want to check this question: Capture stdout from a script in Python

[edit]removed the code snippept, because it is all there (sorry missed the python 3 examples there)

Community
  • 1
  • 1
Lars Grundei
  • 101
  • 5