code: def init_logging(logfile=DEFAULT_LOGNAME, default=None, level=logging.INFO):
      
  
      if logfile == "INDEF":
          if not is_blank(default):
              logname = fileutil.buildNewRootname(default, '.log')
          else:
              logname = DEFAULT_LOGNAME
      elif logfile not in [None, "" , " "]:
          if logfile.endswith('.log'):
              logname = logfile
          else:
              logname = logfile + '.log'
      else:
          logname = None
  
      if logname is not None:
          logutil.setup_global_logging()
          # Don't use logging.basicConfig since it can only be called once in a
          # session
          # TODO: Would be fine to use logging.config.dictConfig, but it's not
          # available in Python 2.5
          global _log_file_handler
          root_logger = logging.getLogger()
          if _log_file_handler:
              root_logger.removeHandler(_log_file_handler)
          # Default mode is 'a' which is fine
          _log_file_handler = logging.FileHandler(logname)
          # TODO: Make the default level configurable in the task parameters
          _log_file_handler.setLevel(level)
          _log_file_handler.setFormatter(
              logging.Formatter('[%(levelname)-8s] %(message)s'))
          root_logger.setLevel(level)
          root_logger.addHandler(_log_file_handler)
  
          print('Setting up logfile : ', logname)
  
          #stdout_logger = logging.getLogger('stsci.tools.logutil.stdout')
          # Disable display of prints to stdout from all packages except
          # drizzlepac
          #stdout_logger.addFilter(logutil.EchoFilter(include=['drizzlepac']))
      else:
          print('No trailer file created...')
docs: Set up logger for capturing stdout/stderr messages.
  
      Must be called prior to writing any messages that you want to log.