old_contents: #!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  from logbook import NestedSetup, NullHandler, FileHandler, MailHandler
  
  
  class LogbookConfig(object):
  
      def __init__(self, name, debug = False):
          self.debug_enabled = debug
          path_tmpl = 'log/{name}_{level}.log'
          mail_tmpl = '{name}_error@localhost'
          self.debug = path_tmpl.format(name = name, level = 'debug')
          self.info = path_tmpl.format(name = name, level = 'info')
          self.warn = path_tmpl.format(name = name, level = 'warn')
          self.err = path_tmpl.format(name = name, level = 'err')
          self.crit = path_tmpl.format(name = name, level = 'crit')
          self.from_mail = mail_tmpl.format(name = name)
          self.to_mails = ['me@localhost']
          self.smtp_server = 'localhost'
  
      def setup(self):
          # a nested handler setup can be used to configure more complex setups
          setup = [
              # make sure we never bubble up to the stderr handler
              # if we run out of setup handling
              NullHandler(),
              # then write messages that are at least info to to a logfile
              FileHandler(self.info, level='INFO', encoding='utf-8'),
              # then write messages that are at least warnings to to a logfile
              FileHandler(self.warn, level='WARNING', encoding='utf-8'),
              # then write messages that are at least errors to to a logfile
              FileHandler(self.err, level='ERROR', encoding='utf-8'),
              # then write messages that are at least critical errors to to a logfile
              FileHandler(self.crit, level='CRITICAL', encoding='utf-8'),
              # errors should then be delivered by mail and also be kept
              # in the application log, so we let them bubble up.
              #MailHandler(self.from_mail, self.to_mails, level='ERROR',
              #    bubble=True, server_addr=(self.smtp_server, 25))
          ]
          if self.debug_enabled:
              setup.insert(1, FileHandler(self.debug, level='DEBUG', encoding='utf-8'))
          return NestedSetup(setup)
  
new_contents: #!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  from logbook import NestedSetup, NullHandler, FileHandler, MailHandler
  import os
  
  dest_mails = []
  smtp_server = None
  smtp_port = 0
  src_server = None
  
  def setup(name, path = 'log', enable_debug = False):
      path_tmpl = os.path.join(path, '{name}_{level}.log')
      info = path_tmpl.format(name = name, level = 'info')
      warn = path_tmpl.format(name = name, level = 'warn')
      err = path_tmpl.format(name = name, level = 'err')
      crit = path_tmpl.format(name = name, level = 'crit')
      # a nested handler setup can be used to configure more complex setups
      setup = [
          # make sure we never bubble up to the stderr handler
          # if we run out of setup handling
          NullHandler(),
          # then write messages that are at least info to to a logfile
          FileHandler(info, level='INFO', encoding='utf-8'),
          # then write messages that are at least warnings to to a logfile
          FileHandler(warn, level='WARNING', encoding='utf-8'),
          # then write messages that are at least errors to to a logfile
          FileHandler(err, level='ERROR', encoding='utf-8'),
          # then write messages that are at least critical errors to to a logfile
          FileHandler(crit, level='CRITICAL', encoding='utf-8'),
      ]
      if enable_debug:
          debug = path_tmpl.format(name = name, level = 'debug')
          setup.insert(1, FileHandler(debug, level='DEBUG', encoding='utf-8'))
      if src_server is not None and smtp_server is not None \
              and smtp_port != 0 and len(dest_mails) != 0:
          mail_tmpl = '{name}_error@{src}'
          from_mail = mail_tmpl.format(name = name, src = src_server)
          print from_mail
          # errors should then be delivered by mail and also be kept
          # in the application log, so we let them bubble up.
          setup.append(MailHandler(from_mail, dest_mails, level='ERROR',
              bubble=True, server_addr=(smtp_server, smtp_port)))
  
      return NestedSetup(setup)
  
subject: remove unnecessary class