logging and httphandler

Jason Friedman jason at powerpull.net
Sat Jan 14 00:28:27 EST 2012


I am logging to my Apache web server, using this Apache format:

LogFormat "%{%Y-%m-%d %H:%M:%S}t %U %q" scriptlog
CustomLog /var/log/apache2/script.log scriptlog

My code is as follows:

#!/usr/bin/env python3
import logging, logging.handlers, sys
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
host = "localhost:9090"
url = "make_deployment_group"
http_handler = logging.handlers.HTTPHandler(host, url, method='GET')
http_formatter = logging.Formatter('%(name)s - %(levelname)8s - %(message)s')
http_handler.setFormatter(http_formatter)
logger.addHandler(http_handler)
logger.warn('warn message')

which results in a entry at /var/log/apache2/script.log:

2012-01-14 05:22:52
make_deployment_group?threadName=MainThread&name=simple_example&thread=139923654465280&created=1326518572.83&process=31122&processName=MainProcess&args=%28%29&module=my-logging&filename=my-logging.py&levelno=30&exc_text=None&pathname=my-logging.py&lineno=33&asctime=2012-01-14+05%3A22%3A52%2C825&msg=warn+message&exc_info=None&message=warn+message&funcName=%3Cmodule%3E&relativeCreated=20.0970172882&levelname=WARNING&msecs=825.411081314

All the information one could want, which is nice, but is there a way
to specify I want only certain information sent via the HTTP request?



More information about the Python-list mailing list