Skip to content

Instantly share code, notes, and snippets.

@xenda
Created December 13, 2009 16:20
Show Gist options
  • Save xenda/255474 to your computer and use it in GitHub Desktop.
Save xenda/255474 to your computer and use it in GitHub Desktop.
Some test with Node.js
var sys = require('sys')
var filename = process.ARGV[2];
if (!filename)
return sys.puts("Usage: node node_logger.js filename");
var tail = process.createChildProcess("tail", ["-f", filename]);
sys.puts("listening to file " + filename);
var http = require("http");
http.createServer(function(req,res){
sys.puts("\n\n\n\n\n\n\nRequesting connection: " + req.method + " " + req.headers.host);
res.sendHeader(200,{"Content-Type": "text/plain"});
res.sendBody("As soon as the log rotates, you'll see it here\n");
tail.addListener("output", function (data) {
res.sendBody(data);
sys.puts("Sent log response");
});
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment