thanks Ben, exactly as you suggested. Below is my new code fyi:
...
def almost_apache_style_log(handler):
'''without status code and body length'''
req = handler.request
print '%s - - [%s +0800] "%s %s %s" - - "%s" "%s"' % \
(req.remote_ip, time.strftime("%d/%b/%Y:%X"), req.method,
req.uri,
req.version, getattr(req, 'referer', '-'),
req.headers['User-Agent'])
class BaseHandler(RequestHandler):
def initialize(self):
# print almost_apache_style_log(self.request)
pass
...
settings = {
....
"log_function": almost_apache_style_log,
}
....
On 2月8日, 下午2时59分, Ben Darnell <
b...@bendarnell.com> wrote:
> It's better to use Application.log_request
> (
http://www.tornadoweb.org/documentation/web.html#tornado.web.Applicat...),
> since that will be used for e.g. StaticFileHandler in addition to your
> own handlers.
>
> -Ben
>
>
>
>
>
>
>
> On Tue, Feb 7, 2012 at 10:02 PM, Felinx Lee <
felinx....@gmail.com> wrote:
> > Try to override _request_summary in RequestHandler.
>
> > On Wed, Feb 8, 2012 at 11:30 AM, 罗晟 <
sheng.peisi....@gmail.com> wrote:
>
> >> Hi all,
>
> >> How to tell tornado server to print apache style log? I can't figure
> >> it out by checking the docs.
> >> So I added one for myself:
>
> >> ...
>
> >> def almost_apache_style_log(req):
> >> '''without status code and body length'''
> >> return '%s - - [%s +0800] "%s %s %s" - - "%s" "%s"' % \
> >> (req.remote_ip, time.strftime("%d/%b/%Y:%X"), req.method,
> >> req.uri,
> >> req.version, getattr(req, 'referer', '-'),
> >> req.headers['User-Agent'])
>
> >> class BaseHandler(RequestHandler):
> >> def initialize(self):
> >> print almost_apache_style_log(self.request)
>
> >> ...
>
> >> Does tornado have any standard way to do this?
>
> >> regards,
>
> >> Sheng
>
> > --
> > What can change the nature of a man?(Planescape Torment)
> > --------------------------------------------------------------------------- -------------
> >
http://feilong.me Felinx Lee's Blog (Chinese Only)
> >
http://www.zhimaq.comIT Q&A (Chinese Only)