Allow different loglevels

This commit is contained in:
Matthias 2018-07-18 22:52:57 +02:00
parent 7134c15e86
commit 789b98015f
3 changed files with 19 additions and 18 deletions

View File

@ -3,7 +3,6 @@ This module contains the argument manager class
"""
import argparse
import logging
import os
import re
from typing import List, NamedTuple, Optional
@ -64,11 +63,10 @@ class Arguments(object):
"""
self.parser.add_argument(
'-v', '--verbose',
help='be verbose',
action='store_const',
help='verbose mode (-vv for more, -vvv to get all messages)',
action='count',
dest='loglevel',
const=logging.DEBUG,
default=logging.INFO,
default=0,
)
self.parser.add_argument(
'--version',

View File

@ -12,10 +12,22 @@ from jsonschema import Draft4Validator, validate
from jsonschema.exceptions import ValidationError, best_match
from freqtrade import OperationalException, constants
logger = logging.getLogger(__name__)
def set_loggers(log_level: int = 0) -> None:
"""
Set the logger level for Third party libs
:return: None
"""
logging.getLogger('requests').setLevel(logging.INFO if log_level <= 1 else logging.DEBUG)
logging.getLogger("urllib3").setLevel(logging.INFO if log_level <= 1 else logging.DEBUG)
logging.getLogger('ccxt.base.exchange').setLevel(
logging.INFO if log_level <= 2 else logging.DEBUG)
logging.getLogger('telegram').setLevel(logging.INFO)
class Configuration(object):
"""
Class to read and init the bot configuration
@ -81,9 +93,10 @@ class Configuration(object):
if 'loglevel' in self.args and self.args.loglevel:
config.update({'loglevel': self.args.loglevel})
logging.basicConfig(
level=config['loglevel'],
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
set_loggers(config['loglevel'])
logger.info('Log level set to %s', logging.getLevelName(config['loglevel']))
# Add dynamic_whitelist if found

View File

@ -10,7 +10,7 @@ from typing import List
from freqtrade import OperationalException
from freqtrade.arguments import Arguments
from freqtrade.configuration import Configuration
from freqtrade.configuration import Configuration, set_loggers
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.state import State
from freqtrade.rpc import RPCMessageType
@ -84,16 +84,6 @@ def reconfigure(freqtrade: FreqtradeBot, args: Namespace) -> FreqtradeBot:
return freqtrade
def set_loggers() -> None:
"""
Set the logger level for Third party libs
:return: None
"""
logging.getLogger('requests.packages.urllib3').setLevel(logging.INFO)
logging.getLogger('ccxt.base.exchange').setLevel(logging.INFO)
logging.getLogger('telegram').setLevel(logging.INFO)
if __name__ == '__main__':
set_loggers()
main(sys.argv[1:])