Re: Logging to stdout and stderr

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: Logging to stdout and stderr

by Robert Brewer-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


doerwalter@... wrote:

> I'm running CherryPy from supervisor, so supervisor handles log file
> rotation for the CherryPy output. With CherryPy-3.1.0beta3 this worked
> flawlessly: The access log got written to stdout and all errors and
> custom logging got written to stderr. But now after updating to
> CherryPy-3.1.0 everything seems to get logged to stderr. Here's the
> script I use for testing this:
>
> import os, optparse
>
> import cherrypy
>
> @cherrypy.expose
> def search(phrase):
>     cherrypy.log(phrase)
>     return phrase
>
> cherrypy.tree.mount(search, script_name="/search")
>
>
> def main(args=None):
>     debug = 0
>     port = 8000
>     threads = 10
>
>     p = optparse.OptionParser(usage="usage: %prog [options]")
>     p.add_option("--debug", dest="debug", help="debug mode (0 or 1;
> default %default)", type="int", default=debug)
>     p.add_option("--port", dest="port", help="port (default
> %default)", type="int", default=port)
>     p.add_option("--threads", dest="threads", help="number of threads
> (non-debug mode only; default %default)", type="int", default=threads)
>
>     (options, args) = p.parse_args(args)
>     if len(args) != 0:
>         p.error("incorrect number of arguments")
>         sys.exit(1)
>
>     configmap = {
>         "server.socket_host": "0.0.0.0",
>         "server.socket_port": options.port,
>         "server.screen": True,
>     }
>     if options.debug:
>         configmap["server.environment"] = "development"
>     else:
>         configmap["server.environment"] = "production"
>         configmap["server.thread_pool"] = options.threads
>
>     cherrypy.config.update(configmap)
>     cherrypy.engine.start()
>
> if __name__ == "__main__":
>     main()
>
> When I start this script with:
>
>     python foo.py >stdout.txt 2>stderr.txt
>
> stdout.txt remains empty and stderr.txt contains all the logging
> output:
>
> [02/Sep/2008:20:27:04] ENGINE Started monitor thread
> '_TimeoutMonitor'.
> [02/Sep/2008:20:27:04] ENGINE Started monitor thread 'Autoreloader'.
> [02/Sep/2008:20:27:04] ENGINE Serving on 0.0.0.0:8000
> [02/Sep/2008:20:27:04] ENGINE Bus STARTED
> [02/Sep/2008:20:27:16]  foo
> 127.0.0.1 - - [02/Sep/2008:20:27:16] "GET /search/foo HTTP/1.1" 200 3
> "" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1)
> Gecko/2008070206 Firefox/3.0.1"
>
> How can I get the old behaviour back (access log to stdout, everything
> else to stderr)?

Unfortunately, the easiest way is:

    cherrypy.log._set_screen_handler(cherrypy.log.access_log, False)
    cherrypy.log._set_screen_handler(cherrypy.log.access_log, True,
stream=sys.stdout)

If you would like the stream to be more easily configurable, or a
different default, please open a ticket and we'll discuss it there.


Robert Brewer
fumanchu@...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Logging to stdout and stderr

by Walter Dörwald-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 28 Sep., 06:09, "Robert Brewer" <fuman...@...> wrote:

> doerwal...@... wrote:
> > I'm running CherryPy from supervisor, so supervisor handles log file
> > rotation for the CherryPy output. With CherryPy-3.1.0beta3 this worked
> > flawlessly: The access log got written to stdout and all errors and
> > custom logging got written to stderr. But now after updating to
> > CherryPy-3.1.0 everything seems to get logged to stderr. Here's the
> > script I use for testing this:
>
> > import os, optparse
>
> > import cherrypy
>
> > @cherrypy.expose
> > def search(phrase):
> >     cherrypy.log(phrase)
> >     return phrase
>
> > cherrypy.tree.mount(search, script_name="/search")
>
> > def main(args=None):
> >     debug = 0
> >     port = 8000
> >     threads = 10
>
> >     p = optparse.OptionParser(usage="usage: %prog [options]")
> >     p.add_option("--debug", dest="debug", help="debug mode (0 or 1;
> > default %default)", type="int", default=debug)
> >     p.add_option("--port", dest="port", help="port (default
> > %default)", type="int", default=port)
> >     p.add_option("--threads", dest="threads", help="number of threads
> > (non-debug mode only; default %default)", type="int", default=threads)
>
> >     (options, args) = p.parse_args(args)
> >     if len(args) != 0:
> >         p.error("incorrect number of arguments")
> >         sys.exit(1)
>
> >     configmap = {
> >         "server.socket_host": "0.0.0.0",
> >         "server.socket_port": options.port,
> >         "server.screen": True,
> >     }
> >     if options.debug:
> >         configmap["server.environment"] = "development"
> >     else:
> >         configmap["server.environment"] = "production"
> >         configmap["server.thread_pool"] = options.threads
>
> >     cherrypy.config.update(configmap)
> >     cherrypy.engine.start()
>
> > if __name__ == "__main__":
> >     main()
>
> > When I start this script with:
>
> >     python foo.py >stdout.txt 2>stderr.txt
>
> > stdout.txt remains empty and stderr.txt contains all the logging
> > output:
>
> > [02/Sep/2008:20:27:04] ENGINE Started monitor thread
> > '_TimeoutMonitor'.
> > [02/Sep/2008:20:27:04] ENGINE Started monitor thread 'Autoreloader'.
> > [02/Sep/2008:20:27:04] ENGINE Serving on 0.0.0.0:8000
> > [02/Sep/2008:20:27:04] ENGINE Bus STARTED
> > [02/Sep/2008:20:27:16]  foo
> > 127.0.0.1 - - [02/Sep/2008:20:27:16] "GET /search/foo HTTP/1.1" 200 3
> > "" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1)
> > Gecko/2008070206 Firefox/3.0.1"
>
> > How can I get the old behaviour back (access log to stdout, everything
> > else to stderr)?
>
> Unfortunately, the easiest way is:
>
>     cherrypy.log._set_screen_handler(cherrypy.log.access_log, False)
>     cherrypy.log._set_screen_handler(cherrypy.log.access_log, True,
> stream=sys.stdout)

This workaround does indeed fix the problem.

> If you would like the stream to be more easily configurable, or a
> different default, please open a ticket and we'll discuss it there.

Done, see http://www.cherrypy.org/ticket/866

Servus,
   Walter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!