def msg(message, *args, **kwargs):
    """Prints a message from the server to the log file."""
    global log_file
    if log_file is None:
        log_file = sys.stderr
    if long_msg:
        file_name, line = caller_trace()
        file_name, file_type = os.path.splitext(file_name)
        if file_name.endswith('/__init__'):
            file_name = os.path.basename(os.path.dirname(file_name))
        elif file_name.endswith('/__main__'):
            file_name = "(-m) {0}".format(
                os.path.basename(os.path.dirname(file_name)))
        else:
            file_name = os.path.basename(file_name)
        head = '{0}{1} ({2}): '.format(file_name, file_type, line)
    else:
        head = '[SERVER] '
    out = StringIO()
    for line in message.format(*args, **kwargs).split('\n'):
        out.write('{0}{1}\n'.format(head, line))
    out.flush()
    out.seek(0)
    if _msg_stderr:
        sys.stderr.write(out.read())
        sys.stderr.flush()
    else:
        log_file.write(out.read())
        log_file.flush()
    out.close()
def msg ( message , * args , ** kwargs ) : global log_file if log_file is None : log_file = sys . stderr if long_msg : file_name , line = caller_trace ( ) file_name , file_type = os . path . splitext ( file_name ) if file_name . endswith ( '/__init__' ) : file_name = os . path . basename ( os . path . dirname ( file_name ) ) elif file_name . endswith ( '/__main__' ) : file_name = "(-m) {0}" . format ( os . path . basename ( os . path . dirname ( file_name ) ) ) else : file_name = os . path . basename ( file_name ) head = '{0}{1} ({2}): ' . format ( file_name , file_type , line ) else : head = '[SERVER] ' out = StringIO ( ) for line in message . format ( * args , ** kwargs ) . split ( '\n' ) : out . write ( '{0}{1}\n' . format ( head , line ) ) out . flush ( ) out . seek ( 0 ) if _msg_stderr : sys . stderr . write ( out . read ( ) ) sys . stderr . flush ( ) else : log_file . write ( out . read ( ) ) log_file . flush ( ) out . close ( )
Prints a message from the server to the log file.