Add an option to specify a log file to pathod.

This commit is contained in:
Aldo Cortesi 2012-07-27 14:03:15 +12:00
parent 3e158211a8
commit d8c53cbc57
2 changed files with 15 additions and 3 deletions

View File

@ -81,18 +81,22 @@ class PathodHandler(tcp.BaseHandler):
for i in self.server.anchors: for i in self.server.anchors:
if i[0].match(path): if i[0].match(path):
self.info("Serving anchor: %s"%path)
return self.serve_crafted(i[1], request_log) return self.serve_crafted(i[1], request_log)
if not self.server.nocraft and path.startswith(self.server.craftanchor): if not self.server.nocraft and path.startswith(self.server.craftanchor):
spec = urllib.unquote(path)[len(self.server.craftanchor):] spec = urllib.unquote(path)[len(self.server.craftanchor):]
self.info("Serving spec: %s"%spec)
try: try:
crafted = rparse.parse_response(self.server.request_settings, spec) crafted = rparse.parse_response(self.server.request_settings, spec)
except rparse.ParseException, v: except rparse.ParseException, v:
self.info("Parse error: %s"%v.msg)
crafted = rparse.PathodErrorResponse( crafted = rparse.PathodErrorResponse(
"Parse Error", "Parse Error",
"Error parsing response spec: %s\n"%v.msg + v.marked() "Error parsing response spec: %s\n"%v.msg + v.marked()
) )
except rparse.FileAccessDenied: except rparse.FileAccessDenied:
self.info("File access denied")
crafted = rparse.PathodErrorResponse("Access Denied") crafted = rparse.PathodErrorResponse("Access Denied")
return self.serve_crafted(crafted, request_log) return self.serve_crafted(crafted, request_log)
elif self.server.noweb: elif self.server.noweb:
@ -100,6 +104,7 @@ class PathodHandler(tcp.BaseHandler):
crafted.serve(self.wfile, self.server.check_policy) crafted.serve(self.wfile, self.server.check_policy)
return False return False
else: else:
self.info("app: %s %s"%(method, path))
cc = wsgi.ClientConn(self.client_address) cc = wsgi.ClientConn(self.client_address)
req = wsgi.Request(cc, "http", method, path, headers, content) req = wsgi.Request(cc, "http", method, path, headers, content)
sn = self.connection.getsockname() sn = self.connection.getsockname()
@ -110,7 +115,6 @@ class PathodHandler(tcp.BaseHandler):
version.NAMEVERSION version.NAMEVERSION
) )
app.serve(req, self.wfile) app.serve(req, self.wfile)
self.debug("%s %s"%(method, path))
return True return True
def handle(self): def handle(self):

12
pathod
View File

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse, sys, logging import argparse, sys, logging, logging.handlers
from libpathod import pathod, utils, version from libpathod import pathod, utils, version
if __name__ == "__main__": if __name__ == "__main__":
@ -18,6 +18,10 @@ if __name__ == "__main__":
"-d", dest='staticdir', default=None, type=str, "-d", dest='staticdir', default=None, type=str,
help='Directory for static files.' help='Directory for static files.'
) )
parser.add_argument(
"-f", dest='logfile', default=None, type=str,
help='Log file.'
)
parser.add_argument( parser.add_argument(
"--debug", dest='debug', default=False, action="store_true", "--debug", dest='debug', default=False, action="store_true",
help='Enable debug output.' help='Enable debug output.'
@ -86,6 +90,10 @@ if __name__ == "__main__":
) )
if not args.debug: if not args.debug:
logging.disable(logging.DEBUG) logging.disable(logging.DEBUG)
if args.logfile:
ch = logging.handlers.WatchedFileHandler(args.logfile)
root.addHandler(ch)
sizelimit = None sizelimit = None
if args.sizelimit: if args.sizelimit:
@ -104,7 +112,7 @@ if __name__ == "__main__":
sizelimit = sizelimit, sizelimit = sizelimit,
noweb = args.noweb, noweb = args.noweb,
nocraft = args.nocraft, nocraft = args.nocraft,
noapi = args.noapi, noapi = args.noapi,
nohang = args.nohang nohang = args.nohang
) )
except pathod.PathodError, v: except pathod.PathodError, v: