New --log option to print a full text log with different verbosity levels

exif-summary
Romain 7 years ago
parent 06ecd2edad
commit 47a924883e

@ -0,0 +1,16 @@
exports.init = (logLevel) => {
// enable particular debug() prefixes
if (logLevel === 'trace') process.env['DEBUG'] = '*'
if (logLevel === 'debug') process.env['DEBUG'] = 'thumbsup:error,thumbsup:warn,thumbsup:info,thumbsup:debug'
if (logLevel === 'info') process.env['DEBUG'] = 'thumbsup:error,thumbsup:warn,thumbsup:info'
// when running in text-mode, make sure all console.log() calls go through debug()
// don't touch them in normal-mode, since it would affect Listr's dnyamic rendering
if (typeof logLevel === 'string') {
console.log = require('debug')('thumbsup:info')
console.info = require('debug')('thumbsup:info')
console.warn = require('debug')('thumbsup:warn')
console.error = require('debug')('thumbsup:error')
}
}

@ -151,6 +151,12 @@ const OPTIONS = {
normalize: true
},
'log': {
description: 'Print a detailed text log',
choices: [null, 'info', 'debug', 'trace'],
'default': null
},
'usage-report': {
description: 'Disable anonymous usage statistics',
type: 'boolean',
@ -222,6 +228,7 @@ exports.get = () => {
index: opts['index'],
footer: opts['footer'],
albumsOutputFolder: opts['albums-output-folder'],
noUsageReport: opts['no-usage-report']
noUsageReport: opts['no-usage-report'],
log: opts['log']
}
}

@ -1,17 +1,25 @@
#!/usr/bin/env node
const Analytics = require('./analytics')
const fs = require('fs')
const index = require('../src/index')
const messages = require('./messages')
const path = require('path')
const Analytics = require('./analytics')
const options = require('./options')
const tty = require('tty')
console.log('')
// Read all options from the command-line / config file
const opts = options.get()
// If stdout is non TTY, make sure there is at least some text logging on stderr
if (!options.log && tty.isatty(process.stdout.fd) === false) {
options.log = 'info'
}
// Only require the index after logging options have been set
require('./log').init(options.log)
const index = require('../src/index')
// If this is the first run, display a welcome message
const indexPath = path.join(opts.output, 'thumbsup.db')
const firstRun = fs.existsSync(indexPath) === false

@ -1,5 +1,6 @@
const childProcess = require('child_process')
const debug = require('debug')('exiftool-stream')
const debug = require('debug')('thumbsup:debug')
const error = require('debug')('thumbsup:error')
const es = require('event-stream')
const JSONStream = require('JSONStream')
@ -26,8 +27,8 @@ exports.parse = (rootFolder, filePaths) => {
stdio: [ 'pipe', 'pipe', 'ignore' ]
})
child.on('error', (err) => {
debug(`Error: please verify that <exiftool> is installed on your system`)
debug(err.toString())
error(`Error: please verify that <exiftool> is installed on your system`)
error(err.toString())
})
child.on('close', (code, signal) => {
debug(`Exiftool exited with code ${code}`)

@ -1,5 +1,6 @@
const _ = require('lodash')
const Database = require('better-sqlite3')
const info = require('debug')('thumbsup:info')
const delta = require('./delta')
const EventEmitter = require('events')
const exiftool = require('../exiftool/parallel')
@ -58,13 +59,15 @@ class Index {
// calculate the difference: which files have been added, modified, etc
const deltaFiles = delta.calculate(databaseMap, diskMap)
emitter.emit('stats', {
const deltaStats = {
unchanged: deltaFiles.unchanged.length,
added: deltaFiles.added.length,
modified: deltaFiles.modified.length,
deleted: deltaFiles.deleted.length,
total: Object.keys(diskMap).length
})
}
emitter.emit('stats', deltaStats)
info('Differences between disk and index', deltaStats)
// remove deleted files from the DB
_.each(deltaFiles.deleted, path => {

@ -4,6 +4,9 @@ const steps = require('./steps/index')
const website = require('./website/website')
exports.build = function (opts, done) {
// How to render tasks
const renderer = (opts.log === 'color') ? 'update' : 'verbose'
// List of high level tasks
const tasks = new Listr([
{
title: 'Indexing folder',
@ -38,7 +41,10 @@ exports.build = function (opts, done) {
})
})
}
])
], {
renderer: renderer,
dateFormat: false
})
tasks.run().then(ctx => {
done(null, ctx.album)

@ -1,4 +1,4 @@
const debug = require('debug')('thumbsup')
const warn = require('debug')('thumbsup:warn')
const path = require('path')
const urljoin = require('url-join')
@ -12,7 +12,7 @@ exports.paths = function (filepath, mediaType, opts) {
items.download = download(filepath, opts['downloadVideos'], opts['downloadLinkPrefix'], items.video)
return items
} else {
debug(`Unsupported file type: ${mediaType}`)
warn(`Unsupported file type <${mediaType}> for ${filepath}`)
return {}
}
}

@ -22,9 +22,13 @@ exports.run = function (opts, callback) {
const files = []
// after a file is indexed
var lastPercent = -1
emitter.on('progress', stats => {
const percent = Math.floor(stats.processed * 100 / stats.total)
observer.next(`Indexing ${stats.processed}/${stats.total} (${percent}%)`)
if (percent > lastPercent) {
observer.next(`Indexing ${stats.processed}/${stats.total} (${percent}%)`)
lastPercent = percent
}
})
// emmitted for every file once indexing is finished

@ -1,4 +1,4 @@
const debug = require('debug')('thumbsup')
const debug = require('debug')('thumbsup:debug')
const downsize = require('thumbsup-downsize')
const os = require('os')
const fs = require('fs-extra')
@ -28,13 +28,13 @@ exports.create = function (files, opts) {
// accumulate all tasks into an object
// to remove duplicate destinations
files.forEach(f => {
debug(`Tasks for ${f.path}, ${JSON.stringify(f.output)}`)
Object.keys(f.output).forEach(out => {
var src = path.join(opts.input, f.path)
var dest = path.join(opts.output, f.output[out].path)
var destDate = modifiedDate(dest)
var action = actionMap[f.output[out].rel]
// ignore output files that don't have an action (e.g. existing links)
debug(`Comparing ${f.path} (${f.date}) and ${f.output[out].path} (${destDate})`)
if (action && f.date > destDate) {
tasks[dest] = {
file: f,

Loading…
Cancel
Save