From a3921bc3b22232d6dc0f85589e18e4300f9348b3 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Thu, 3 Nov 2016 17:35:38 -0700 Subject: [PATCH] update logger and use multi-dimensional array --- commands/download.js | 23 +++++++++++++---------- commands/share.js | 22 +++++++++++++--------- package.json | 2 +- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/commands/download.js b/commands/download.js index 14fd4edc..42e8b0e9 100644 --- a/commands/download.js +++ b/commands/download.js @@ -5,7 +5,10 @@ var speedometer = require('speedometer') var ui = require('../lib/ui') module.exports = function (dat, args) { - var log = logger(args) + var lines = [[], []] + var log = logger(lines, {debug: args.debug, quiet: args.quiet}) + var messages = lines[0] = [] + var progress = lines[1] = [] var downloadTxt = 'Downloading ' var finished = false @@ -13,13 +16,13 @@ module.exports = function (dat, args) { dat.stats.rateUp = speedometer() dat.stats.rateDown = speedometer() - log.status('Starting Dat...\n', 0) - log.status('Connecting...', 1) + progress.push('Starting Dat...\n') + progress.push('Connecting...') dat.on('error', onerror) dat.open(function () { - log.message('Downloading in ' + dat.dir + '\n') + messages.push('Downloading in ' + dat.dir + '\n') dat.download(function (err) { if (err) onerror(err) }) @@ -32,7 +35,7 @@ module.exports = function (dat, args) { }) dat.once('key', function (key) { - log.message(ui.keyMsg(key)) + messages.push(ui.keyMsg(key)) if (args.quiet) console.log(ui.keyMsg(key)) }) @@ -50,7 +53,7 @@ module.exports = function (dat, args) { finished = false dat.stats.rateDown = speedometer() updateStats() - log.status('', -1) // remove download finished message + progress[2] = '' // remove download finished message }) dat.on('file-downloaded', updateStats) @@ -59,16 +62,16 @@ module.exports = function (dat, args) { dat.stats.rateDown = 0 updateStats() if (args.exit) { - log.status('', 1) + progress[1] = '' // clear swarm info before exiting process.exit(0) } - log.status('\nDownload Finished. You may exit the process with Ctrl-C.', -1) + progress[2] = '\nDownload Finished. You may exit the process with Ctrl-C.' }) dat.on('swarm-update', printSwarm) function printSwarm () { - log.status(ui.swarmMsg(dat), 1) + progress[1] = ui.swarmMsg(dat) } function updateStats () { @@ -79,7 +82,7 @@ module.exports = function (dat, args) { } msg += ' ' + downloadTxt + chalk.bold(stats.filesTotal) + ' items' msg += chalk.dim(' (' + prettyBytes(stats.bytesTotal) + ')') - log.status(msg + '\n', 0) + progress[0] = msg + '\n' } } diff --git a/commands/share.js b/commands/share.js index d1f81fd8..5d8abb2a 100644 --- a/commands/share.js +++ b/commands/share.js @@ -6,22 +6,26 @@ var speedometer = require('speedometer') var ui = require('../lib/ui') module.exports = function (dat, args) { - var log = logger(args) + var lines = [[], []] + var log = logger(lines, {debug: args.debug, quiet: args.quiet}) + var messages = lines[0] = [] + var progress = lines[1] = [] + var addText = 'Adding ' var finalized = false dat.stats.rateUp = speedometer() - log.status('Starting Dat...\n', 0) - if (args.snapshot) log.status('Creating Link...', 1) - else log.status('Connecting...', 1) + progress.push('Starting Dat...\n') + if (args.snapshot) progress.push('Creating Link...') + else progress.push('Connecting...') dat.on('error', onerror) dat.open(function () { dat.archive.open(function () { if (dat.archive.key && !dat.archive.owner) return download(dat, args) - log.message('Sharing ' + dat.dir + '\n') + messages.push('Sharing ' + dat.dir + '\n') dat.share(function (err) { if (err) onerror(err) }) @@ -43,11 +47,11 @@ module.exports = function (dat, args) { var msg = 'Calculating Size: ' msg += stats.filesTotal + ' items ' msg += chalk.dim('(' + prettyBytes(stats.bytesTotal) + ')') - log.status(msg + '\n', 0) + progress[0] = msg + '\n' }) dat.once('key', function (key) { - log.message(ui.keyMsg(key)) + messages.push(ui.keyMsg(key)) if (args.quiet) console.log(ui.keyMsg(key)) }) @@ -72,7 +76,7 @@ module.exports = function (dat, args) { dat.on('swarm-update', printSwarm) function printSwarm () { - log.status(ui.swarmMsg(dat), 1) + progress[1] = ui.swarmMsg(dat) } function updateStats () { @@ -85,7 +89,7 @@ module.exports = function (dat, args) { if (finalized) msg += chalk.bold(files) + ' ' msg += 'items' msg += chalk.dim(' (' + prettyBytes(bytesTotal) + ')') - log.status(msg + '\n', 0) + progress[0] = msg + '\n' } } diff --git a/package.json b/package.json index 02726168..a166eafe 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "pretty-bytes": "^3.0.0", "pump": "^1.0.1", "speedometer": "^1.0.0", - "status-logger": "^2.0.1" + "status-logger": "^3.0.0" }, "bugs": { "url": "https://github.com/datproject/dat/issues"