Logging truss for pathod.

This commit is contained in:
Aldo Cortesi 2012-06-24 21:40:31 +12:00
parent 90c6fb394d
commit 65487ead6d
4 changed files with 21 additions and 4 deletions

View File

@ -1,7 +1,6 @@
from netlib import tcp, http from netlib import tcp, http
import rparse import rparse
class PathocError(Exception): pass class PathocError(Exception): pass

View File

@ -1,7 +1,8 @@
import urllib, threading, re import urllib, threading, re, logging
from netlib import tcp, http, odict, wsgi from netlib import tcp, http, odict, wsgi
import version, app, rparse import version, app, rparse
class PathodError(Exception): pass class PathodError(Exception): pass

2
pathoc
View File

@ -10,7 +10,7 @@ if __name__ == "__main__":
parser.add_argument('request', type=str, nargs="+", help='Request specification') parser.add_argument('request', type=str, nargs="+", help='Request specification')
args = parser.parse_args() args = parser.parse_args()
if args.port is None: if args.port is None:
port = 443 if args.ssl else 80 port = 443 if args.ssl else 80
else: else:

19
pathod
View File

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse, sys import argparse, sys, logging
from libpathod import pathod, utils, version from libpathod import pathod, utils, version
if __name__ == "__main__": if __name__ == "__main__":
@ -14,6 +14,11 @@ 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(
"--debug", dest='debug', default=False,
action="store_true",
help='Enable debug output.'
)
parser.add_argument( parser.add_argument(
"-s", dest='ssl', default=False, "-s", dest='ssl', default=False,
action="store_true", action="store_true",
@ -50,6 +55,18 @@ if __name__ == "__main__":
parser.error("Invalid anchor specification: %s"%i) parser.error("Invalid anchor specification: %s"%i)
alst.append(parts) alst.append(parts)
root = logging.getLogger()
if root.handlers:
for handler in root.handlers:
root.removeHandler(handler)
logging.basicConfig(
format='%(asctime)s: %(message)s',
datefmt='%d-%m-%y %I:%M:%S',
level=logging.DEBUG
)
if not args.debug:
logging.disable(logging.DEBUG)
try: try:
pd = pathod.Pathod( pd = pathod.Pathod(
(args.address, args.port), (args.address, args.port),