Skip to content

Commit

Permalink
Do not truncate lines from build logs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TooTallNate authored and leo committed May 2, 2017
1 parent 9889a3b commit e0e5d03
Showing 1 changed file with 10 additions and 42 deletions.
52 changes: 10 additions & 42 deletions lib/build-logger.js
Expand Up @@ -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();
Expand All @@ -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 = [];
}
Expand Down Expand Up @@ -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 });
}
Expand Down Expand Up @@ -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}`);
}
});
}
Expand Down

0 comments on commit e0e5d03

Please sign in to comment.