~loggerhead-team/loggerhead/experimental

« back to all changes in this revision

Viewing changes to loggerhead/main.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-11 14:55:55 UTC
  • mfrom: (419.2.26 loggerhead)
  • Revision ID: john@arbash-meinel.com-20110411145555-7xflzcipb32kuknh
Merge trunk into the history-db branch.

We had to disable the mainline tests, because they were monkey-patching
a parameter that we have removed. We need to figure out a way to
do a similar test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    return config, base
57
57
 
58
58
 
59
 
def setup_logging(config):
60
 
    logging.basicConfig()
 
59
def setup_logging(config, init_logging=True, log_file=None):
61
60
    log_level = config.get_log_level()
62
 
    logging.getLogger('').setLevel(log_level)
 
61
    if init_logging:
 
62
        logging.basicConfig()
 
63
        if log_level is not None:
 
64
            logging.getLogger('').setLevel(log_level)
63
65
    logger = logging.getLogger('loggerhead')
64
 
    logger.setLevel(log_level)
65
 
    if config.get_option('log_folder'):
66
 
        logfile_path = os.path.join(
67
 
            config.get_option('log_folder'), 'serve-branches.log')
 
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)
68
70
    else:
69
 
        logfile_path = 'serve-branches.log'
70
 
    logfile = logging.FileHandler(logfile_path, 'a')
71
 
    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)s:'
72
 
                                  ' %(message)s')
73
 
    logfile.setFormatter(formatter)
74
 
    logfile.setLevel(logging.DEBUG)
75
 
    logger.addHandler(logfile)
 
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)
76
84
    def _restrict_logging(logger_name):
77
85
        logger = logging.getLogger(logger_name)
78
86
        if logger.getEffectiveLevel() < logging.INFO: