def METHOD_NAME(msg, logname=''):
    """Generic logging function."""
    if len(msg) > 1000:
        # See http://bugs.python.org/issue11907 and RFC-3164
        # break up huge msg into chunks and send 1000 characters at a time
        msg_buffer = msg
        while msg_buffer:
            logging.info(msg_buffer[:1000])
            msg_buffer = msg_buffer[1000:]
    else:
        logging.info(msg)  # noop unless configure_syslog() is called first.
    # date/time format string
    formatstr = '%b %d %Y %H:%M:%S %z'
    if not logname:
        # use our regular logfile
        logpath = prefs.pref('LogFile')
    else:
        logpath = os.path.join(os.path.dirname(prefs.pref('LogFile')), logname)
    try:
        fileobj = codecs.open(logpath, mode='a', encoding='UTF-8')
        try:
            fileobj.write("%s %s\n" % (time.strftime(formatstr), msg))
        except (OSError, IOError):
            pass
        fileobj.close()
    except (OSError, IOError):
        pass