This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
teemant-old/server/logger.js
2016-12-21 20:54:22 +02:00

51 lines
1.1 KiB
JavaScript

const util = require('util');
const config = require(__dirname+'/config');
module.exports.log = function() {
console.log.apply(null, arguments);
};
module.exports.debugLog = function() {
if(!config.server.debug) return;
console.log.apply(null, arguments);
};
module.exports.errorLog = function(errObj, specify) {
if(specify)
console.error(specify);
console.error(errObj);
if(errObj.stack)
console.error(errObj.stack);
};
module.exports.printRuntimeStats = function(runtime_stats, connections) {
if(!config.server.printStats) return;
let date = new Date();
let users = 0;
let servers = 0;
let serversPerUser = 0;
for(let uid in connections) {
let ca = connections[uid];
users += 1;
for(let snam in ca) {
if(!snam) continue;
if(snam == 'host') continue;
servers += 1;
}
}
if(users != 0) // Don't divide by zero lmao
serversPerUser = servers/users;
console.log(date+(': Currently connected users: {0}. ' +
'IRC server connections: {1}. ' +
'Average servers per user: {2}. ' +
'Total connections made: {3}. ' +
'Uptime: {4}s;').format(users, servers, serversPerUser, runtime_stats.connectionsMade, process.uptime()));
};