Permalink
Browse files

Stream de log

  • Loading branch information...
1 parent 1cbf594 commit 4d6394b6c34621ec322408c6753f760acc863c6b @emerleite committed May 17, 2011
Showing with 46 additions and 0 deletions.
  1. +9 −0 app.js
  2. +18 −0 log.js
  3. +19 −0 public/log.html
View
9 app.js
@@ -0,0 +1,9 @@
+var connect = require('connect');
+
+var server = connect.createServer(
+ connect.favicon()
+ , connect.logger()
+ , connect.static(__dirname + '/public')
+);
+
+server.listen(8000);
View
18 log.js
@@ -0,0 +1,18 @@
+var connect = require('connect');
+var io = require('socket.io');
+var spawn = require('child_process').spawn;
+
+var app = connect.createServer(
+ connect.favicon()
+ , connect.logger()
+ , connect.static(__dirname + '/public')
+);
+app.listen(8001);
+
+var socket = io.listen(app, {flashPolicyServer: false});
+
+var tail = spawn('tail', ['-f', './nohup.out']);
+
+tail.stdout.on('data', function (data) {
+ socket.broadcast(data.toString('utf8'));
+});
View
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <script src="/js/jquery.min.js" type="text/javascript"></script>
+ <script src="/socket.io/socket.io.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ $(document).ready(function() {
+ var log = new io.Socket();
+ log.connect();
+ log.on('message', function (message) {
+ $('#log').append(message + "<br/>");
+ window.scrollTo(0, document.body.scrollHeight);
+ });
+ });
+ </script>
+ </head>
+ <body>
+ <div id="log"></div>
+ </body>
+</html>

0 comments on commit 4d6394b

Please sign in to comment.