Handling the log in BaseHTTPServer

LehH Sdsk8 leandrodsferreira at gmail.com
Wed May 4 12:09:17 EDT 2011


On 4 maio, 12:55, Tapi <t... at syskall.net> wrote:
> Hi,
>
> You may create a subclass of (or Mixin for) BaseHTTPRequestHandler to
> override its log_message() method.
> Here's a really simple example ; it's perfectible, but it should show
> you the way :
>
> class MyLoggingHTTPRequestHandler(BaseHTTPRequestHandler):
>      def log_message(self, format, *args):
>          open(LOGFILE, "a").write("%s - - [%s] %s\n" %
>                           (self.address_string(),
>                            self.log_date_time_string(),
>                            format%args))
>
> httpd = HTTPServer(ADDR, MyLoggingHTTPRequestHandler)
> httpd.serve_forever()
>
> Simon
>
>
>
>
>
>
>
> On Wed, 4 May 2011 03:52:29 -0700 (PDT), LehH Sdsk8 wrote:
> > First, i'm sorry for any inglish error!
>
> > So, i use the BaseHTTPServer to create a page for monitoring
> > purposes,
> > someone now how to direct the event log to a file?

Thanks dude, this really works, my class is a subclass of
basehttprequesthandler, the only thing i have to do is put this
function inside.

Thanks.



More information about the Python-list mailing list