Skip to content

Commit 82c84d0

Browse files
committed
Remove timestamps from fastboot-app-server
1 parent cee1354 commit 82c84d0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

fastboot.js

+26-5
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,49 @@ const FastBootAppServer = require('fastboot-app-server');
88
// because fastboot-app-server uses cluster, but it might change in future
99
const cluster = require('cluster');
1010

11-
function writeAppInitializedWhenReady() {
11+
class LoggerWithoutTimestamp {
12+
constructor() {
13+
this.prefix = cluster.isMaster ? 'master' : 'worker';
14+
}
15+
writeLine() {
16+
this._write('info', Array.prototype.slice.apply(arguments));
17+
}
18+
19+
writeError() {
20+
this._write('error', Array.prototype.slice.apply(arguments));
21+
}
22+
23+
_write(level, args) {
24+
args[0] = `[${level}][${this.prefix}] ${args[0]}`
25+
console.log.apply(console, args)
26+
}
27+
}
28+
29+
function writeAppInitializedWhenReady(logger) {
1230
let timeout;
1331

1432
timeout = setInterval(function() {
15-
console.log('waiting backend');
33+
logger.writeLine('waiting backend');
1634
if (fs.existsSync('/tmp/backend-initialized')) {
17-
console.log('backend is up. let heroku know the app is ready');
35+
logger.writeLine('backend is up. let heroku know the app is ready');
1836
fs.writeFileSync('/tmp/app-initialized', 'hello');
1937
clearInterval(timeout);
2038
} else {
21-
console.log('backend is still not up');
39+
logger.writeLine('backend is still not up');
2240
}
2341
}, 1000);
2442
}
2543

44+
var logger = new LoggerWithoutTimestamp();
45+
2646
let server = new FastBootAppServer({
2747
distPath: 'dist',
2848
port: 9000,
49+
ui: logger
2950
});
3051

3152
if (!cluster.isWorker) {
32-
writeAppInitializedWhenReady();
53+
writeAppInitializedWhenReady(logger);
3354
}
3455

3556
server.start();

0 commit comments

Comments
 (0)