code: def create_log_and_print_function(level: str) -> Callable:
      def log_and_print(*args: Any, **kwargs: Any) -> None:
          try:
              method = getattr(logger.opt(lazy=True), level, None)
              if "print" in kwargs and kwargs["print"] is True:
                  del kwargs["print"]
                  print(*args, **kwargs)
                  if "end" in kwargs:
                      # clean up extra end for printinga
                      del kwargs["end"]
  
              if method is not None:
                  method(*args, **kwargs)
              else:
                  raise Exception(f"no method {level} on logger")
          except BaseException as e:
              msg = f"failed to log exception. {e}"
              try:
                  logger.debug(msg)
  
              except Exception as e:
                  print(f"{msg}. {e}")
  
      return log_and_print
  
imports: import logging
  import os
  import sys
  from typing import Any
  from typing import Callable
  from typing import NoReturn
  from typing import TextIO
  from typing import Union
  from loguru import logger
label_desc: Use image node_id 6 for calling a global function with example usage: create_log_and_print_function(level) and returns: log_and_print