code: def add_logging_args(parser: argparse.ArgumentParser, patch: bool = True,
                       erase_args: bool = True) -> None:
      
      parser.add_argument("--log-level", default="INFO", choices=logging._nameToLevel,
                          help="Logging verbosity.")
      parser.add_argument("--log-structured", action="store_true",
                          help="Enable structured logging (JSON record per line).")
      parser.add_argument("--log-config",
                          help="Path to the file which sets individual log levels of domains.")
      # monkey-patch parse_args()
      # custom actions do not work, unfortunately, because they are not invoked if
      # the corresponding --flags are not specified
  
      def _patched_parse_args(args=None, namespace=None) -> argparse.Namespace:
          args = parser._original_parse_args(args, namespace)
          setup(args.log_level, args.log_structured, args.log_config)
          if erase_args:
              for log_arg in ("log_level", "log_structured", "log_config"):
                  delattr(args, log_arg)
          return args
  
      if patch and not hasattr(parser, "_original_parse_args"):
          parser._original_parse_args = parser.parse_args
          parser.parse_args = _patched_parse_args
docs: Add command line flags specific to logging.
  
      :param parser: `argparse` parser where to add new flags.
      :param erase_args: Automatically remove logging-related flags from parsed args.
      :param patch: Patch parse_args() to automatically setup logging.