/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/main.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-09 22:33:14 UTC
  • mto: This revision was merged to the branch mainline in revision 423.
  • Revision ID: john@arbash-meinel.com-20110209223314-risl8ewyp49xwoty
Make loggerhead compatible with bzr.dev again

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335  USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""Search for branches underneath a directory and serve them all."""
19
19
 
21
21
import os
22
22
import sys
23
23
 
24
 
from breezy.plugin import load_plugins
 
24
from bzrlib.plugin import load_plugins
25
25
 
26
26
from paste import httpserver
27
27
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
56
56
    return config, base
57
57
 
58
58
 
59
 
def setup_logging(config, init_logging=True, log_file=None):
60
 
    log_level = config.get_log_level()
61
 
    if init_logging:
62
 
        logging.basicConfig()
63
 
        if log_level is not None:
64
 
            logging.getLogger('').setLevel(log_level)
 
59
def setup_logging(config):
 
60
    logging.basicConfig()
 
61
    logging.getLogger('').setLevel(logging.DEBUG)
65
62
    logger = logging.getLogger('loggerhead')
66
 
    if log_level is not None:
67
 
        logger.setLevel(log_level)
68
 
    if log_file is not None:
69
 
        handler = logging.StreamHandler(log_file)
 
63
    if config.get_option('log_folder'):
 
64
        logfile_path = os.path.join(
 
65
            config.get_option('log_folder'), 'serve-branches.log')
70
66
    else:
71
 
        if config.get_option('log_folder'):
72
 
            logfile_path = os.path.join(
73
 
                config.get_option('log_folder'), 'serve-branches.log')
74
 
        else:
75
 
            logfile_path = 'serve-branches.log'
76
 
        handler = logging.FileHandler(logfile_path, 'a')
77
 
        formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
78
 
                                      ' %(message)s')
79
 
        handler.setFormatter(formatter)
80
 
    # We set the handler to accept all messages, the *logger* won't emit them
81
 
    # if it is configured to suppress it
82
 
    handler.setLevel(logging.DEBUG)
83
 
    logger.addHandler(handler)
84
 
    def _restrict_logging(logger_name):
85
 
        logger = logging.getLogger(logger_name)
86
 
        if logger.getEffectiveLevel() < logging.INFO:
87
 
            logger.setLevel(logging.INFO)
88
 
    # simpleTAL is *very* verbose in DEBUG mode, which is otherwise the
89
 
    # default. So quiet it up a bit.
90
 
    _restrict_logging('simpleTAL')
91
 
    _restrict_logging('simpleTALES')
 
67
        logfile_path = 'serve-branches.log'
 
68
    logfile = logging.FileHandler(logfile_path, 'a')
 
69
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
 
70
                                  ' %(message)s')
 
71
    logfile.setFormatter(formatter)
 
72
    logfile.setLevel(logging.DEBUG)
 
73
    logger.addHandler(logfile)
92
74
    return logger
93
75
 
94
76