feat(log): using tagslog
This commit is contained in:
@ -11,38 +11,10 @@ const io = require('socket.io')(server);
|
||||
const fs = require('fs');
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
require('tagslog')({logFile: 'rats.log'});
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||
|
||||
const util = require('util');
|
||||
const colors = require('ansi-256-colors');
|
||||
const stringHashCode = (str) => {
|
||||
let hash = 0, i, chr;
|
||||
if (str.length === 0)
|
||||
return hash;
|
||||
for (i = 0; i < str.length; i++) {
|
||||
chr = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + chr;
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
return hash;
|
||||
};
|
||||
|
||||
const logFile = fs.createWriteStream('rats.log', {flags : 'w'});
|
||||
|
||||
global.logT = (type, ...d) => {
|
||||
const date = (new Date).toLocaleTimeString()
|
||||
console.log(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + util.format(...d));
|
||||
logFile.write(`[${date}] ` + util.format(...d) + '\n');
|
||||
}
|
||||
|
||||
global.logTE = (type, ...d) => {
|
||||
const date = (new Date).toLocaleTimeString()
|
||||
console.log(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + colors.fg.codes[9] + util.format(...d) + colors.reset + '\n');
|
||||
logFile.write(`[${date}] ` + util.format(...d) + '\n');
|
||||
}
|
||||
|
||||
|
||||
server.listen(appConfig.httpPort);
|
||||
logT('system', 'Rats v' + packageJson.version)
|
||||
logT('system', 'Listening web server on', appConfig.httpPort, 'port')
|
||||
|
Reference in New Issue
Block a user