diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 8bc552d74..b62d8240e 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -32,7 +32,7 @@ class Analyze(object): Init Analyze :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.strategy = Strategy(self.config) diff --git a/freqtrade/configuration.py b/freqtrade/configuration.py index 1f6cea4e6..d4f73a086 100644 --- a/freqtrade/configuration.py +++ b/freqtrade/configuration.py @@ -20,7 +20,7 @@ class Configuration(object): """ def __init__(self, args: Namespace) -> None: self.args = args - self.logging = Logger(name=__name__) + self.logging = Logger(__name__) self.logger = self.logging.get_logger() self.config = None diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 29790515e..48212b865 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -38,7 +38,7 @@ class FreqtradeBot(object): """ # 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 self.state = State.STOPPED diff --git a/freqtrade/logger.py b/freqtrade/logger.py index 95e55e477..4d051dcdc 100644 --- a/freqtrade/logger.py +++ b/freqtrade/logger.py @@ -5,13 +5,14 @@ This module contains the class for logger and logging messages """ import logging +from typing import Optional class Logger(object): """ Logging class """ - def __init__(self, name='', level=logging.INFO) -> None: + def __init__(self, name, level: Optional[int] = None) -> None: """ Init the logger class :param name: Name of the Logger scope @@ -21,9 +22,7 @@ class Logger(object): self.name = name self.logger = None - if level is None: - level = logging.INFO - self.level = level + self.level = level or logging.getLogger().getEffectiveLevel() self._init_logger() diff --git a/freqtrade/main.py b/freqtrade/main.py index 556b70708..511270a60 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -14,8 +14,6 @@ from freqtrade.configuration import Configuration from freqtrade.freqtradebot import FreqtradeBot from freqtrade.logger import Logger -logger = Logger(name='freqtrade').get_logger() - def main(sysargv: List[str]) -> None: """ @@ -28,6 +26,8 @@ def main(sysargv: List[str]) -> None: ) args = arguments.get_parsed_arg() + logger = Logger(__name__, level=args.loglevel).get_logger() + # A subcommand has been issued. # Means if Backtesting or Hyperopt have been called we exit the bot if hasattr(args, 'func'): diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index a26744691..23e8f19ad 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -10,7 +10,7 @@ from freqtrade.exchange import get_ticker_history from freqtrade.logger import Logger 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]: diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index d8af47326..5cedb093c 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -32,7 +32,7 @@ class Backtesting(object): def __init__(self, config: Dict[str, Any]) -> None: # 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.config = config self.analyze = None @@ -301,7 +301,7 @@ def start(args: Namespace) -> None: """ # Initialize logger - logger = Logger(name=__name__).get_logger() + logger = Logger(__name__).get_logger() logger.info('Starting freqtrade in Backtesting mode') # Initialize configuration diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 7dcd46fd2..551c3e860 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -44,7 +44,7 @@ class Hyperopt(Backtesting): super().__init__(config) # 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() # 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) # Initialize logger - logger = Logger(name=__name__).get_logger() + logger = Logger(__name__).get_logger() logger.info('Starting freqtrade in Hyperopt mode') # Initialize configuration diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index db6ff69d1..b052f6775 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -29,7 +29,7 @@ class RPC(object): """ self.freqtrade = freqtrade self.logger = Logger( - name=__name__, + __name__, level=self.freqtrade.config.get('loglevel') ).get_logger() diff --git a/freqtrade/rpc/rpc_manager.py b/freqtrade/rpc/rpc_manager.py index fb18a8d73..6bd1f69d0 100644 --- a/freqtrade/rpc/rpc_manager.py +++ b/freqtrade/rpc/rpc_manager.py @@ -20,7 +20,7 @@ class RPCManager(object): # Init the logger self.logger = Logger( - name=__name__, + __name__, level=self.freqtrade.config.get('loglevel') ).get_logger() diff --git a/freqtrade/strategy/strategy.py b/freqtrade/strategy/strategy.py index d7a89d1de..c6e6e49f7 100644 --- a/freqtrade/strategy/strategy.py +++ b/freqtrade/strategy/strategy.py @@ -27,7 +27,7 @@ class Strategy(object): :param config: :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 if 'strategy' in config: diff --git a/freqtrade/tests/test_logger.py b/freqtrade/tests/test_logger.py index 8e094b2d1..3e38084ad 100644 --- a/freqtrade/tests/test_logger.py +++ b/freqtrade/tests/test_logger.py @@ -12,13 +12,13 @@ def test_logger_object() -> None: Test the Constants object has the mandatory Constants :return: None """ - logger = Logger() + logger = Logger('') assert logger.name == '' assert logger.level == 20 assert logger.level is logging.INFO 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 != '' assert logger.level == 30 diff --git a/scripts/plot_dataframe.py b/scripts/plot_dataframe.py index 285ba6d97..1bb944c7b 100755 --- a/scripts/plot_dataframe.py +++ b/scripts/plot_dataframe.py @@ -28,7 +28,7 @@ from freqtrade.logger import Logger import freqtrade.optimize as optimize -logger = Logger(name="Graph dataframe").get_logger() +logger = Logger(__name__).get_logger() def plot_analyzed_dataframe(args: Namespace) -> None: diff --git a/scripts/plot_profit.py b/scripts/plot_profit.py index 022bbf33c..1c025ce1d 100755 --- a/scripts/plot_profit.py +++ b/scripts/plot_profit.py @@ -30,7 +30,7 @@ import freqtrade.optimize as optimize import freqtrade.misc as misc -logger = Logger(name="Graph profits").get_logger() +logger = Logger(__name__).get_logger() # data:: [ pair, profit-%, enter, exit, time, duration]