
from __future__ import division


class HalError(RuntimeError):
    def __init__(self, string=''):

        # Get the username
        try:
            from getpass import getuser
            username = getuser()
        except Exception:
            username = 'Dave'

        # Put in HAL error text.
        text = 'I\'m sorry {0}. I\'m afraid I can\'t do that. {1}'.format(
            username, string)

        # Init base class
        RuntimeError.__init__(self, text)


def halraiser(e):
    ''' Function to re-raise an exception with a Hal message. '''

    # Get the username
    try:
        from getpass import getuser
        username = getuser()
    except Exception:
        username = 'Humanoid'

    # Put in HAL error text.
    text = 'I\'m sorry {0}. I\'m afraid I can\'t do that.'.format(username)

    # Append to exception
    if len(e.args) == 0:
        e.args = (text,)
    elif len(e.args) == 1:
        e.args = (text + ' ' + e.args[0],)
    else:
        e.args = (text,) + e.args

    # Reraise the exception
    raise


from __future__ import division


class HalError(RuntimeError):
    def __init__(self, string=''):

        # Get the username
        try:
            from getpass import getuser
            username = getuser()
        except Exception:
            username = 'Dave'

        # Put in HAL error text.
        text = 'I\'m sorry {0}. I\'m afraid I can\'t do that. {1}'.format(
            username, string)

        # Init base class
        RuntimeError.__init__(self, text)


def halraiser(e):
    ''' Function to re-raise an exception with a Hal message. '''
    import logging

    # Get the log and write the error to the log file
    log = logging.getLogger(__name__)
    log.error(e)

    # Get the username
    try:
        from getpass import getuser
        username = getuser()
    except Exception:
        username = 'Humanoid'

    # Put in HAL error text.
    text = 'I\'m sorry {0}. I\'m afraid I can\'t do that.'.format(username)

    # Append to exception
    if len(e.args) == 0:
        e.args = (text,)
    elif len(e.args) == 1:
        e.args = (text + ' ' + e.args[0],)
    else:
        e.args = (text,) + e.args

    # Reraise the exception
    raise

Print out errors to log.
Print out errors to log.
  
  from __future__ import division
  
  
  class HalError(RuntimeError):
      def __init__(self, string=''):
  
          # Get the username
          try:
              from getpass import getuser
              username = getuser()
          except Exception:
              username = 'Dave'
  
          # Put in HAL error text.
          text = 'I\'m sorry {0}. I\'m afraid I can\'t do that. {1}'.format(
              username, string)
  
          # Init base class
          RuntimeError.__init__(self, text)
  
  
  def halraiser(e):
      ''' Function to re-raise an exception with a Hal message. '''
+     import logging
+ 
+     # Get the log and write the error to the log file
+     log = logging.getLogger(__name__)
+     log.error(e)
  
      # Get the username
      try:
          from getpass import getuser
          username = getuser()
      except Exception:
          username = 'Humanoid'
  
      # Put in HAL error text.
      text = 'I\'m sorry {0}. I\'m afraid I can\'t do that.'.format(username)
  
      # Append to exception
      if len(e.args) == 0:
          e.args = (text,)
      elif len(e.args) == 1:
          e.args = (text + ' ' + e.args[0],)
      else:
          e.args = (text,) + e.args
  
      # Reraise the exception
      raise
  
Print out errors to log.
## Code Before:

from __future__ import division


class HalError(RuntimeError):
    def __init__(self, string=''):

        # Get the username
        try:
            from getpass import getuser
            username = getuser()
        except Exception:
            username = 'Dave'

        # Put in HAL error text.
        text = 'I\'m sorry {0}. I\'m afraid I can\'t do that. {1}'.format(
            username, string)

        # Init base class
        RuntimeError.__init__(self, text)


def halraiser(e):
    ''' Function to re-raise an exception with a Hal message. '''

    # Get the username
    try:
        from getpass import getuser
        username = getuser()
    except Exception:
        username = 'Humanoid'

    # Put in HAL error text.
    text = 'I\'m sorry {0}. I\'m afraid I can\'t do that.'.format(username)

    # Append to exception
    if len(e.args) == 0:
        e.args = (text,)
    elif len(e.args) == 1:
        e.args = (text + ' ' + e.args[0],)
    else:
        e.args = (text,) + e.args

    # Reraise the exception
    raise

## Instruction:
Print out errors to log.
## Code After:

from __future__ import division


class HalError(RuntimeError):
    def __init__(self, string=''):

        # Get the username
        try:
            from getpass import getuser
            username = getuser()
        except Exception:
            username = 'Dave'

        # Put in HAL error text.
        text = 'I\'m sorry {0}. I\'m afraid I can\'t do that. {1}'.format(
            username, string)

        # Init base class
        RuntimeError.__init__(self, text)


def halraiser(e):
    ''' Function to re-raise an exception with a Hal message. '''
    import logging

    # Get the log and write the error to the log file
    log = logging.getLogger(__name__)
    log.error(e)

    # Get the username
    try:
        from getpass import getuser
        username = getuser()
    except Exception:
        username = 'Humanoid'

    # Put in HAL error text.
    text = 'I\'m sorry {0}. I\'m afraid I can\'t do that.'.format(username)

    # Append to exception
    if len(e.args) == 0:
        e.args = (text,)
    elif len(e.args) == 1:
        e.args = (text + ' ' + e.args[0],)
    else:
        e.args = (text,) + e.args

    # Reraise the exception
    raise
