title: timer as decorator in a class using self.logger to log
body: <p>I have a class with a bunch of functions and I just implemented logging similar to the code below. Now I would like to time some functions and log the time they took to run. The example below works but I am not very satisfied with the implementation. Is there a better way? I am running this in python 3.6.9.</p>
  <pre><code>import logging
  from time import time, sleep
  
  class Cls(object):
      def __init__(self, name):
          print('Class initialized')
          self.name = name
          self.logger = logging.getLogger(self.name)
          self.logger.setLevel(logging.DEBUG)
          file_handler = logging.FileHandler('Log_'+self.name+'.log')
          file_handler.setLevel(logging.INFO)
          self.logger.addHandler(file_handler)
  
      def timer(function):
          &quot;&quot;&quot;
          times a function and logs the time it needed to run.
          &quot;&quot;&quot;
          def wraper(self, *args, **kwargs):
              start = time()
              result = function(self, *args,**kwargs)
              end = time()
              self.logger.info(f'The function {function.__name__} ran in {end-start} seconds.')
              return result
          return wraper
     @timer 
     def func(self):
          sleep(1)
  </code></pre>
  <p>Edit: The timer function does now not take self in as its first argument but a function. So it should be a staticmethod? But it can't be as the wraper function takes in self as an argument.
  Furthermore the timed functions need to take in self as the first argument else it does not work. I would prefer a more general solution with a wraper that takes in any (*args, **kwargs) such that I can time any function in my class.</p>