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. Advertisements

  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. Advertisements

  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. Advertisements

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. Henrik_the_boss
    Replies:
    0
    Views:
    3,093
    Henrik_the_boss
    Nov 5, 2003
  2. Amratash
    Replies:
    0
    Views:
    731
    Amratash
    Apr 13, 2004
  3. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,627
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  4. unomystEz
    Replies:
    0
    Views:
    747
    unomystEz
    Nov 19, 2006
  5. vj
    Replies:
    0
    Views:
    816
  6. ES
    Replies:
    3
    Views:
    821
  7. AAaron123
    Replies:
    1
    Views:
    425
    Cowboy \(Gregory A. Beamer\)
    Oct 14, 2008
  8. Tom Wingert
    Replies:
    0
    Views:
    581
    Tom Wingert
    Jan 12, 2006
Loading...