Handling the log in BaseHTTPServer

L

LehH Sdsk8

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?
 
T

Tapi

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
 
L

LehH Sdsk8

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







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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top