Created
December 13, 2009 16:20
-
-
Save xenda/255474 to your computer and use it in GitHub Desktop.
Some test with Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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