From e0e5d03949adc106a5988a45376b13ed9bf04707 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 1 May 2017 12:15:33 -0700 Subject: [PATCH] Do not truncate lines from build logs Is is disrupting to remove logs that are potentially useful for diagnosing when something is going wrong when starting up / building a deployment. Just log stdout in its entirety to the `now` build output with no lines being removed in the process. As discussed with @rauchg. --- lib/build-logger.js | 52 +++++++++------------------------------------ 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/lib/build-logger.js b/lib/build-logger.js index 76019125724..a081adaae1d 100644 --- a/lib/build-logger.js +++ b/lib/build-logger.js @@ -2,36 +2,11 @@ const EventEmitter = require('events'); // Packages -const ansi = require('ansi-escapes'); const io = require('socket.io-client'); const chalk = require('chalk'); const { compare, deserialize } = require('./logs'); -class Lines { - constructor(maxLines = 100) { - this.max = maxLines; - this.buf = []; - } - - write(str) { - const { max, buf } = this; - - if (buf.length === max) { - process.stdout.write(ansi.eraseLines(max + 1)); - buf.shift(); - buf.forEach(line => console.log(line)); - } - - buf.push(str); - console.log(str); - } - - reset() { - this.buf = []; - } -} - module.exports = class Logger extends EventEmitter { constructor(host, token, { debug = false, quiet = false } = {}) { super(); @@ -50,8 +25,6 @@ module.exports = class Logger extends EventEmitter { this.socket.on('logs', this.onLog.bind(this)); this.socket.on('backend', this.onComplete.bind(this)); - this.lines = new Lines(10); - // Log buffer this.buf = []; } @@ -100,18 +73,15 @@ module.exports = class Logger extends EventEmitter { log = deserialize(log); - const timer = setTimeout( - () => { - this.buf.sort((a, b) => compare(a.log, b.log)); - const idx = this.buf.findIndex(b => b.log.id === log.id) + 1; - for (const b of this.buf.slice(0, idx)) { - clearTimeout(b.timer); - this.printLog(b.log); - } - this.buf = this.buf.slice(idx); - }, - 300 - ); + const timer = setTimeout(() => { + this.buf.sort((a, b) => compare(a.log, b.log)); + const idx = this.buf.findIndex(b => b.log.id === log.id) + 1; + for (const b of this.buf.slice(0, idx)) { + clearTimeout(b.timer); + this.printLog(b.log); + } + this.buf = this.buf.slice(idx); + }, 300); this.buf.push({ log, timer }); } @@ -146,18 +116,16 @@ module.exports = class Logger extends EventEmitter { if (log.type === 'command') { console.log(`${chalk.gray('>')} ▲ ${data}`); - this.lines.reset(); } else if (log.type === 'stderr') { data.split('\n').forEach(v => { if (v.length > 0) { console.error(chalk.gray(`> ${v}`)); } }); - this.lines.reset(); } else if (log.type === 'stdout') { data.split('\n').forEach(v => { if (v.length > 0) { - this.lines.write(`${chalk.gray('>')} ${v}`); + console.log(`${chalk.gray('>')} ${v}`); } }); }