Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal verbose mode #1834

Merged
merged 5 commits into from Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Bundler.js
Expand Up @@ -584,6 +584,8 @@ class Bundler extends EventEmitter {
}
});

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

if (this.cache && cacheMiss) {
this.cache.write(asset.name, processed);
}
Expand Down
34 changes: 33 additions & 1 deletion 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,28 @@ 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 = this.logFile.write.bind(this.logFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this bind needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so, I'll remove it, seems to work fine without

}
this.logFile.write(stripAnsi(message) + '\n');
}
this._log(message);
}

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

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

Expand All @@ -122,6 +150,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
6 changes: 3 additions & 3 deletions src/cli.js
Expand Up @@ -59,7 +59,7 @@ program
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this message to add the new verbose modes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, updated it to include the verbose and debug mode

/^([0-3])$/
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down Expand Up @@ -108,7 +108,7 @@ program
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
/^([0-3])$/
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down Expand Up @@ -152,7 +152,7 @@ program
.option(
'--log-level <level>',
'set the log level, either "0" (no output), "1" (errors), "2" (warnings + errors) or "3" (all).',
/^([0-3])$/
/^([0-5])$/
)
.option('--cache-dir <path>', 'set the cache directory. defaults to ".cache"')
.action(bundle);
Expand Down