code: def log_method_calls(
      class_condition: typing.Callable[[typing.Any], bool]
      | None = None,
      method_condition: typing.Callable[[typing.Any], bool]
      | None = None,
  ):
      """A context manager to log method calls.
  
      All method calls will be logged by default. This behavior can be overriden by passing filtering
      functions.
  
      Parameters
      ----------
      class_condition
          A function which determines if a class should be logged or not.
      method_condition
          A function which determines if a method should be logged or not.
  
      Examples
      --------
      >>> import io
      >>> import logging
      >>> from river import anomaly
      >>> from river import compose
      >>> from river import datasets
      >>> from river import preprocessing
      >>> from river import utils
  
      >>> model = compose.Pipeline(
      ...     preprocessing.MinMaxScaler(),
      ...     anomaly.HalfSpaceTrees(seed=42)
      ... )
  
      >>> class_condition = lambda x: x.__class__.__name__ in ('MinMaxScaler', 'HalfSpaceTrees')
  
      >>> logger = logging.getLogger()
      >>> logger.setLevel(logging.DEBUG)
  
      >>> logs = io.StringIO()
      >>> sh = logging.StreamHandler(logs)
      >>> sh.setLevel(logging.DEBUG)
      >>> logger.addHandler(sh)
  
      >>> with utils.log_method_calls(class_condition):
      ...     for x, y in datasets.CreditCard().take(1):
      ...         score = model.score_one(x)
      ...         model.learn_one(x)
  
      >>> print(logs.getvalue())
      MinMaxScaler.transform_one
      HalfSpaceTrees.score_one
      MinMaxScaler.learn_one
      MinMaxScaler.transform_one
      HalfSpaceTrees.learn_one
  
      >>> logs.close()
  
      """
      old = Base.__getattribute__
      class_condition = class_condition or (lambda x: True)
      method_condition = method_condition or (lambda x: True)
      Base.__getattribute__ = lambda self, name: _log_method_calls(  # type: ignore
          self, name, class_condition, method_condition
      )
      try:
          yield
      finally:
          Base.__getattribute__ = old
  
imports: from __future__ import annotations
  import collections
  import contextlib
  import copy
  import inspect
  import itertools
  import logging
  import sys
  import types
  import typing
label_desc: Use image node_id 2 for calling a global function with example usage: log_method_calls(class_condition, method_condition) without return types