Fix for migrator logging configuration

Closes-Bug: #1398897
Change-Id: I12d1454f826a307a45a0b6fdee70bd81d91a03ce
This commit is contained in:
Alexander Kislitsky 2014-12-03 18:38:22 +03:00
parent 58e89a2d01
commit bcf5e0a736
3 changed files with 24 additions and 7 deletions

View File

@ -13,8 +13,12 @@
# under the License.
import logging
import os
LOG_FILE = "/var/log/migration.log"
LOG_DIR = '/var/log/fuel-stats'
LOG_FILE = os.path.join(LOG_DIR, 'migration.log')
LOG_FILE_ES = os.path.join(LOG_DIR, 'elasticsearch.log')
LOG_FILE_EST = os.path.join(LOG_DIR, 'elasticsearch-trace.log')
LOG_LEVEL = logging.INFO
LOG_FILE_SIZE = 2048000
LOG_FILES_COUNT = 20

View File

@ -26,13 +26,12 @@ def get_formatter():
return Formatter(fmt=LOG_FORMAT, datefmt=DATE_FORMAT)
def get_file_handler():
def get_file_handler(log_file):
file_handler = RotatingFileHandler(
config.LOG_FILE,
log_file,
maxBytes=config.LOG_FILE_SIZE,
backupCount=config.LOG_FILES_COUNT
)
file_handler.setLevel(config.LOG_LEVEL)
formatter = get_formatter()
file_handler.setFormatter(formatter)
return file_handler
@ -40,4 +39,14 @@ def get_file_handler():
logger = logging.getLogger('migration')
logger.setLevel(config.LOG_LEVEL)
logger.addHandler(get_file_handler())
logger.addHandler(get_file_handler(config.LOG_FILE))
logging.getLogger('elasticsearch').setLevel(config.LOG_LEVEL)
logging.getLogger('elasticsearch').addHandler(
get_file_handler(config.LOG_FILE_ES))
logging.getLogger('elasticsearch.trace').setLevel(config.LOG_LEVEL)
logging.getLogger('elasticsearch.trace').addHandler(
get_file_handler(config.LOG_FILE_EST))

View File

@ -24,6 +24,10 @@ def configure_test_env():
config.ELASTIC_PORT = 9200
config.DB_CONNECTION_STRING = \
'postgresql://collector:collector@localhost:5432/collector'
config.LOG_FILE = os.path.realpath(os.path.join(
os.path.dirname(__file__), 'logs', 'migration.log'))
config.LOG_DIR = os.path.realpath(os.path.join(
os.path.dirname(__file__), 'logs'))
config.LOG_FILE = os.path.join(config.LOG_DIR, 'migration.log')
config.LOG_FILE_ES = os.path.join(config.LOG_DIR, 'elasticsearch.log')
config.LOG_FILE_EST = os.path.join(config.LOG_DIR,
'elasticsearch-trace.log')
config.LOG_LEVEL = logging.DEBUG