code: def _setup_logger(self, level, log_file):
          
          if logger.handlers:
              return
          level = getattr(logging, level.upper())
          logger.setLevel(level)
          formatter = logging.Formatter(
              '[%(levelname)s] %(asctime)s - %(module)s.%(funcName)s() - %(message)s')
          handler = logging.StreamHandler()
          logger.addHandler(handler)
          handler.setFormatter(formatter)
          if not log_file:
              return
          try:
              handler = TimedRotatingFileHandler(log_file)
          except IOError:
              logger.error("Could not write to %s, falling back to stdout",
                           log_file)
          else:
              logger.addHandler(handler)
              handler.setFormatter(formatter)
docs: Setup log level and log file if set