I am relatively new to Python and Python web application development. Currently I am creating a hello world application in Python using mod_wsgi
Here are my configurations.
Apache configuration
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /var/www/mysite
WSGIDaemonProcess mysite threads=5
WSGIScriptAlias / /var/www/mysite/mysite.wsgi
WSGIProcessGroup mysite
<Directory /var/www/mysite>
WSGIProcessGroup mysite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
mysite.wsgi
import os
import sys
path='/var/www/mysite'
if path not in sys.path:
sys.path.append(path)
import mysite.app
application = mysite.app.App()
app.py
import mysite.log as log
logger = log.custom_logger('root')
logger.debug('I am included only once')
class App:
"""
This Class is responsible
"""
def __init__(self):
logger.debug('I will be called only after apache restart')
"""
WSGI module will call this function by default
"""
def __call__(self, environ, start_response):
logger.debug('I will be invoked for every request')
# Do some stuff here
start_response(response_state, response_header)
return [response]
Problem: I am not able to see logs inside __init__ and log which is outside in app.py.
Output
First time run after restarting apache
DEBUG - app - I am included only once
DEBUG - app - I will be called only after apache restart
DEBUG - app - I will be invoked for every request
When I refresh the page in browser
DEBUG - app - I will be invoked for every request
What is happening? I am aware that __init__ is not constructor, application objects are caching somewhere? whats the story.