feat(log): using tagslog
This commit is contained in:
parent
f3e08b5aa4
commit
fa112ffd9c
26
package-lock.json
generated
26
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rats-search",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rats-search",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"ansi-256-colors": "^1.1.0",
|
||||
@ -44,6 +44,7 @@
|
||||
"react-minimal-pie-chart": "^8.2.0",
|
||||
"simple-encryptor": "github:DEgITx/node-simple-encryptor",
|
||||
"stun": "1.1.0",
|
||||
"tagslog": "^1.1.2",
|
||||
"webtorrent": "github:DEgITx/webtorrent"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -14063,6 +14064,11 @@
|
||||
"safer-buffer": "^2.0.2",
|
||||
"tweetnacl": "~0.14.0"
|
||||
},
|
||||
"bin": {
|
||||
"sshpk-conv": "bin/sshpk-conv",
|
||||
"sshpk-sign": "bin/sshpk-sign",
|
||||
"sshpk-verify": "bin/sshpk-verify"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
@ -18761,6 +18767,14 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tagslog": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/tagslog/-/tagslog-1.1.2.tgz",
|
||||
"integrity": "sha512-AstKis9gr4Ss0jpzJNhynPAXr85aevBsG0/FMRAwkedCYKATUhOjuSfP5Wm9Pwd58VocXWfBMYww/CEdKWnHgQ==",
|
||||
"dependencies": {
|
||||
"ansi-256-colors": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tapable": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.0.tgz",
|
||||
@ -35763,6 +35777,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tagslog": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/tagslog/-/tagslog-1.1.2.tgz",
|
||||
"integrity": "sha512-AstKis9gr4Ss0jpzJNhynPAXr85aevBsG0/FMRAwkedCYKATUhOjuSfP5Wm9Pwd58VocXWfBMYww/CEdKWnHgQ==",
|
||||
"requires": {
|
||||
"ansi-256-colors": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"tapable": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.0.tgz",
|
||||
|
@ -140,6 +140,7 @@
|
||||
"react-minimal-pie-chart": "^8.2.0",
|
||||
"simple-encryptor": "github:DEgITx/node-simple-encryptor",
|
||||
"stun": "1.1.0",
|
||||
"tagslog": "^1.1.2",
|
||||
"webtorrent": "github:DEgITx/webtorrent"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -75,39 +75,12 @@ const util = require('util');
|
||||
if (!fs.existsSync(app.getPath("userData"))){
|
||||
fs.mkdirSync(app.getPath("userData"));
|
||||
}
|
||||
const logFile = fs.createWriteStream(app.getPath("userData") + '/rats.log', {flags : 'w'});
|
||||
const logStdout = process.stdout;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
console.log = (...d) => {
|
||||
const date = (new Date).toLocaleTimeString()
|
||||
logFile.write(`[${date}] ` + util.format(...d) + '\n');
|
||||
logStdout.write(util.format(...d) + '\n');
|
||||
};
|
||||
|
||||
global.logT = (type, ...d) => {
|
||||
const date = (new Date).toLocaleTimeString()
|
||||
logFile.write(`[${date}] [${type}] ` + util.format(...d) + '\n');
|
||||
logStdout.write(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + util.format(...d) + '\n');
|
||||
}
|
||||
|
||||
global.logTE = (type, ...d) => {
|
||||
const date = (new Date).toLocaleTimeString()
|
||||
logFile.write(`\n[${date}] [ERROR] [${type}] ` + util.format(...d) + '\n\n');
|
||||
logStdout.write(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + colors.fg.codes[9] + util.format(...d) + colors.reset + '\n');
|
||||
}
|
||||
require('tagslog')({
|
||||
logFile: app.getPath("userData") + '/rats.log',
|
||||
stdout: (log) => process.stdout.write(log + '\n'),
|
||||
overrideConsole: true
|
||||
});
|
||||
|
||||
// print os info
|
||||
logT('system', 'Rats', app.getVersion())
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user