Apply log level cmd line option to log file

This commit is contained in:
Sylvain Bellemare 2017-04-18 14:51:12 +02:00 committed by Sylvain Bellemare
parent 4c0fc52e9e
commit b3290f12d2
3 changed files with 19 additions and 15 deletions

View File

@ -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'],
},
}

View File

@ -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:

View File

@ -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():