code: def setup_logging(level, monchrome=False, log_file=None):
      '''
      Utility function for setting up logging.
      '''
      # Logging to file
      if log_file:
          logging.basicConfig(filename=log_file, filemode='w',
                              level=logging.DEBUG)
  
      # Pretty color terminal logging
      ch = logging.StreamHandler()
      ch.setLevel(logging.DEBUG)
      formatter = ColoredFormatter("%(levelname)s: %(message)s", monchrome)
      ch.setFormatter(formatter)
      # Which packages do we want to log from.
      packages = ('__main__', 'fusesoc',)
      for package in packages:
          logger = logging.getLogger(package)
          logger.addHandler(ch)
          logger.setLevel(level)
      # Warning only packages
      warning_only_packages = []
      for package in warning_only_packages:
          logger = logging.getLogger(package)
          logger.addHandler(ch)
          logger.setLevel(logging.WARNING)
      logger.debug('Setup logging at level {}.'.format(level)f setup_logging(level, monchrome=False, log_file=None):
      '''
      Utility function for setting up logging.
      '''
      # Logging to file
      if log_file:
          logging.basicConfig(filename=log_file, filemode='w',
                              level=logging.DEBUG)
  
      # Pretty color terminal logging
      ch = logging.StreamHandler()
      ch.setLevel(logging.DEBUG)
      formatter = ColoredFormatter("%(levelname)s: %(message)s", monchrome)
      ch.setFormatter(formatter)
      # Which packages do we want to log from.
      packages = ('__main__', 'fusesoc',)
      for package in packages:
          logger = logging.getLogger(package)
          logger.addHandler(ch)
          logger.setLevel(level)
      # Warning only packages
      warning_only_packages = []
      for package in warning_only_packages:
          logger = logging.getLogger(package)
          logger.addHandler(ch)
          logger.setLevel(logging.WARNING)
      logger.debug('Setup logging at level {}.'.format(level))
docs: Utility function for setting up logging.