~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: John Arbash Meinel
  • Date: 2011-03-16 11:35:03 UTC
  • mto: This revision was merged to the branch mainline in revision 435.
  • Revision ID: john@arbash-meinel.com-20110316113503-c21ve1v3wru7kvae
Remove duplicated effort in setup_logging.

Instead, pass in some extra flags, indicating what loggerhead should do.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009, 2010 Canonical Ltd
 
1
# Copyright 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
58
58
    HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
59
59
            (DEFAULT_PORT,))
60
60
 
61
 
    def setup_logging(config):
62
 
        import logging
63
 
        import sys
64
 
 
65
 
        logger = logging.getLogger('loggerhead')
66
 
        log_level = config.get_log_level()
67
 
        if log_level is not None:
68
 
            logger.setLevel(log_level)
69
 
        handler = logging.StreamHandler(sys.stderr)
70
 
        handler.setLevel(logging.DEBUG)
71
 
        logger.addHandler(handler)
72
 
        logging.getLogger('simpleTAL').addHandler(handler)
73
 
        logging.getLogger('simpleTALES').addHandler(handler)
74
 
        def _restrict_logging(logger_name):
75
 
            logger = logging.getLogger(logger_name)
76
 
            if logger.getEffectiveLevel() < logging.INFO:
77
 
                logger.setLevel(logging.INFO)
78
 
        # simpleTAL is *very* verbose in DEBUG mode, which is otherwise the
79
 
        # default. So quiet it up a bit.
80
 
        _restrict_logging('simpleTAL')
81
 
        _restrict_logging('simpleTALES')
82
 
 
83
 
 
84
 
 
85
61
    def serve_http(transport, host=None, port=None, inet=None):
86
62
        from paste.httpexceptions import HTTPExceptionHandler
87
63
        from paste.httpserver import serve
96
72
 
97
73
        from loggerhead.apps.transport import BranchesFromTransportRoot
98
74
        from loggerhead.config import LoggerheadConfig
 
75
        from loggerhead.main import setup_logging
99
76
 
100
77
        if host is None:
101
78
            host = DEFAULT_HOST
105
82
        if not transport.is_readonly():
106
83
            argv.insert(0, '--allow-writes')
107
84
        config = LoggerheadConfig(argv)
108
 
        setup_logging(config)
 
85
        setup_logging(config, init_logging=False, log_file=sys.stderr)
109
86
        app = BranchesFromTransportRoot(transport.base, config)
110
87
        app = HTTPExceptionHandler(app)
111
88
        serve(app, host=host, port=port)