import functools
import logging


def _wrap(behavior):
  """Wraps an arbitrary callable behavior in exception-logging."""
  @functools.wraps(behavior)
  def _wrapping(*args, **kwargs):
    try:
      return behavior(*args, **kwargs)
    except Exception as e:
      logging.exception('Unexpected exception from task run in logging pool!')
      raise
  return _wrapping