【发布时间】:2020-03-06 06:21:56
【问题描述】:
我正在尝试实现一个简单的 Web 界面,我可以在其中看到我的日志文件的 do tail -f。
找到下面的链接
https://thoughtbot.com/blog/real-time-online-activity-monitor-example-with-node-js-and-websocket
它似乎很旧,与现代node.j不兼容。
我尝试浏览 node.j` 文档,但无法解决此问题。 创建子进程会导致一些问题。
var filename = process.argv[2];
if (!filename)
return sys.puts("Usage: node watcher.js filename");
var tail = process.createChildProcess("tail", ["-f", filename]);
console.log("start tailing");
tail.addListener("output", function (data) {
console(data);
});
var http = require("http");
http.createServer(function(req,res){
res.sendHeader(200,{"Content-Type": "text/plain"});
tail.addListener("output", function (data) {
res.sendBody(data);
});
}).listen(8000);
我想将此tailf'd 日志发送到另一台服务器,该服务器将运行nodejs 应用程序来读取它。 有人可以帮帮我吗?
【问题讨论】:
标签: javascript node.js linux logging websocket