From b3290f12d24aed895e5e5eb1c8ab89935adbd323 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Tue, 18 Apr 2017 14:51:12 +0200 Subject: [PATCH] Apply log level cmd line option to log file --- bigchaindb/__init__.py | 26 +++++++++++++------------- bigchaindb/commands/utils.py | 5 ++++- tests/commands/test_utils.py | 3 ++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bigchaindb/__init__.py b/bigchaindb/__init__.py index 98e6b27b..fc8142a0 100644 --- a/bigchaindb/__init__.py +++ b/bigchaindb/__init__.py @@ -1,6 +1,9 @@ import copy +import logging import os +from bigchaindb.log.configs import SUBSCRIBER_LOGGING_CONFIG as log_config + # from functools import reduce # PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16 # basically, the port number is 9984 @@ -73,19 +76,16 @@ config = { 'keyring': [], 'backlog_reassign_delay': 120, 'log': { - # TODO Document here or elsewhere. - # Example of config: - # 'file': '/var/log/bigchaindb.log', - # 'level_console': 'info', - # 'level_logfile': 'info', - # 'datefmt_console': '%Y-%m-%d %H:%M:%S', - # 'datefmt_logfile': '%Y-%m-%d %H:%M:%S', - # 'fmt_console': '%(asctime)s [%(levelname)s] (%(name)s) %(message)s', - # 'fmt_logfile': '%(asctime)s [%(levelname)s] (%(name)s) %(message)s', - # 'granular_levels': { - # 'bichaindb.backend': 'info', - # 'bichaindb.core': 'info', - # }, + 'file': log_config['handlers']['file']['filename'], + 'error_file': log_config['handlers']['errors']['filename'], + 'level_console': logging.getLevelName( + log_config['handlers']['console']['level']), + 'level_logfile': logging.getLevelName( + log_config['handlers']['file']['level']), + 'datefmt_console': log_config['formatters']['console']['datefmt'], + 'datefmt_logfile': log_config['formatters']['file']['datefmt'], + 'fmt_console': log_config['formatters']['console']['format'], + 'fmt_logfile': log_config['formatters']['file']['format'], }, } diff --git a/bigchaindb/commands/utils.py b/bigchaindb/commands/utils.py index cd59856c..d6840d68 100644 --- a/bigchaindb/commands/utils.py +++ b/bigchaindb/commands/utils.py @@ -36,7 +36,10 @@ def configure_bigchaindb(command): def configure(args): try: config_from_cmdline = { - 'log': {'level_console': args.log_level}, + 'log': { + 'level_console': args.log_level, + 'level_logfile': args.log_level, + }, 'server': {'loglevel': args.log_level}, } except AttributeError: diff --git a/tests/commands/test_utils.py b/tests/commands/test_utils.py index 85aa8de4..d361efcb 100644 --- a/tests/commands/test_utils.py +++ b/tests/commands/test_utils.py @@ -76,7 +76,8 @@ def test_configure_bigchaindb_logging(log_level): args = Namespace(config=None, log_level=log_level) test_configure_logger(args) from bigchaindb import config - assert config['log'] == {'level_console': log_level} + assert config['log']['level_console'] == log_level + assert config['log']['level_logfile'] == log_level def test_start_raises_if_command_not_implemented():