fix(log): color log (part 2)

This commit is contained in:
Alexey Kasyanchuk
2018-08-07 02:25:10 +03:00
parent 5bdab1b516
commit bf62a2de16
2 changed files with 38 additions and 38 deletions

View File

@ -137,22 +137,22 @@ module.exports = async ({
// remote request // remote request
if(options.peer) if(options.peer)
{ {
console.log('remote torrent request to peer') logT('search', 'remote torrent request to peer')
const peer = p2p.find(options.peer) const peer = p2p.find(options.peer)
if(!peer) if(!peer)
{ {
console.log('dont found requested peer in peers') logT('search', 'dont found requested peer in peers')
callback(undefined) callback(undefined)
return; return;
} }
delete options.peer; delete options.peer;
peer.emit('torrent', {hash, options}, (data, nil, address) => { peer.emit('torrent', {hash, options}, (data, nil, address) => {
console.log('remote torrent result', hash) logT('search', 'remote torrent result', hash)
callback(data) callback(data)
if(compareVersions(address.version, '0.19.0') < 0) if(compareVersions(address.version, '0.19.0') < 0)
{ {
console.log('replication selected torrent now works only with 0.19.0 version, ignore this torrent') logT('search', 'replication selected torrent now works only with 0.19.0 version, ignore this torrent')
return return
} }
@ -186,7 +186,7 @@ module.exports = async ({
}); });
if(torrent.good != good || torrent.bad != bad) if(torrent.good != good || torrent.bad != bad)
{ {
console.log('finded new rating on', torrent.name, 'update votes to it') logT('rating', 'finded new rating on', torrent.name, 'update votes to it')
torrent.good = good torrent.good = good
torrent.bad = bad torrent.bad = bad
updateTorrentToDB(torrent) updateTorrentToDB(torrent)
@ -204,7 +204,7 @@ module.exports = async ({
if(config.p2pReplicationServer) if(config.p2pReplicationServer)
{ {
console.log('p2p replication server enabled') logT('replication', 'p2p replication server enabled')
p2p.on('randomTorrents', (nil, callback) => { p2p.on('randomTorrents', (nil, callback) => {
if(typeof callback != 'function') if(typeof callback != 'function')
@ -257,14 +257,14 @@ module.exports = async ({
if(compareVersions(address.version, '0.19.0') < 0) if(compareVersions(address.version, '0.19.0') < 0)
{ {
console.log('replication now works only with 0.19.0 version, ignore this torrent') logT('replication', 'replication now works only with 0.19.0 version, ignore this torrent')
return return
} }
gotTorrents += torrents.length gotTorrents += torrents.length
torrents.forEach((torrent) => { torrents.forEach((torrent) => {
console.log('replicate remote torrent', torrent && torrent.name) logT('replication', 'replicate remote torrent', torrent && torrent.name)
insertTorrentToDB(torrent) insertTorrentToDB(torrent)
}) })
}) })
@ -272,7 +272,7 @@ module.exports = async ({
setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout) setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout)
} }
// start // start
console.log('replication client is enabled') logT('replication', 'replication client is enabled')
getReplicationTorrents() getReplicationTorrents()
} }
} }
@ -347,13 +347,13 @@ module.exports = async ({
const isSHA1 = isSH1Hash(text) const isSHA1 = isSH1Hash(text)
sphinx.query('SELECT * FROM `torrents` WHERE ' + (isSHA1 ? 'hash = ?' : 'MATCH(?)') + ' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) { sphinx.query('SELECT * FROM `torrents` WHERE ' + (isSHA1 ? 'hash = ?' : 'MATCH(?)') + ' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) {
if(!rows) { if(!rows) {
console.log(error) logT('search', error)
callback(undefined) callback(undefined)
return; return;
} }
if(rows.length === 0 && isSHA1 && !isP2P) // trying to get via dht if(rows.length === 0 && isSHA1 && !isP2P) // trying to get via dht
{ {
console.log('get torrent via infohash with dht') logT('search', 'get torrent via infohash with dht')
torrentClient.getMetadata(text, (torrent) => { torrentClient.getMetadata(text, (torrent) => {
searchList.push(baseRowData(torrent)); searchList.push(baseRowData(torrent));
callback(searchList); callback(searchList);
@ -372,7 +372,7 @@ module.exports = async ({
recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback) => { recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback) => {
searchTorrentCall(text, navigation, callback) searchTorrentCall(text, navigation, callback)
p2p.emit('searchTorrent', {text, navigation}, (remote, socketObject) => { p2p.emit('searchTorrent', {text, navigation}, (remote, socketObject) => {
console.log('remote search results', remote && remote.length) logT('search', 'remote search results', remote && remote.length)
if(remote && remote.length > 0) if(remote && remote.length > 0)
{ {
const { _socket: socket } = socketObject const { _socket: socket } = socketObject
@ -447,7 +447,7 @@ module.exports = async ({
//sphinx.query('SELECT * FROM `files` inner join torrents on(torrents.hash = files.hash) WHERE files.path like \'%' + text + '%\' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) { //sphinx.query('SELECT * FROM `files` inner join torrents on(torrents.hash = files.hash) WHERE files.path like \'%' + text + '%\' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) {
sphinx.query('SELECT * FROM `files` WHERE MATCH(?) ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, files, fields) { sphinx.query('SELECT * FROM `files` WHERE MATCH(?) ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, files, fields) {
if(!files) { if(!files) {
console.log(error) logT('search', error)
callback(undefined) callback(undefined)
return; return;
} }
@ -467,7 +467,7 @@ module.exports = async ({
const inSql = Object.keys(search).map(hash => sphinx.escape(hash)).join(','); const inSql = Object.keys(search).map(hash => sphinx.escape(hash)).join(',');
sphinx.query(`SELECT * FROM torrents WHERE hash IN(${inSql})`, (err, torrents) => { sphinx.query(`SELECT * FROM torrents WHERE hash IN(${inSql})`, (err, torrents) => {
if(!torrents) { if(!torrents) {
console.log(err) logT('search', err)
return; return;
} }
@ -495,7 +495,7 @@ module.exports = async ({
recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback) => { recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback) => {
searchFilesCall(text, navigation, callback) searchFilesCall(text, navigation, callback)
p2p.emit('searchFiles', {text, navigation}, (remote, socketObject) => { p2p.emit('searchFiles', {text, navigation}, (remote, socketObject) => {
console.log('remote search files results', remote && remote.length) logT('search', 'remote search files results', remote && remote.length)
if(remote && remote.length > 0) if(remote && remote.length > 0)
{ {
const { _socket: socket } = socketObject const { _socket: socket } = socketObject
@ -571,7 +571,7 @@ module.exports = async ({
{ {
topTorrentsCall(type, navigation, callback) topTorrentsCall(type, navigation, callback)
p2p.emit('topTorrents', {type, navigation}, (remote, socketObject) => { p2p.emit('topTorrents', {type, navigation}, (remote, socketObject) => {
console.log('remote top results', remote && remote.length) logT('top', 'remote top results', remote && remote.length)
if(remote && remote.length > 0) if(remote && remote.length > 0)
{ {
const { _socket: socket } = socketObject const { _socket: socket } = socketObject
@ -661,9 +661,9 @@ module.exports = async ({
torrentClient._add = (torrentObject, savePath, callback) => torrentClient._add = (torrentObject, savePath, callback) =>
{ {
const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}` const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}`
console.log('download', magnet) logT('downloader', 'download', magnet)
if(torrentClient.get(magnet)) { if(torrentClient.get(magnet)) {
console.log('aready added') logT('downloader', 'aready added')
if(callback) if(callback)
callback(false) callback(false)
return return
@ -684,7 +684,7 @@ module.exports = async ({
} }
torrent.on('ready', () => { torrent.on('ready', () => {
console.log('start downloading', torrent.infoHash, 'to', torrent.path) logT('downloader', 'start downloading', torrent.infoHash, 'to', torrent.path)
send('downloading', torrent.infoHash) send('downloading', torrent.infoHash)
progress(0) // immediately display progress progress(0) // immediately display progress
if(torrent._paused) if(torrent._paused)
@ -695,7 +695,7 @@ module.exports = async ({
}) })
torrent.on('done', () => { torrent.on('done', () => {
console.log('download done', torrent.infoHash) logT('downloader', 'download done', torrent.infoHash)
progress(0) // update progress progress(0) // update progress
// remove torrent if marked // remove torrent if marked
if(torrent.removeOnDone) if(torrent.removeOnDone)
@ -703,7 +703,7 @@ module.exports = async ({
torrentClient.remove(magnet, (err) => { torrentClient.remove(magnet, (err) => {
if(err) if(err)
{ {
console.log('download removing error', err) logT('downloader', 'download removing error', err)
return return
} }
@ -728,7 +728,7 @@ module.exports = async ({
//custom api pause //custom api pause
torrent._pause = () => { torrent._pause = () => {
console.log('pause torrent downloading', torrent.infoHash) logT('downloader', 'pause torrent downloading', torrent.infoHash)
torrent.pause() torrent.pause()
torrent.wires = []; torrent.wires = [];
setTimeout(() => { setTimeout(() => {
@ -746,7 +746,7 @@ module.exports = async ({
} }
torrent._resume = () => { torrent._resume = () => {
console.log('resume torrent downloading', torrent.infoHash) logT('downloader', 'resume torrent downloading', torrent.infoHash)
torrent._restoreWires() torrent._restoreWires()
torrent.resume() torrent.resume()
} }
@ -776,13 +776,13 @@ module.exports = async ({
const id = torrentClientHashMap[hash] const id = torrentClientHashMap[hash]
if(!id) if(!id)
{ {
console.log('cant find torrent for removing', hash) logT('downloader', 'cant find torrent for removing', hash)
return return
} }
const torrent = torrentClient.get(id) const torrent = torrentClient.get(id)
if(!torrent) { if(!torrent) {
console.log('no torrent for update founded') logT('downloader', 'no torrent for update founded')
return return
} }
@ -811,7 +811,7 @@ module.exports = async ({
const id = torrentClientHashMap[hash] const id = torrentClientHashMap[hash]
if(!id) if(!id)
{ {
console.log('cant find torrent for removing', hash) logT('downloader', 'cant find torrent for removing', hash)
if(callback) if(callback)
callback(false) callback(false)
return return
@ -820,7 +820,7 @@ module.exports = async ({
torrentClient.remove(id, (err) => { torrentClient.remove(id, (err) => {
if(err) if(err)
{ {
console.log('download removing error', err) logT('downloader', 'download removing error', err)
if(callback) if(callback)
callback(false) callback(false)
return return
@ -855,12 +855,12 @@ module.exports = async ({
return return
removeProtect = true removeProtect = true
console.log('checktorrents call') logT('clean', 'checktorrents call')
const toRemove = [] const toRemove = []
const done = async () => { const done = async () => {
console.log('torrents to remove founded', toRemove.length) logT('clean', 'torrents to remove founded', toRemove.length)
if(checkOnly) if(checkOnly)
{ {
callback(toRemove.length) callback(toRemove.length)
@ -874,7 +874,7 @@ module.exports = async ({
}) })
callback(toRemove.length) callback(toRemove.length)
removeProtect = false removeProtect = false
console.log('removed torrents by filter:', toRemove.length) logT('clean', 'removed torrents by filter:', toRemove.length)
} }
let i = 1 let i = 1
@ -969,7 +969,7 @@ module.exports = async ({
if(!myself) if(!myself)
{ {
console.log('replicate torrent from store record', torrent.hash) logT('store', 'replicate torrent from store record', torrent.hash)
await insertTorrentToDB(torrent) await insertTorrentToDB(torrent)
} }
@ -1018,7 +1018,7 @@ module.exports = async ({
if(remoteFeed.feed.length > feed.size() || (remoteFeed.feed.length == feed.size() && remoteFeed.feedDate > feed.feedDate)) if(remoteFeed.feed.length > feed.size() || (remoteFeed.feed.length == feed.size() && remoteFeed.feedDate > feed.feedDate))
{ {
console.log('replace our feed with remote feed') logT('feed', 'replace our feed with remote feed')
feed.feed = remoteFeed.feed feed.feed = remoteFeed.feed
feed.feedDate = remoteFeed.feedDate || 0 feed.feedDate = remoteFeed.feedDate || 0
// it can be new torrents replicate all // it can be new torrents replicate all

View File

@ -122,7 +122,7 @@ process.on('unhandledRejection', r => console.log('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.
console.log('openned second application, just focus this one') logT('app', 'openned second application, just focus this one')
if (mainWindow) { if (mainWindow) {
if (mainWindow.isMinimized()) if (mainWindow.isMinimized())
mainWindow.restore(); mainWindow.restore();
@ -131,7 +131,7 @@ const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory
}); });
if (shouldQuit) { if (shouldQuit) {
console.log('closed because of second application') logT('app', 'closed because of second application')
app.exit(0); app.exit(0);
} }
@ -141,12 +141,12 @@ log.transports.file.level = false;
log.transports.console.level = false; log.transports.console.level = false;
log.transports.console = function(msg) { log.transports.console = function(msg) {
const text = util.format.apply(util, msg.data); const text = util.format.apply(util, msg.data);
console.log(text); logT('updater', text);
}; };
autoUpdater.logger = log; autoUpdater.logger = log;
autoUpdater.on('update-downloaded', () => { autoUpdater.on('update-downloaded', () => {
console.log('update-downloaded lats quitAndInstall'); logT('updater', 'update-downloaded lats quitAndInstall');
if (env.name === "production") { if (env.name === "production") {
dialog.showMessageBox({ dialog.showMessageBox({
type: 'info', type: 'info',
@ -240,7 +240,7 @@ app.on("ready", () => {
checkInternet(enabled => { checkInternet(enabled => {
if(!enabled) if(!enabled)
{ {
console.log('no internet connection were founded, updater not started') logT('updater', 'no internet connection were founded, updater not started')
return return
} }
@ -249,7 +249,7 @@ app.on("ready", () => {
autoUpdater.getUpdateInfo().then(info => { autoUpdater.getUpdateInfo().then(info => {
if(info.version == app.getVersion()) if(info.version == app.getVersion())
{ {
console.log('update not founded for version', app.getVersion()) logT('updater', 'update not founded for version', app.getVersion())
return return
} }