code: def logging_manager(
      *, debug: bool = False
  ) -> Generator[logging.Logger, None, None]:
      """Setup logging. If a failure starts here we won't
      be able to save the user in a reasonable way.
  
      Logging structure: there is one logger (the root logger)
      and in processes all events.  There are two handlers:
      stderr (INFO) and file handler (DEBUG).
      """
      formatter = Formatter(
          fmt="%(levelname)s: %(message)s", datefmt=""
      )
      root_logger = logging.getLogger("conda-pytorch")
      root_logger.setLevel(logging.DEBUG)
  
      console_handler = logging.StreamHandler()
      if debug:
          console_handler.setLevel(logging.DEBUG)
      else:
          console_handler.setLevel(logging.INFO)
      console_handler.setFormatter(formatter)
      root_logger.addHandler(console_handler)
  
      log_file = os.path.join(logging_run_dir(), "nightly.log")
  
      file_handler = logging.FileHandler(log_file)
      file_handler.setFormatter(formatter)
      root_logger.addHandler(file_handler)
      logging_record_argv()
  
      try:
          logging_rotate()
          print(f"log file: {log_file}")
          yield root_logger
      except Exception as e:
          logging.exception("Fatal exception")
          logging_record_exception(e)
          print(f"log file: {log_file}")
          sys.exit(1)
      except BaseException as e:
          # You could logging.debug here to suppress the backtrace
          # entirely, but there is no reason to hide it from technically
          # savvy users.
          logging.info("", exc_info=True)
          logging_record_exception(e)
          print(f"log file: {log_file}")
          sys.exit(1)
  
imports: import contextlib
  import datetime
  import functools
  import glob
  import json
  import logging
  import os
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
  import time
  import uuid
  from argparse import ArgumentParser
  from ast import literal_eval
  from typing import Any, Callable, cast, Dict, Generator, Iterable, Iterator, List, Optional, Sequence, Set, Tuple, TypeVar
label_desc: Use image node_id 6 for calling a global function with example usage: logging_manager() without return types