示例#1
0
var initCallbacks = function(model) {
    var AdRecord = model;
    // Tail the pi's DNS query logfile
    t.on('line', function(data) {
        // pluck out IP from logfile entry
    	var ad_domain = util.getIP(data);
    	util.geolocate(ad_domain, function(response) {
            try {
                var res = JSON.parse(response);
                if (!!res.city == false)
                    res.city = 'N/A';

                AdRecord.create({
                    domain : ad_domain,
                    ip : res['ip'],
                    city : res['city'],
                    country : res['country_name'],
                    coordinate : res['latitude'] + ',' + res['longitude']
                }, function(err, adloc) {
                    if (err)
                        console.log('geolocate->database eror: ', err);
                });

            // if JSON parse error... :(
            } catch(err) {
                console.log('parse... ', err);
            }
    	});
    });
    t.on('error', function(error) {
    	console.log('always-tail outfile error: ', error);
    });
};
示例#2
0
文件: log.js 项目: Atlante45/hifi
        diff.add.forEach(function(addedLogFilePath) {
            const START_AT_X_BYTES_FROM_END = 10000;
            var cleanFilePath = cleanPath(addedLogFilePath);

            // For larger files we won't want to start tailing from the beginning of the file,
            // so start `START_AT_X_BYTES_FROM_END` bytes from the end of the file.
            var start = 0;
            try {
                var fileInfo  = fs.statSync(cleanFilePath);
                start = Math.max(0, fileInfo.size - START_AT_X_BYTES_FROM_END);
            } catch (e) {
                console.error("ERROR READING FILE INFO", e);
            }
            var logTail = new Tail(cleanFilePath, '\n', { start: start, interval: 500 });

            logTail.on('line', function(msg) {
                pendingLines[stream].push(msg);
            });

            logTail.on('error', function(error) {
                console.log("ERROR:", error);
            });

            logTail.watch();

            watchList[addedLogFilePath] = logTail;
            console.log("Watching", cleanFilePath);
        });
var ah_dashboard_plugin = function(api, next){
  var path = require('path');
  var TS = require('redis-timeseries');
  var Tail = require('always-tail');
  var timeSeries = new TS(api.redis.client);
  api.ahDashboard = {};
  api.ahDashboard.timesSeries = timeSeries;
  api.ahDashboard.prevStats = {};
  api.chatRoom.add("logMessages");
  var spawn = require('child_process').spawn;


  tail = new Tail(api.config.general.paths.log[0] + path.sep + api.pids.title + '.log');

  tail.on("line", function(data) {
    api.chatRoom.broadcast({room: "logMessages"}, "logMessages", data.toString());
  });

  tail.on("error", function(error) {
    console.log('ERROR: ', error);
  });
  next();
}
示例#4
0
						simHandle.logPaths.forEach(function (logPath) {
							if (fs.existsSync(logPath)) {
								var files = fs.readdirSync(logPath),
									i = 0,
									l = files.length,
									file, appDir, stat, dt, docs, j, k;

								for (; i < l; i++) {
									if (fs.existsSync(file = path.join(logPath, /*guid*/files[i], 'Documents', options.logFilename))) {
										logFile = file;
										tail = new Tail(logFile, '\n', { interval: 500 } );
										tail.on('line', function (msg) {
											emitter.emit('logFile', msg);
										});
										tail.watch();
										found = true;
										return;
									}
								}
							}
						});
示例#5
0
		});
	}
}

function clear() {
	callbacks = {};
}

var middleware = [];

var access = new Tail(accessPath, /\r?\n/);
access.on('line', function (data) {
	middleware.forEach(function (m) {
		if (_.isFunction(m.onAccess)) {
			data = m.onAccess(data);
		}
	});
	if (!data.http_referer || refererFilters.indexOf(data.http_referer) === -1) {
		emit('access', data);
	}
});
access.on('error', function (data) {
	console.error('error:', data);
});

var log = new Tail(errorPath, /\r?\n/);
log.on('line', function (data) {
	middleware.forEach(function (m) {
		if (_.isFunction(m.onLog)) {
			data = m.onLog(data);
		}
	});