make name a required argument and add fallback to getEffectiveLevel

This commit is contained in:
gcarq 2018-03-25 21:05:10 +02:00
parent a2c3df3ac5
commit 3f8d7dae39
14 changed files with 20 additions and 21 deletions

View File

@ -32,7 +32,7 @@ class Analyze(object):
Init Analyze Init Analyze
:param config: Bot configuration (use the one from Configuration()) :param config: Bot configuration (use the one from Configuration())
""" """
self.logger = Logger(name=__name__, level=config.get('loglevel')).get_logger() self.logger = Logger(__name__, level=config.get('loglevel')).get_logger()
self.config = config self.config = config
self.strategy = Strategy(self.config) self.strategy = Strategy(self.config)

View File

@ -20,7 +20,7 @@ class Configuration(object):
""" """
def __init__(self, args: Namespace) -> None: def __init__(self, args: Namespace) -> None:
self.args = args self.args = args
self.logging = Logger(name=__name__) self.logging = Logger(__name__)
self.logger = self.logging.get_logger() self.logger = self.logging.get_logger()
self.config = None self.config = None

View File

@ -38,7 +38,7 @@ class FreqtradeBot(object):
""" """
# Init the logger # Init the logger
self.logger = Logger(name=__name__, level=config.get('loglevel')).get_logger() self.logger = Logger(__name__, level=config.get('loglevel')).get_logger()
# Init bot states # Init bot states
self.state = State.STOPPED self.state = State.STOPPED

View File

@ -5,13 +5,14 @@ This module contains the class for logger and logging messages
""" """
import logging import logging
from typing import Optional
class Logger(object): class Logger(object):
""" """
Logging class Logging class
""" """
def __init__(self, name='', level=logging.INFO) -> None: def __init__(self, name, level: Optional[int] = None) -> None:
""" """
Init the logger class Init the logger class
:param name: Name of the Logger scope :param name: Name of the Logger scope
@ -21,9 +22,7 @@ class Logger(object):
self.name = name self.name = name
self.logger = None self.logger = None
if level is None: self.level = level or logging.getLogger().getEffectiveLevel()
level = logging.INFO
self.level = level
self._init_logger() self._init_logger()

View File

@ -14,8 +14,6 @@ from freqtrade.configuration import Configuration
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.logger import Logger from freqtrade.logger import Logger
logger = Logger(name='freqtrade').get_logger()
def main(sysargv: List[str]) -> None: def main(sysargv: List[str]) -> None:
""" """
@ -28,6 +26,8 @@ def main(sysargv: List[str]) -> None:
) )
args = arguments.get_parsed_arg() args = arguments.get_parsed_arg()
logger = Logger(__name__, level=args.loglevel).get_logger()
# A subcommand has been issued. # A subcommand has been issued.
# Means if Backtesting or Hyperopt have been called we exit the bot # Means if Backtesting or Hyperopt have been called we exit the bot
if hasattr(args, 'func'): if hasattr(args, 'func'):

View File

@ -10,7 +10,7 @@ from freqtrade.exchange import get_ticker_history
from freqtrade.logger import Logger from freqtrade.logger import Logger
from user_data.hyperopt_conf import hyperopt_optimize_conf from user_data.hyperopt_conf import hyperopt_optimize_conf
logger = Logger(name=__name__).get_logger() logger = Logger(__name__).get_logger()
def trim_tickerlist(tickerlist: List[Dict], timerange: Tuple[Tuple, int, int]) -> List[Dict]: def trim_tickerlist(tickerlist: List[Dict], timerange: Tuple[Tuple, int, int]) -> List[Dict]:

View File

@ -32,7 +32,7 @@ class Backtesting(object):
def __init__(self, config: Dict[str, Any]) -> None: def __init__(self, config: Dict[str, Any]) -> None:
# Init the logger # Init the logger
self.logging = Logger(name=__name__, level=config['loglevel']) self.logging = Logger(__name__, level=config['loglevel'])
self.logger = self.logging.get_logger() self.logger = self.logging.get_logger()
self.config = config self.config = config
self.analyze = None self.analyze = None
@ -301,7 +301,7 @@ def start(args: Namespace) -> None:
""" """
# Initialize logger # Initialize logger
logger = Logger(name=__name__).get_logger() logger = Logger(__name__).get_logger()
logger.info('Starting freqtrade in Backtesting mode') logger.info('Starting freqtrade in Backtesting mode')
# Initialize configuration # Initialize configuration

View File

@ -44,7 +44,7 @@ class Hyperopt(Backtesting):
super().__init__(config) super().__init__(config)
# Rename the logging to display Hyperopt file instead of Backtesting # Rename the logging to display Hyperopt file instead of Backtesting
self.logging = Logger(name=__name__, level=config['loglevel']) self.logging = Logger(__name__, level=config['loglevel'])
self.logger = self.logging.get_logger() self.logger = self.logging.get_logger()
# set TARGET_TRADES to suit your number concurrent trades so its realistic # set TARGET_TRADES to suit your number concurrent trades so its realistic
@ -598,7 +598,7 @@ def start(args: Namespace) -> None:
logging.getLogger('hyperopt.tpe').setLevel(logging.WARNING) logging.getLogger('hyperopt.tpe').setLevel(logging.WARNING)
# Initialize logger # Initialize logger
logger = Logger(name=__name__).get_logger() logger = Logger(__name__).get_logger()
logger.info('Starting freqtrade in Hyperopt mode') logger.info('Starting freqtrade in Hyperopt mode')
# Initialize configuration # Initialize configuration

View File

@ -29,7 +29,7 @@ class RPC(object):
""" """
self.freqtrade = freqtrade self.freqtrade = freqtrade
self.logger = Logger( self.logger = Logger(
name=__name__, __name__,
level=self.freqtrade.config.get('loglevel') level=self.freqtrade.config.get('loglevel')
).get_logger() ).get_logger()

View File

@ -20,7 +20,7 @@ class RPCManager(object):
# Init the logger # Init the logger
self.logger = Logger( self.logger = Logger(
name=__name__, __name__,
level=self.freqtrade.config.get('loglevel') level=self.freqtrade.config.get('loglevel')
).get_logger() ).get_logger()

View File

@ -27,7 +27,7 @@ class Strategy(object):
:param config: :param config:
:return: :return:
""" """
self.logger = Logger(name=__name__).get_logger() self.logger = Logger(__name__).get_logger()
# Verify the strategy is in the configuration, otherwise fallback to the default strategy # Verify the strategy is in the configuration, otherwise fallback to the default strategy
if 'strategy' in config: if 'strategy' in config:

View File

@ -12,13 +12,13 @@ def test_logger_object() -> None:
Test the Constants object has the mandatory Constants Test the Constants object has the mandatory Constants
:return: None :return: None
""" """
logger = Logger() logger = Logger('')
assert logger.name == '' assert logger.name == ''
assert logger.level == 20 assert logger.level == 20
assert logger.level is logging.INFO assert logger.level is logging.INFO
assert hasattr(logger, 'get_logger') assert hasattr(logger, 'get_logger')
logger = Logger(name='Foo', level=logging.WARNING) logger = Logger('Foo', level=logging.WARNING)
assert logger.name == 'Foo' assert logger.name == 'Foo'
assert logger.name != '' assert logger.name != ''
assert logger.level == 30 assert logger.level == 30

View File

@ -28,7 +28,7 @@ from freqtrade.logger import Logger
import freqtrade.optimize as optimize import freqtrade.optimize as optimize
logger = Logger(name="Graph dataframe").get_logger() logger = Logger(__name__).get_logger()
def plot_analyzed_dataframe(args: Namespace) -> None: def plot_analyzed_dataframe(args: Namespace) -> None:

View File

@ -30,7 +30,7 @@ import freqtrade.optimize as optimize
import freqtrade.misc as misc import freqtrade.misc as misc
logger = Logger(name="Graph profits").get_logger() logger = Logger(__name__).get_logger()
# data:: [ pair, profit-%, enter, exit, time, duration] # data:: [ pair, profit-%, enter, exit, time, duration]