-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogphperror.js
84 lines (65 loc) · 1.77 KB
/
logphperror.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
*
* Author: Sherwin R. Terunez
* Contact: sherwinterunez@yahoo.com
*
* Description:
*
* NodeJS Log Server
*
* December 7, 2016
*
*/
// log receiver
const SERVER_IP = '192.168.1.80';
var io = require('./node_modules/socket.io-client');
var spawn = require('child_process').spawn;
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('end.\n');
});
var portfinder = require('portfinder');
portfinder.getPort(function (err, port) {
server.listen(port, '127.0.0.1', function () {
//console.log('Server running at http://%s:%d/', '127.0.0.1', port);
//console.log('Press CTRL+C to exit');
});
});
var app = function() {
var socket = io.connect('http://'+SERVER_IP+':8080/',{
'reconnection': true,
'reconnectionDelay': 10,
'reconnectionAttempts': 999999
});
var lines = 0;
socket.emit('call', '/var/log/php-fpm/www-error.log', function(resp, data) {
//console.log('server sent resp code ' + resp, data);
});
//tell socket.io to never give up :)
socket.on('error', function(){
console.log('socket error');
//socket.connect();
});
socket.on('disconnect', function(){
console.log('socket disconnect');
//socket.connect();
setTimeout( app, 5000 );
});
socket.on('connect', function() {
//console.log('Connected to:', socket.host);
});
socket.on('message', function(message) {
//console.log('Received message:', message);
//if (message.filename) {
// $('#info').html( '$ tail -f ' + message.filename );
//};
if (message.tail) {
//$('#tail').html( $('#tail').html() + message.tail );
//lines++
//$('#tail').scrollTop(lines*100)
console.log(message.tail);
}
});
};
app();