feat(log): error display with separate color #31
This commit is contained in:
parent
297baac3d3
commit
ddfd43498d
@ -106,7 +106,7 @@ module.exports = async ({
|
|||||||
|
|
||||||
sphinx.query('SELECT count(*) AS torrents, sum(size) AS sz FROM `torrents`', function (error, rows, fields) {
|
sphinx.query('SELECT count(*) AS torrents, sum(size) AS sz FROM `torrents`', function (error, rows, fields) {
|
||||||
if(!rows) {
|
if(!rows) {
|
||||||
console.error(error)
|
logTE('statistic', error)
|
||||||
callback(undefined)
|
callback(undefined)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ module.exports = async ({
|
|||||||
|
|
||||||
sphinx.query('SELECT count(*) AS files FROM `files`', function (error, rows, fields) {
|
sphinx.query('SELECT count(*) AS files FROM `files`', function (error, rows, fields) {
|
||||||
if(!rows) {
|
if(!rows) {
|
||||||
console.error(error)
|
logTE('statistic', error)
|
||||||
callback(undefined)
|
callback(undefined)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,12 @@ global.logT = (type, ...d) => {
|
|||||||
logStdout.write(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + 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');
|
||||||
|
}
|
||||||
|
|
||||||
// print os info
|
// print os info
|
||||||
logT('system', 'Rats', app.getVersion())
|
logT('system', 'Rats', app.getVersion())
|
||||||
logT('system', 'Platform:', os.platform())
|
logT('system', 'Platform:', os.platform())
|
||||||
@ -118,7 +124,7 @@ if(portative)
|
|||||||
logT('system', 'portative compability')
|
logT('system', 'portative compability')
|
||||||
|
|
||||||
// handle promise rejections
|
// handle promise rejections
|
||||||
process.on('unhandledRejection', r => console.log('Rejection:', r));
|
process.on('unhandledRejection', r => logTE('system', 'Rejection:', r));
|
||||||
|
|
||||||
const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
|
@ -313,7 +313,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
sphinx.query('select * from version', async (err, version) => {
|
sphinx.query('select * from version', async (err, version) => {
|
||||||
if(err)
|
if(err)
|
||||||
{
|
{
|
||||||
logT('patcher', 'error on version get on db patch')
|
logTE('patcher', 'error on version get on db patch')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ module.exports = (sphinx, table, callback, doneCallback, max = 1000, where = '')
|
|||||||
sphinx.query(`SELECT * FROM ${table} WHERE id > ${index} ${where} LIMIT ${max}`, (err, torrents) => {
|
sphinx.query(`SELECT * FROM ${table} WHERE id > ${index} ${where} LIMIT ${max}`, (err, torrents) => {
|
||||||
const finish = () => {
|
const finish = () => {
|
||||||
if(err)
|
if(err)
|
||||||
logT('sql', 'big table parse error', err)
|
logTE('sql', 'big table parse error', err)
|
||||||
if(doneCallback)
|
if(doneCallback)
|
||||||
doneCallback(true)
|
doneCallback(true)
|
||||||
done(true)
|
done(true)
|
||||||
|
@ -223,12 +223,12 @@ const single = (callback) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mysqlSingle._mysql.on('error', (err) => {
|
mysqlSingle._mysql.on('error', (err) => {
|
||||||
logT('sql', 'db error', err);
|
|
||||||
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
|
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
|
||||||
logT('sql', 'restart single sql connection')
|
logT('sql', 'lost connection, restart single sql connection')
|
||||||
mysqlSingle._mysql = undefined
|
mysqlSingle._mysql = undefined
|
||||||
start(); // lost due to either server restart, or a
|
start(); // lost due to either server restart, or a
|
||||||
} else { // connnection idle timeout (the wait_timeout
|
} else { // connnection idle timeout (the wait_timeout
|
||||||
|
logTE('sql', 'db error', err);
|
||||||
throw err; // server variable configures this)
|
throw err; // server variable configures this)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -32,6 +32,10 @@ global.logT = (type, ...d) => {
|
|||||||
console.log(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + util.format(...d));
|
console.log(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + util.format(...d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.logTE = (type, ...d) => {
|
||||||
|
console.log(colors.fg.codes[Math.abs(stringHashCode(type)) % 256] + `[${type}]` + colors.reset + ' ' + colors.fg.codes[9] + util.format(...d) + colors.reset + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
server.listen(appConfig.httpPort);
|
server.listen(appConfig.httpPort);
|
||||||
logT('system', 'Rats v' + packageJson.version)
|
logT('system', 'Rats v' + packageJson.version)
|
||||||
@ -48,7 +52,7 @@ logT('system', 'NodeJS:', process.version)
|
|||||||
const majorVersion = /v?([0-9]+)\.?([0-9]+)?\.?([0-9]+)?\.?([0-9]+)?/.exec(process.version)[1]
|
const majorVersion = /v?([0-9]+)\.?([0-9]+)?\.?([0-9]+)?\.?([0-9]+)?/.exec(process.version)[1]
|
||||||
if(majorVersion < 8)
|
if(majorVersion < 8)
|
||||||
{
|
{
|
||||||
logT('system', 'Minumum Node.JS version >= 8.0.0, please update and try again')
|
logTE('system', 'Minumum Node.JS version >= 8.0.0, please update and try again')
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
resolve(data.length > 0 && JSON.parse(data))
|
resolve(data.length > 0 && JSON.parse(data))
|
||||||
});
|
});
|
||||||
}).on("error", (err) => {
|
}).on("error", (err) => {
|
||||||
logT('http', `${url} error: ` + err.message)
|
logTE('http', `${url} error: ` + err.message)
|
||||||
resolve(false)
|
resolve(false)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -225,7 +225,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
|
|
||||||
sphinxSingle.query('UPDATE torrents SET seeders = ?, completed = ?, leechers = ?, trackersChecked = ? WHERE hash = ?', [seeders, completed, leechers, Math.floor(checkTime.getTime() / 1000), hash], function(err, result) {
|
sphinxSingle.query('UPDATE torrents SET seeders = ?, completed = ?, leechers = ?, trackersChecked = ? WHERE hash = ?', [seeders, completed, leechers, Math.floor(checkTime.getTime() / 1000), hash], function(err, result) {
|
||||||
if(!result) {
|
if(!result) {
|
||||||
console.error(err);
|
logTE('udp-tracker', err);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
sphinxSingle.query("SELECT id FROM torrents WHERE hash = ?", torrent.hash, (err, single) => {
|
sphinxSingle.query("SELECT id FROM torrents WHERE hash = ?", torrent.hash, (err, single) => {
|
||||||
if(!single)
|
if(!single)
|
||||||
{
|
{
|
||||||
logT('add', err)
|
logTE('add', err)
|
||||||
resolve()
|
resolve()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -462,8 +462,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logT('add', torrent);
|
logTE('add', err);
|
||||||
console.error(err);
|
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
events.emit('insert', torrent)
|
events.emit('insert', torrent)
|
||||||
@ -475,6 +474,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
const {hash} = torrent
|
const {hash} = torrent
|
||||||
await sphinxSingle.query('DELETE FROM torrents WHERE hash = ?', hash)
|
await sphinxSingle.query('DELETE FROM torrents WHERE hash = ?', hash)
|
||||||
await sphinxSingle.query('DELETE FROM files WHERE hash = ?', hash)
|
await sphinxSingle.query('DELETE FROM files WHERE hash = ?', hash)
|
||||||
|
logT('remove', 'removed torrent', torrent.name || torrent.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateTorrentToDB = async (torrent) => {
|
const updateTorrentToDB = async (torrent) => {
|
||||||
@ -491,6 +491,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
delete torrent.filesList
|
delete torrent.filesList
|
||||||
|
|
||||||
await sphinxSingle.updateValues('torrents', torrent, {hash: torrent.hash})
|
await sphinxSingle.updateValues('torrents', torrent, {hash: torrent.hash})
|
||||||
|
logT('update', 'updated torrent', torrent.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertMetadata = (metadata, infohash, rinfo) => {
|
const insertMetadata = (metadata, infohash, rinfo) => {
|
||||||
@ -551,7 +552,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
{
|
{
|
||||||
disk.check(rootPath, function(err, info) {
|
disk.check(rootPath, function(err, info) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logT('quota', err);
|
logTE('quota', err);
|
||||||
} else {
|
} else {
|
||||||
const {available, free, total} = info;
|
const {available, free, total} = info;
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ module.exports = class P2PStore extends EventEmitter {
|
|||||||
(err) => {
|
(err) => {
|
||||||
if(err)
|
if(err)
|
||||||
{
|
{
|
||||||
logT('store', err)
|
logTE('store', err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {startApplication, stopApplication} from "../tests/application";
|
import {startApplication, stopApplication} from "../tests/application";
|
||||||
global.logT = (...args) => {console.log(...args)}
|
global.logT = (...args) => {console.log(...args)}
|
||||||
|
global.logTE = (...args) => {console.log('error', ...args)}
|
||||||
|
|
||||||
describe("application", () => {
|
describe("application", () => {
|
||||||
before(startApplication);
|
before(startApplication);
|
||||||
|
Loading…
Reference in New Issue
Block a user