~fginther/core-image-publisher/hardcoded-edge-rolling

« back to all changes in this revision

Viewing changes to core_image_publisher/__init__.py

  • Committer: Ubuntu CI Bot
  • Author(s): Thomi Richards
  • Date: 2015-04-01 21:18:17 UTC
  • mfrom: (21.1.2 trunk-use-uservice-utils)
  • Revision ID: ubuntu_ci_bot-20150401211817-qbbwqrz09rh5e41g
Use the new logging functions in uservice_utils. [r=Joe Talbott]

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import argparse
19
19
import configparser
20
 
import logging
21
 
import logging.handlers
22
20
import os
23
21
 
24
 
import logstash
 
22
from uservice_utils.logging import configure_service_logging
25
23
 
26
24
from core_image_publisher.queue import (
27
25
    create_connection_from_config,
47
45
    return config
48
46
 
49
47
 
50
 
def configure_logging(config):
51
 
    root_logger = logging.getLogger()
52
 
    root_logger.setLevel(logging.INFO)
53
 
 
54
 
    # glanceclient & keystoneclient use requests, which logs for every
55
 
    # new HTTP connection, so let's make it a little less chatty:
56
 
    logging.getLogger('requests').setLevel(logging.WARNING)
57
 
 
58
 
    # If there is no ./logs directory, fallback to stderr.
59
 
    log_path = os.path.abspath(
60
 
        os.path.join(__file__, '../../logs/core-image-publisher.log'))
61
 
    log_dir = os.path.dirname(log_path)
62
 
    if os.path.exists(log_dir):
63
 
        handler = logging.handlers.TimedRotatingFileHandler(
64
 
            log_path,
65
 
            when='D',
66
 
            interval=1
67
 
        )
68
 
    else:
69
 
        print("'logs' directory '{}' does not exist, using stderr "
70
 
              "for app log.".format(log_dir))
71
 
        handler = logging.StreamHandler()
72
 
 
73
 
    handler.setFormatter(
74
 
        logging.Formatter(
75
 
            '%(asctime)s  %(name)s %(levelname)s: %(message)s'
76
 
        )
77
 
    )
78
 
    root_logger.addHandler(handler)
79
 
    if 'logstash' in config:
80
 
        root_logger.addHandler(
81
 
            logstash.LogstashHandler(
82
 
                config['logstash']['host'],
83
 
                int(config['logstash']['port']),
84
 
                int(config['logstash']['version'])
85
 
            )
86
 
        )
87
 
 
88
 
 
89
48
def main():
90
49
    config = read_config()
91
 
    configure_logging(config)
 
50
    log_path = os.path.abspath(
 
51
        os.path.join(__file__, '../../logs/core-image-publisher.log')
 
52
    )
 
53
    configure_service_logging(
 
54
        log_path,
 
55
        config['logstash'] if 'logstash' in config else None
 
56
    )
92
57
    connection = create_connection_from_config(config)
93
58
    try:
94
59
        with connection: