old_contents: class OkupyException(Exception):
  	def __init__(self, value):
  		self.value = value
  	def __str__(self):
  		return repr(self.value)
  
new_contents: from django.contrib.sites.models import Site
  
  
  class OkupyException(Exception):
      '''
      Custon exception class
      '''
      def __init__(self, value):
          self.value = value
      def __str__(self):
          return repr(self.value)
  
  def log_extra_data(request = None, form = None):
      '''
      Extra data needed by the custom formatter
      All values default to None
      '''
      log_extra_data = {
          'site_name': Site.objects.get_current().name or 'None',
          'clientip':request.META.get('REMOTE_ADDR','None'),
      }
      if form:
          log_extra_data['username'] = form.data.get('username','None')
      else:
          if request.user.is_authenticated():
              '''
              Handle logged in users
              '''
              log_extra_data['username'] = request.user.name
          else:
              '''
              Handle anonymous users
              '''
              log_extra_data['username'] = 'Anonymous'
      return log_extra_data
  
subject: Add a log_extra_data function, which returns a dictionary needed by the logging formatter Add comments in the lib