code: def redirect_custom_log(
      func: Callable[[Type, Context, OperandType], None]
  ):
      """
      Redirect stdout to a file by wrapping ``Operand.execute(ctx, op)``
      """
  
      @functools.wraps(func)
      def wrap(cls, ctx: Context, op: OperandType):
          custom_log_dir = ctx.new_custom_log_dir()
  
          if custom_log_dir is None:
              return func(cls, ctx, op)
  
          log_path = os.path.join(custom_log_dir, op.key)
  
          with _LogWrapper(ctx, op, log_path):
              return func(cls, ctx, op)
  
      return wrap
  
imports: import functools
  import io
  import os
  import sys
  import textwrap
  import weakref
  from typing import List, Callable, Type
  from ..typing import OperandType, TileableType, SessionType
  from .context import Context
label_desc: Use image node_id 1 for calling a global function with example usage: redirect_custom_log(func) and returns: wrap, func, func