def log_file(msg, filename="game.log"):
    """
    Arbitrary file logger using threads.

    Args:
        filename (str, optional): Defaults to 'game.log'. All logs
            will appear in the logs directory and log entries will start
            on new lines following datetime info.

    """
    global LOG_FILE_HANDLES, _LOGDIR, _TIMEZONE

    if not _LOGDIR:
        from django.conf import settings
        _LOGDIR = settings.LOG_DIR
    if not _TIMEZONE:
        from django.utils import timezone as _TIMEZONE

    def callback(filehandle, msg):
        "Writing to file and flushing result"
        msg = "\n%s [-] %s" % (_TIMEZONE.now(), msg.strip())
        filehandle.write(msg)
        # since we don't close the handle, we need to flush
        # manually or log file won't be written to until the
        # write buffer is full.
        filehandle.flush()

    def errback(failure):
        "Catching errors to normal log"
        log_trace()

    # save to server/logs/ directory
    filename = os.path.join(_LOGDIR, filename)

    if filename in LOG_FILE_HANDLES:
        filehandle = LOG_FILE_HANDLES[filename]
    else:
        try:
            filehandle = open(filename, "a")
            LOG_FILE_HANDLES[filename] = filehandle
        except IOError:
            log_trace()
            return
    deferToThread(callback, filehandle, msg).addErrback(errback)
dataset/ETHPy150Open evennia/evennia/evennia/utils/logger.py/log_file/original