From bf62a2de16a321d770fba59776d83d9ae6c1aa05 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Tue, 7 Aug 2018 02:25:10 +0300 Subject: [PATCH] fix(log): color log (part 2) --- src/background/api.js | 64 ++++++++++++++++++------------------ src/background/background.js | 12 +++---- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/background/api.js b/src/background/api.js index 81d68aa..2aa6cfb 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -137,22 +137,22 @@ module.exports = async ({ // remote request if(options.peer) { - console.log('remote torrent request to peer') + logT('search', 'remote torrent request to peer') const peer = p2p.find(options.peer) if(!peer) { - console.log('dont found requested peer in peers') + logT('search', 'dont found requested peer in peers') callback(undefined) return; } delete options.peer; peer.emit('torrent', {hash, options}, (data, nil, address) => { - console.log('remote torrent result', hash) + logT('search', 'remote torrent result', hash) callback(data) 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 } @@ -186,7 +186,7 @@ module.exports = async ({ }); 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.bad = bad updateTorrentToDB(torrent) @@ -204,7 +204,7 @@ module.exports = async ({ if(config.p2pReplicationServer) { - console.log('p2p replication server enabled') + logT('replication', 'p2p replication server enabled') p2p.on('randomTorrents', (nil, callback) => { if(typeof callback != 'function') @@ -257,14 +257,14 @@ module.exports = async ({ 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 } gotTorrents += torrents.length torrents.forEach((torrent) => { - console.log('replicate remote torrent', torrent && torrent.name) + logT('replication', 'replicate remote torrent', torrent && torrent.name) insertTorrentToDB(torrent) }) }) @@ -272,7 +272,7 @@ module.exports = async ({ setTimeout(() => getReplicationTorrents(gotTorrents > 8 ? gotTorrents * 600 : 10000), nextTimeout) } // start - console.log('replication client is enabled') + logT('replication', 'replication client is enabled') getReplicationTorrents() } } @@ -347,13 +347,13 @@ module.exports = async ({ const isSHA1 = isSH1Hash(text) sphinx.query('SELECT * FROM `torrents` WHERE ' + (isSHA1 ? 'hash = ?' : 'MATCH(?)') + ' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) { if(!rows) { - console.log(error) + logT('search', error) callback(undefined) return; } 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) => { searchList.push(baseRowData(torrent)); callback(searchList); @@ -372,7 +372,7 @@ module.exports = async ({ recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback) => { searchTorrentCall(text, navigation, callback) 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) { 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` WHERE MATCH(?) ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, files, fields) { if(!files) { - console.log(error) + logT('search', error) callback(undefined) return; } @@ -467,7 +467,7 @@ module.exports = async ({ const inSql = Object.keys(search).map(hash => sphinx.escape(hash)).join(','); sphinx.query(`SELECT * FROM torrents WHERE hash IN(${inSql})`, (err, torrents) => { if(!torrents) { - console.log(err) + logT('search', err) return; } @@ -495,7 +495,7 @@ module.exports = async ({ recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback) => { searchFilesCall(text, navigation, callback) 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) { const { _socket: socket } = socketObject @@ -571,7 +571,7 @@ module.exports = async ({ { topTorrentsCall(type, navigation, callback) 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) { const { _socket: socket } = socketObject @@ -661,9 +661,9 @@ module.exports = async ({ torrentClient._add = (torrentObject, savePath, callback) => { const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}` - console.log('download', magnet) + logT('downloader', 'download', magnet) if(torrentClient.get(magnet)) { - console.log('aready added') + logT('downloader', 'aready added') if(callback) callback(false) return @@ -684,7 +684,7 @@ module.exports = async ({ } 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) progress(0) // immediately display progress if(torrent._paused) @@ -695,7 +695,7 @@ module.exports = async ({ }) torrent.on('done', () => { - console.log('download done', torrent.infoHash) + logT('downloader', 'download done', torrent.infoHash) progress(0) // update progress // remove torrent if marked if(torrent.removeOnDone) @@ -703,7 +703,7 @@ module.exports = async ({ torrentClient.remove(magnet, (err) => { if(err) { - console.log('download removing error', err) + logT('downloader', 'download removing error', err) return } @@ -728,7 +728,7 @@ module.exports = async ({ //custom api pause torrent._pause = () => { - console.log('pause torrent downloading', torrent.infoHash) + logT('downloader', 'pause torrent downloading', torrent.infoHash) torrent.pause() torrent.wires = []; setTimeout(() => { @@ -746,7 +746,7 @@ module.exports = async ({ } torrent._resume = () => { - console.log('resume torrent downloading', torrent.infoHash) + logT('downloader', 'resume torrent downloading', torrent.infoHash) torrent._restoreWires() torrent.resume() } @@ -776,13 +776,13 @@ module.exports = async ({ const id = torrentClientHashMap[hash] if(!id) { - console.log('cant find torrent for removing', hash) + logT('downloader', 'cant find torrent for removing', hash) return } const torrent = torrentClient.get(id) if(!torrent) { - console.log('no torrent for update founded') + logT('downloader', 'no torrent for update founded') return } @@ -811,7 +811,7 @@ module.exports = async ({ const id = torrentClientHashMap[hash] if(!id) { - console.log('cant find torrent for removing', hash) + logT('downloader', 'cant find torrent for removing', hash) if(callback) callback(false) return @@ -820,7 +820,7 @@ module.exports = async ({ torrentClient.remove(id, (err) => { if(err) { - console.log('download removing error', err) + logT('downloader', 'download removing error', err) if(callback) callback(false) return @@ -855,12 +855,12 @@ module.exports = async ({ return removeProtect = true - console.log('checktorrents call') + logT('clean', 'checktorrents call') const toRemove = [] const done = async () => { - console.log('torrents to remove founded', toRemove.length) + logT('clean', 'torrents to remove founded', toRemove.length) if(checkOnly) { callback(toRemove.length) @@ -874,7 +874,7 @@ module.exports = async ({ }) callback(toRemove.length) removeProtect = false - console.log('removed torrents by filter:', toRemove.length) + logT('clean', 'removed torrents by filter:', toRemove.length) } let i = 1 @@ -969,7 +969,7 @@ module.exports = async ({ if(!myself) { - console.log('replicate torrent from store record', torrent.hash) + logT('store', 'replicate torrent from store record', torrent.hash) 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)) { - console.log('replace our feed with remote feed') + logT('feed', 'replace our feed with remote feed') feed.feed = remoteFeed.feed feed.feedDate = remoteFeed.feedDate || 0 // it can be new torrents replicate all diff --git a/src/background/background.js b/src/background/background.js index f4ed799..67e24de 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -122,7 +122,7 @@ process.on('unhandledRejection', r => console.log('Rejection:', r)); const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { // 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.isMinimized()) mainWindow.restore(); @@ -131,7 +131,7 @@ const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory }); if (shouldQuit) { - console.log('closed because of second application') + logT('app', 'closed because of second application') app.exit(0); } @@ -141,12 +141,12 @@ log.transports.file.level = false; log.transports.console.level = false; log.transports.console = function(msg) { const text = util.format.apply(util, msg.data); - console.log(text); + logT('updater', text); }; autoUpdater.logger = log; autoUpdater.on('update-downloaded', () => { - console.log('update-downloaded lats quitAndInstall'); + logT('updater', 'update-downloaded lats quitAndInstall'); if (env.name === "production") { dialog.showMessageBox({ type: 'info', @@ -240,7 +240,7 @@ app.on("ready", () => { checkInternet(enabled => { if(!enabled) { - console.log('no internet connection were founded, updater not started') + logT('updater', 'no internet connection were founded, updater not started') return } @@ -249,7 +249,7 @@ app.on("ready", () => { autoUpdater.getUpdateInfo().then(info => { if(info.version == app.getVersion()) { - console.log('update not founded for version', app.getVersion()) + logT('updater', 'update not founded for version', app.getVersion()) return }