code: def logged(f):
      """Decorator that logs unique calls to ``f``.
  
      The call log can always be retrieved using ``f.call_log``.
      Decorating a function that is already being logged has
      no effect.
  
      The call log is an instance of CallLog.
  
      >>> @logged
      ... def f(x): return x+1
      >>> a, b, c = f(1), f(1), f(2)
      >>> print(f.call_log)
      {'pos_0': 1} --> 2
      {'pos_0': 2} --> 3
  
      logged as inner decorator:
  
      >>> from .constraints import constrained
      >>> @logged
      ... @constrained([lambda x: x > 1])
      ... def f2(x): return x+1
      >>> len(f2.call_log)
      0
      >>> f2(2)
      3
      >>> print(f2.call_log)
      {'pos_0': 2} --> 3
  
      logged as outer decorator:
  
      >>> from .constraints import constrained
      >>> @constrained([lambda x: x > 1])
      ... @logged
      ... def f3(x): return x+1
      >>> len(f3.call_log)
      0
      >>> f3(2)
      3
      >>> print(f3.call_log)
      {'pos_0': 2} --> 3
  
      >>> @logged
      ... def f(x): return 1
      >>> f(1)
      1
      >>> print(f.call_log)
      {'pos_0': 1} --> 1
      >>> @logged
      ... @wraps(f)
      ... def f2(x): return f(x)
      >>> print(f2.call_log)
      {'pos_0': 1} --> 1
  
      """
      if hasattr(f, "call_log"):
          return f
  
      @wraps(f)
      def wrapped_f(*args, **kwargs):
          value = wrapped_f.call_log.get(*args, **kwargs)
          if value is None:
              value = f(*args, **kwargs)
              wrapped_f.call_log.insert(value, *args, **kwargs)
          return value
  
      wrapped_f.call_log = CallLog()
      return wrapped_f
  
imports: import collections
  import functools
  import threading
  import operator
label_desc: Use image node_id 2 for calling a global function with example usage: logged(f) and returns: wrapped_f, f, value