v1.18.x
barisusakli 10 years ago
parent c827485de5
commit 394a01fdef

@ -161,14 +161,14 @@ adminController.database.get = function(req, res, next) {
};
adminController.events.get = function(req, res, next) {
events.getLog(function(err, data) {
events.getLog(-1, 5000, function(err, data) {
if(err || !data) {
return next(err);
}
data = data.toString().split('\n').reverse().join('\n');
res.render('admin/advanced/events', {
eventdata: data
eventdata: data.data,
next: data.next
});
});
};

@ -101,15 +101,39 @@ var fs = require('fs'),
});
};
events.getLog = function(callback) {
events.getLog = function(end, len, callback) {
var logFile = path.join(nconf.get('base_dir'), logFileName);
fs.readFile(logFile, function(err, res) {
if(err) {
fs.stat(logFile, function(err, stat) {
if (err) {
return callback(null, 'No logs found!');
}
callback(null, res);
var buffer = '';
var size = stat.size;
if (end === -1) {
end = size;
}
end = parseInt(end, 10);
var start = Math.max(0, end - len);
var rs = fs.createReadStream(logFile, {start: start, end: end});
rs.addListener('data', function(lines) {
buffer += lines.toString();
});
rs.addListener('end', function() {
var firstNewline = buffer.indexOf('\n');
if (firstNewline !== -1) {
buffer = buffer.slice(firstNewline);
buffer = buffer.split('\n').reverse().join('\n');
}
callback(null, {data: buffer, next: end - buffer.length});
})
});
};
}(module.exports));

@ -241,4 +241,12 @@ SocketAdmin.clearLog = function(socket, data, callback) {
fs.truncate(logPath, callback);
};
SocketAdmin.getMoreEvents = function(socket, next, callback) {
if (parseInt(next, 10) < 0) {
return callback(null, {data: [], next: next});
}
events.getLog(next, 5000, callback);
};
module.exports = SocketAdmin;

@ -2,9 +2,30 @@
<div class="col-sm-9">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-calendar-o"></i> Events</div>
<div class="panel-body">
<div class="panel-body" data-next="{next}">
<pre>{eventdata}</pre>
</div>
</div>
</div>
</div>
</div>
<script>
require(['forum/infinitescroll'], function(infinitescroll) {
infinitescroll.init(function(direction) {
if (direction < 0 && !$('.events').length) {
return;
}
infinitescroll.loadMore('admin.getMoreEvents', $('[data-next]').attr('data-next'), function(events, done) {
if (events.data && events.data.length) {
$('.panel-body pre').append(events.data);
$('[data-next]').attr('data-next', events.next);
}
done();
});
});
});
</script

Loading…
Cancel
Save