CyberPunkMetalHead / gateio-crypto-trading-bot-binance-announcements-new-coins

This is a crypto trading bot that scans the Binance Annoucements page for new coins, and places trades on Gateio
MIT License
1.21k stars 303 forks source link

Turn off console logging. #80

Closed DominicFrei closed 2 years ago

DominicFrei commented 2 years ago

This PR removed the console log. We do log to a file already anyway, removing the console saves us valuable time.

Jrjy3 commented 2 years ago

Maybe this would be best as a config variable. I like seeing the live output of the bot, and it helps me see if I ran into the rare issue of a failed network request crashing one of the threads. Maybe something like CONSOLE_LOGGING: True as a default in the config under the logging section.

Jrjy3 commented 2 years ago

I had a minute to do it. I tested this and it works as intended. Just commit this to your branch and it should be good to go.

Here's the update to logger.py:

# Get logging variables
log_level = config['LOGGING']['LOG_LEVEL']
log_file = config['LOGGING']['LOG_FILE']
log_to_console = config['LOGGING']['CONSOLE_LOGGING']

file_handler = TimedRotatingFileHandler(log_path, when="midnight")
if log_to_console:
    log.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                    handlers=[file_handler, logging.StreamHandler()])
else:
    log.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                    handlers=[file_handler])
logger = logging.getLogger(__name__)
level = logging.getLevelName(log_level)
logger.setLevel(level)

Also update config.example.yml:

  LOGGING:
    CONSOLE_LOGGING: True
    LOG_LEVEL: INFO
    LOG_FILE: bot.log
DominicFrei commented 2 years ago

@Jrjy3 Yup, it does. Implemented it at the same time too. ;) I might have one more addition to this though. So in case this gets approved please wait a moment with the merge. I don't like the duplicated code in my solution.

DominicFrei commented 2 years ago

Alright, done. Ready for review again.