Remove timestamps from fastboot-app-server
@@ -8,28 +8,49 @@ const FastBootAppServer = require('fastboot-app-server');
// because fastboot-app-server uses cluster, but it might change in future
const cluster = require('cluster');
-function writeAppInitializedWhenReady() {
+class LoggerWithoutTimestamp {
+ constructor() {
+ this.prefix = cluster.isMaster ? 'master' : 'worker';
+ }
+ writeLine() {
+ this._write('info', Array.prototype.slice.apply(arguments));
+ }
+
+ writeError() {
+ this._write('error', Array.prototype.slice.apply(arguments));
+ }
+
+ _write(level, args) {
+ args[0] = `[${level}][${this.prefix}] ${args[0]}`
+ console.log.apply(console, args)
+ }
+}
+
+function writeAppInitializedWhenReady(logger) {
let timeout;
timeout = setInterval(function() {
- console.log('waiting backend');
+ logger.writeLine('waiting backend');
if (fs.existsSync('/tmp/backend-initialized')) {
- console.log('backend is up. let heroku know the app is ready');
+ logger.writeLine('backend is up. let heroku know the app is ready');
fs.writeFileSync('/tmp/app-initialized', 'hello');
clearInterval(timeout);
} else {
- console.log('backend is still not up');
+ logger.writeLine('backend is still not up');
}
}, 1000);
}
+var logger = new LoggerWithoutTimestamp();
+
let server = new FastBootAppServer({
distPath: 'dist',
port: 9000,
+ ui: logger
});
if (!cluster.isWorker) {
- writeAppInitializedWhenReady();
+ writeAppInitializedWhenReady(logger);
}
server.start();
