Changeset 1939
- Timestamp:
- 04/05/08 15:07:05
- Files:
-
- trunk/cherrypy/_cpmodpy.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpmodpy.py
r1830 r1939 65 65 """ 66 66 67 import logging 67 68 import StringIO 68 69 … … 76 77 77 78 79 78 80 def setup(req): 81 from mod_python import apache 82 79 83 # Run any setup function defined by a "PythonOption cherrypy.setup" directive. 80 84 options = req.get_options() 81 85 if 'cherrypy.setup' in options: 82 modname, fname = options['cherrypy.setup'].split('::') 83 mod = __import__(modname, globals(), locals(), [fname]) 84 func = getattr(mod, fname) 85 func() 86 atoms = options['cherrypy.setup'].split('::', 1) 87 if len(atoms) == 1: 88 mod = __import__(atoms[0], globals(), locals()) 89 else: 90 modname, fname = atoms 91 mod = __import__(modname, globals(), locals(), [fname]) 92 func = getattr(mod, fname) 93 func() 86 94 87 95 cherrypy.config.update({'log.screen': False, … … 90 98 }) 91 99 100 cherrypy._console_control_handler.unsubscribe() 101 cherrypy.engine.autoreload.unsubscribe() 92 102 cherrypy.server.unsubscribe() 103 104 def _log(msg, level): 105 newlevel = apache.APLOG_ERR 106 if logging.DEBUG >= level: 107 newlevel = apache.APLOG_DEBUG 108 elif logging.INFO >= level: 109 newlevel = apache.APLOG_INFO 110 elif logging.WARNING >= level: 111 newlevel = apache.APLOG_WARNING 112 # On Windows, req.server is required or the msg will vanish. See 113 # http://www.modpython.org/pipermail/mod_python/2003-October/014291.html. 114 # Also, "When server is not specified...LogLevel does not apply..." 115 apache.log_error(msg, newlevel, req.server) 116 cherrypy.engine.subscribe('log', _log) 117 93 118 cherrypy.engine.start() 94 119 … … 96 121 cherrypy.engine.exit() 97 122 try: 98 from mod_python import apache99 123 # apache.register_cleanup wasn't available until 3.1.4. 100 124 apache.register_cleanup(cherrypy_cleanup) … … 210 234 except: 211 235 tb = format_exc() 212 cherrypy.log(tb )236 cherrypy.log(tb, 'MOD_PYTHON', severity=logging.ERROR) 213 237 s, h, b = bare_error() 214 238 send_response(req, s, h, b)

