Search code examples
pythonmacosstdoutpy2app

Where does stuff "print" to when not running application from terminal?


So I have a python application that is being bundled into a .app using py2app. I have some debugging print statements in there that would normally print to stdout if I was running the code in the terminal. If I just open the bundled .app, obviously I don't see any of this output. Is any of this actually being printed somewhere even though I don't see it?


Solution

  • It goes to standard output (so in the command line, if you are opening it in command line, or eg. to the log, if you are running it with cron jobs).

    For more advanced and flexible usage try using built-in logging support (logging module). It allows you to direct messages to the console, to the file, stream (like external logging server), syslog process, email etc., as well as filter based on log message level. Debug statements (logging statements) can then be still placed in the production code, but configured to not cause any logging other than errors. Very useful and simplifies logging a lot.