Skip to content

Commit

Permalink
Minimal verbose mode (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored and devongovett committed Aug 24, 2018
1 parent 8f42f3b commit d819a3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/core/parcel/src/Bundler.js
Expand Up @@ -600,6 +600,8 @@ class Bundler extends EventEmitter {
}
});

logger.verbose(`Built ${asset.relativeName}...`);

if (this.cache && cacheMiss) {
this.cache.write(asset.name, processed);
}
Expand Down
33 changes: 32 additions & 1 deletion packages/core/parcel/src/Logger.js
Expand Up @@ -6,6 +6,8 @@ const {countBreaks} = require('grapheme-breaker');
const stripAnsi = require('strip-ansi');
const ora = require('ora');
const WorkerFarm = require('./workerfarm/WorkerFarm');
const path = require('path');
const fs = require('fs');

class Logger {
constructor(options) {
Expand Down Expand Up @@ -50,6 +52,10 @@ class Logger {
}

write(message, persistent = false) {
if (this.logLevel > 3) {
return this.verbose(message);
}

if (!persistent) {
this.lines += this.countLines(message);
}
Expand All @@ -58,6 +64,27 @@ class Logger {
this._log(message);
}

verbose(message) {
if (this.logLevel < 4) {
return;
}

let currDate = new Date();
message = `[${currDate.toLocaleTimeString()}]: ${message}`;
if (this.logLevel > 4) {
if (!this.logFile) {
this.logFile = fs.createWriteStream(
path.join(
process.cwd(),
`parcel-debug-${currDate.toLocaleDateString()}@${currDate.toLocaleTimeString()}.log`
)
);
}
this.logFile.write(stripAnsi(message) + '\n');
}
this._log(message);
}

log(message) {
if (this.logLevel < 3) {
return;
Expand Down Expand Up @@ -103,7 +130,7 @@ class Logger {
}

clear() {
if (!this.color || this.isTest) {
if (!this.color || this.isTest || this.logLevel > 3) {
return;
}

Expand All @@ -122,6 +149,10 @@ class Logger {
return;
}

if (this.logLevel > 3) {
return this.verbose(message);
}

let styledMessage = this.chalk.gray.bold(message);
if (!this.spinner) {
this.spinner = ora({
Expand Down
12 changes: 6 additions & 6 deletions packages/core/parcel/src/cli.js
Expand Up @@ -58,8 +58,8 @@ program
.option('-V, --version', 'output the version number')
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
/^([0-3])$/
'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).',
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down Expand Up @@ -107,8 +107,8 @@ program
)
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
/^([0-3])$/
'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).',
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down Expand Up @@ -151,8 +151,8 @@ program
)
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
/^([0-3])$/
'set the log level, either "0" (no output), "1" (errors), "2" (warnings), "3" (info), "4" (verbose) or "5" (debug, creates a log file).',
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down

0 comments on commit d819a3e

Please sign in to comment.