'Generate a new log-file with a default header.
Raises RuntimeError if the log has already been started'

def logstart(self, logfname=None, loghead=None, logmode=None, log_output=False, timestamp=False, log_raw_input=False):

    if (self.logfile is not None):
        raise RuntimeError(('Log    file    is    already    active:    %s' % self.logfname))
    if (logfname is not None):
        self.logfname = logfname
    if (loghead is not None):
        self.loghead = loghead
    if (logmode is not None):
        self.logmode = logmode
    self.timestamp = timestamp
    self.log_output = log_output
    self.log_raw_input = log_raw_input
    isfile = os.path.isfile
    logmode = self.logmode
    if (logmode == 'append'):
        self.logfile = io.open(self.logfname, 'a', encoding='utf-8')
    elif (logmode == 'backup'):
        if isfile(self.logfname):
            backup_logname = (self.logfname + '~')
            if isfile(backup_logname):
                os.remove(backup_logname)
            os.rename(self.logfname, backup_logname)
        self.logfile = io.open(self.logfname, 'w', encoding='utf-8')
    elif (logmode == 'global'):
        self.logfname = os.path.join(self.home_dir, self.logfname)
        self.logfile = io.open(self.logfname, 'a', encoding='utf-8')
    elif (logmode == 'over'):
        if isfile(self.logfname):
            os.remove(self.logfname)
        self.logfile = io.open(self.logfname, 'w', encoding='utf-8')
    elif (logmode == 'rotate'):
        if isfile(self.logfname):
            if isfile((self.logfname + '.001~')):
                old = glob.glob((self.logfname + '.*~'))
                old.sort()
                old.reverse()
                for f in old:
                    (root, ext) = os.path.splitext(f)
                    num = (int(ext[1:(-1)]) + 1)
                    os.rename(f, (((root + '.') + repr(num).zfill(3)) + '~'))
            os.rename(self.logfname, (self.logfname + '.001~'))
        self.logfile = io.open(self.logfname, 'w', encoding='utf-8')
    if (logmode != 'append'):
        self.logfile.write(self.loghead)
    self.logfile.flush()
    self.log_active = True
