Answer the question
In order to leave comments, you need to log in
Error: throw new ERR_INVALID_CALLBACK. how to remove?
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
var fs = require("fs");
varutil = require('util');
varEOL = require('os').EOL;
function Log() {
// Nothing
}
module.exports = Log;
Log.prototype.setup = function(gameServer) {
if (!fs.existsSync('./logs')) {
// Make log folder
fs.mkdir('./logs');
}
switch (gameServer.config.serverLogLevel) {
case 2:
ip_log = fs.createWriteStream('./logs/ip.log', {flags : 'w'});
// Override
this.onConnect = function(ip) {
ip_log.write("["+this.formatTime()+"] Connect: " + ip + EOL);
};
this.onDisconnect = function(ip) {
ip_log.write("["+this.formatTime()+"] Disconnect: " + ip + EOL);
};
case 1:
console_log = fs.createWriteStream('./logs/console.log', {flags : 'w'});
console.log = function(d) { //
console_log.write(util.format(d) + EOL);
process.stdout.write(util.format(d) + EOL);
};
//
this.onCommand = function(command) {
console_log.write(">" + command + EOL);
case 0:
// Prevent crashes
process.on('uncaughtException', function(err) {
console.log(err.stack);
});
default:
break;
}
};
Log.prototype.onConnect = function(ip) {
// Nothing
};
Log.prototype.onDisconnect = function(ip) {
// Nothing
};
Log.prototype.onCommand = function(command) {
// Nothing
}
Log.prototype.formatTime = function() {
var date = new Date();
varhour = date.getHours();
hour = (hour < 10 ? "0" : "") + hour;
varmin = date.getMinutes();
min = (min < 10 ? "0" : "") + min;
return hour + ":" + min;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question