0

我正在构建一个跟踪日志并将其显示在客户端上的小应用程序。但是,当我在日志中附加行时,我会丢失一些数据。

这是相关的 Python 处理程序:

@socketio.on('Request logs')
def handle_request_logs():
    logfile = '/path/to/some_log.log'

    # gets last 25 lines from logfile
    last_n_lines = tailer.tail(open(logfile), 25)

    # sends the initial 25 lines
    emit('Initial send', { 'lines' : last_n_lines })

    # emits lines that were appended to logfile
    @copy_current_request_context
    def tail(logfile):
        for line in tailer.follow(open(logfile)):
            print("About to emit {0}".format(line))
            emit('log', { 'line' : line })

    # emit added lines as they come
    t = threading.Thread(target=tail, args=(logfile,))
    t.start()

这是接收的JS 'log'

  socket.on('log', function(data) {
      alert("Got some data: ", data['line']);
  });

每当我将某些内容附加到日志(例如echo 'hello, world!' >> /path/to/some_log.log)时,我都会在客户端上看到一条带有消息的警报 "Got some data: "。但是,我的服务器打印"About to emit hello, world!".

为什么会这样?

4

1 回答 1

1

您的警报中有一个逗号 (javascript)。它可能应该是用于连接的 +。

于 2016-02-19T21:25:26.167 回答