Handles logging.

        | Logs to a sql db.

def do_log(self, target, nick, msg, msgtype):
        """Handles logging.

        | Logs to a sql db.

        """
        if not isinstance(msg, str):
            raise Exception("IRC doesn't like it when you send it a %s" % type(msg).__name__)
        target = target.lower()
        flags = 0
        # Properly handle /msg +#channel
        if target.startswith(('+', '@')):
            target = target[1:]
        with self.data_lock:
            if target in self.channels:
                if self.opers[target].get(nick, False):
                    flags |= 1
                if self.voiced[target].get(nick, False):
                    flags |= 2
            else:
                target = 'private'
        # FIXME: should we special-case this?
        # strip ctrl chars from !creffett
        msg = msg.replace('\x02\x038,4', '<rage>')
        self.db.log(nick, target, flags, msg, msgtype)

        if self.log_to_ctrlchan:
            ctrlchan = self.config['core']['ctrlchan']
            if target != ctrlchan:
                ctrlmsg = "%s:%s:%s:%s" % (target, msgtype, nick, msg)
                # If we call self.send, we'll get a infinite loop.
                self.connection.privmsg(ctrlchan, ctrlmsg.strip())