Skip to content

Commit

Permalink
move chrome launcher logging to core logger
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Oct 13, 2016
1 parent 22c1fc5 commit 2275084
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 8 additions & 14 deletions lighthouse-cli/chrome-launcher.js
Expand Up @@ -25,6 +25,7 @@ const net = require('net');
const rimraf = require('rimraf');
const ask = require('./ask');
const chromeFinder = require('./chrome-finder');
const log = require('../lighthouse-core/lib/log');

const spawn = childProcess.spawn;
const execSync = childProcess.execSync;
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = class Launcher {
// you can't pass a fd to fs.writeFileSync
this.pidFile = `${this.TMP_PROFILE_DIR}/chrome.pid`;

console.log(`created ${this.TMP_PROFILE_DIR}`);
log.log('ChromeLauncher', `created ${this.TMP_PROFILE_DIR}`);

this.prepared = true;
}
Expand Down Expand Up @@ -116,7 +117,7 @@ module.exports = class Launcher {

fs.writeFileSync(this.pidFile, chrome.pid.toString());

console.log('Chrome running with pid =', chrome.pid);
log.log('ChromeLauncher', 'Chrome running with pid =', chrome.pid);
resolve(chrome.pid);
})
.then(pid => Promise.all([pid, this.waitUntilReady()]));
Expand Down Expand Up @@ -153,24 +154,17 @@ module.exports = class Launcher {
return new Promise((resolve, reject) => {
let retries = 0;
(function poll() {
const green = '\x1B[32m';
const reset = '\x1B[0m';

if (retries === 0) {
process.stdout.write('Waiting for browser.');
log.log('ChromeLauncher', 'Waiting for browser...');
}
retries++;
process.stdout.write('..');
log.verbose('ChromeLauncher', 'Waiting for browser...');

launcher
.isDebuggerReady()
.then(() => {
process.stdout.write(`${green}${reset}\n`);
resolve();
})
.then(resolve)
.catch(err => {
if (retries > 10) {
process.stdout.write('\n');
return reject(err);
}
delay(launcher.pollInterval).then(poll);
Expand All @@ -187,7 +181,7 @@ module.exports = class Launcher {
resolve();
});

console.log('Killing all Chrome Instances');
log.log('ChromeLauncher', 'Killing all Chrome Instances');
this.chrome.kill();

if (process.platform === 'win32') {
Expand All @@ -202,7 +196,7 @@ module.exports = class Launcher {

destroyTmp() {
if (this.TMP_PROFILE_DIR) {
console.log(`Removing ${this.TMP_PROFILE_DIR}`);
log.log('ChromeLauncher', `Removing ${this.TMP_PROFILE_DIR}`);
rimraf.sync(this.TMP_PROFILE_DIR);
}
}
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-cli/index.js
Expand Up @@ -30,6 +30,7 @@ const Printer = require('./printer');
const lighthouse = require('../lighthouse-core');
const assetSaver = require('../lighthouse-core/lib/asset-saver.js');
const ChromeLauncher = require('./chrome-launcher');
const log = require('../lighthouse-core/lib/log');

const perfOnlyConfig = require('../lighthouse-core/config/perf.json');

Expand Down Expand Up @@ -152,6 +153,7 @@ if (cli.verbose) {
} else if (cli.quiet) {
flags.logLevel = 'error';
}
log.setLevel(flags.logLevel);

const cleanup = {
fns: [],
Expand All @@ -173,7 +175,7 @@ function launchChromeAndRun(addresses) {
return launcher
.isDebuggerReady()
.catch(() => {
console.log('Launching Chrome...');
log.log('Lighthouse CLI', 'Launching Chrome...');
return launcher.run();
})
.then(() => lighthouseRun(addresses))
Expand Down

0 comments on commit 2275084

Please sign in to comment.