python - logging in mod_python/apache -
What is the standard way to create Python's logging module with apache / modpython?
I want to call Mylog.warn ('whatever') and as a result req.log_error () can be called where req modpython is requested.
Is this an easy way to set it?
I ever did, but it seems that it should not be difficult to write a sub-class. It should be something that moves I can not say that I've actually tried it because I do not currently installed mod_python but you call logging.root.addHandler (ApacheLogHandler ()) Should be able and it should be taken to work out YMMV
import logging import apache class Apache Loghandlr (logging. Handler): LEVEL_MAP = {Logingkdebug: Apache.apioelji_debug, logging .INFO: Apache.apioelajianafoanooo, logging. Warning Apache.apielji_wairng, Logging.ERROR: apache.APLOG_ERR, logging.CRITICAL: apache.APLOG_CRIT,} def __init __ (self, request = None): self.log_error = apache.log_error None if no request: self. log_error = request.log_error def emit (self-recorded): apacheLevel = apache.APLOG_DEBUG If Rikordklevlno in apacheLogHandler.LEVEL_MAP: apacheLevel = ApacheLogHandler.LEVEL_MAP [record.levelno] self.log_error (record.getMessage (), apacheLevel) < / Code>
Comments
Post a Comment