such as

def log_message(message, log_file=None, file_open=True, console=False):
    """Logs a message in a file and/or to console

       If log_file is set, logs the message in the file.
       If console is True, sends the message to console.
    """
    if console:
        console_log(message)
    if log_file is not None:
        if isinstance(message, unicode):
            message = message.encode("utf-8")
        if file_open:
            log_file = open(log_file, 'a', 0)
        log_file.write(message)
        if file_open:
            log_file.close()
        else:
            log_file.flush()