On Dec 20, 3:38 pm, Adam Atlas <[EMAIL PROTECTED]> wrote:
> On 19 Dec 2007, at 23:32, Tzury Bar Yochay wrote:
>
> > is that means we will get back the print to behave as 'normal' stdout
> > - thus printing to the console (for debugging)?
>
> You should call web.debug() for debugging. Printing to stdout will  
> work if you're running it with the built-in CherryPy HTTP server, but  
> that won't work on mod_wsgi, fastcgi, etc. If you use web.debug(),  
> then it should always be printed to the server log, whether that's the  
> console or some Apache log file or whatever else.

FWIW, the reason why 'print' (without specifying an output stream)
should not be used for debugging output is that by doing so your WSGI
application is technically not portable. In particular it would
typically not work with any WSGI adapter that used stdin/stdout as the
means of communicating with the web server. For example, CGI works
this way. Thus, using 'print' to stdout would interleave output with
the response content and probably produce a malformed HTTP response.

Technically a CGI-WSGI could be implemented to avoid this problem by
creating an alias to sys.stdout for its own use and then remapping
sys.stdout to sys.stderr, but not CGI-WSGI adapter I have ever seen
does that.

Because using stdout would reduce portability of a WSGI application
mod_wsgi specifically restricts the ability to use sys.stdout by
default and will raise an error if you do so. In other words, mod_wsgi
makes it break so you will not do it and fix your code instead. If for
some reason the code couldn't be changed, there are ways with mod_wsgi
to disable the restriction, in which case output to stdout would then
appear in the Apache error log.

If you just find 'print' to convenient, then at least instead write it
as:

  import sys
  print >> sys.stderr, "log message"

By specifically directing it to stderr instead, you have more
guarantee that it will end up in the log file for what ever hosting
system you are using.

Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to