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

Search Discussions

  • Tapi at May 4, 2011 at 3:55 pm
    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?
  • LehH Sdsk8 at May 4, 2011 at 4:09 pm

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 4, '11 at 10:52a
activeMay 4, '11 at 4:09p
posts3
users2
websitepython.org

2 users in discussion

LehH Sdsk8: 2 posts Tapi: 1 post

People

Translate

site design / logo © 2022 Grokbase