Handling the log in BaseHTTPServer

Discussion in 'Python' started by LehH Sdsk8, May 4, 2011.

  1. LehH Sdsk8

    LehH Sdsk8 Guest

    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?
    LehH Sdsk8, May 4, 2011
    #1
    1. Advertising

  2. LehH Sdsk8

    Tapi Guest

    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?
    Tapi, May 4, 2011
    #2
    1. Advertising

  3. LehH Sdsk8

    LehH Sdsk8 Guest

    On 4 maio, 12:55, Tapi <> 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.
    LehH Sdsk8, May 4, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Molly
    Replies:
    0
    Views:
    519
    Molly
    Aug 25, 2003
  2. Joshua W. Biagio
    Replies:
    0
    Views:
    594
    Joshua W. Biagio
    Sep 30, 2003
  3. Yin
    Replies:
    1
    Views:
    400
    Eddie Corns
    Jan 26, 2004
  4. David
    Replies:
    1
    Views:
    878
    Christos TZOTZIOY Georgiou
    Jul 28, 2004
  5. Simon Wittber

    Status of BaseHTTPServer

    Simon Wittber, Nov 11, 2004, in forum: Python
    Replies:
    2
    Views:
    290
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Nov 11, 2004
Loading...

Share This Page