source: TI12-security/trunk/python/Tests/paste_logging_test/app.py @ 5884

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/paste_logging_test/app.py@5884
Revision 5884, 1.3 KB checked in by pjkersha, 11 years ago (diff)

Test Paste and logging configuration

Line 
1import logging
2log = logging.getLogger(__name__)
3
4class TestLoggingApp(object):
5    '''Test logging with Paste'''
6    RESPONSE = __doc__
7     
8    @classmethod 
9    def app_factory(cls, app_conf, **local_conf):
10        log.debug("Creating app ...")
11        logging.debug("Creating app ...")
12        return cls()
13   
14    def __call__(self, environ, start_response):
15        log.debug("Returning response ...")
16        logging.debug("Returning response ...")
17        start_response('200 OK', 
18                       [('Content-type', 'text/plain'),
19                        ('Content-length', str(len(TestLoggingApp.RESPONSE)))])
20        return [TestLoggingApp.RESPONSE]
21   
22# To start run
23# $ paster serve services.ini or run this file as a script
24# $ ./app.py [port #]
25if __name__ == '__main__':
26    import sys
27    import os
28    from os.path import dirname, abspath
29
30    if len(sys.argv) > 1:
31        port = int(sys.argv[1])
32    else:
33        port = 6080
34       
35    cfgFilePath = os.path.join(dirname(abspath(__file__)), 'app.ini')
36       
37    from paste.httpserver import serve
38    from paste.deploy import loadapp
39    from paste.script.util.logging_config import fileConfig
40   
41    fileConfig(cfgFilePath)
42    app = loadapp('config:%s' % cfgFilePath)
43    serve(app, host='0.0.0.0', port=port)
Note: See TracBrowser for help on using the repository browser.