title: Using functools.wraps with a logging decorator
body: <p>I'm trying to write a simple decorator that logs a given statement before calling the decorated function. The logged statements should both appear to come from the same function, which I thought was the purpose of functools.wraps(). </p>
  
  <p>Why does the following code:</p>
  
  <pre><code>import logging
  logging.basicConfig(
      level=logging.DEBUG,
      format='%(funcName)20s - %(message)s')
  
  from functools import wraps
  
  def log_and_call(statement):
      def decorator(func):
          @wraps(func)
          def wrapper(*args, **kwargs):
              logging.info(statement)            
              return func(*args, **kwargs)
          return wrapper
      return decorator
  
  
  @log_and_call("This should be logged by 'decorated_function'")
  def decorated_function():
      logging.info('I ran')
  
  decorated_function()
  </code></pre>
  
  <p>result in log statements like:</p>
  
  <pre><code>             wrapper - This should be logged by 'decorated_function'
    decorated_function - I ran
  </code></pre>
  
  <p>I thought the call to wraps would rename wrapper with decorated_function's name.</p>
  
  <p>I'm using python 2.7.1.</p>