From 8114d790a5f3b887f85713e9b4201512aed43713 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Sun, 7 Jul 2019 01:40:52 +0300 Subject: [PATCH] commit forgotten loggers.py --- freqtrade/loggers.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 freqtrade/loggers.py diff --git a/freqtrade/loggers.py b/freqtrade/loggers.py new file mode 100644 index 000000000..56dcf2486 --- /dev/null +++ b/freqtrade/loggers.py @@ -0,0 +1,50 @@ +import logging +import sys + +from logging.handlers import RotatingFileHandler +from typing import Any, Dict, List + + +logger = logging.getLogger(__name__) + + +def _set_loggers(verbosity: int = 0) -> None: + """ + Set the logging level for Third party libs + :return: None + """ + + logging.getLogger('requests').setLevel( + logging.INFO if verbosity <= 1 else logging.DEBUG + ) + logging.getLogger("urllib3").setLevel( + logging.INFO if verbosity <= 1 else logging.DEBUG + ) + logging.getLogger('ccxt.base.exchange').setLevel( + logging.INFO if verbosity <= 2 else logging.DEBUG + ) + logging.getLogger('telegram').setLevel(logging.INFO) + + +def setup_logging(config: Dict[str, Any]) -> None: + """ + Process --loglevel, --logfile options + """ + # Log level + verbosity = config['verbosity'] + + # Log to stdout, not stderr + log_handlers: List[logging.Handler] = [logging.StreamHandler(sys.stdout)] + + if config.get('logfile'): + log_handlers.append(RotatingFileHandler(config['logfile'], + maxBytes=1024 * 1024, # 1Mb + backupCount=10)) + + logging.basicConfig( + level=logging.INFO if verbosity < 1 else logging.DEBUG, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + handlers=log_handlers + ) + _set_loggers(verbosity) + logger.info('Verbosity set to %s', verbosity)