Skip to content

Commit

Permalink
Auto merge of #1908 - kzys:fastboot-log, r=jtgeibel
Browse files Browse the repository at this point in the history
Emit Heroku-like logs from the Fastboot server

This change adds Heroku-like logs from the Fastboot server, as we discussed in #1811.
  • Loading branch information
bors committed Nov 26, 2019
2 parents 50b75b3 + 5ebd4bc commit aaacc50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
13 changes: 12 additions & 1 deletion fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const FastBootAppServer = require('fastboot-app-server');
// because fastboot-app-server uses cluster, but it might change in future
const cluster = require('cluster');

const morgan = require('morgan');

class LoggerWithoutTimestamp {
constructor() {
this.prefix = cluster.isMaster ? 'master' : 'worker';
Expand Down Expand Up @@ -44,16 +46,25 @@ function writeAppInitializedWhenReady(logger) {
}

var logger = new LoggerWithoutTimestamp();

logger.writeLine(`${os.cpus().length} cores available`);

let workerCount = process.env.WEB_CONCURRENCY || 1;
let logRequests = morgan(
'at=info method=:method path=":url" ' +
'request_id=:req[x-request-id] ' +
'fwd=":req[x-real-ip]" ' +
'user_agent=":req[user-agent]"',
);

let server = new FastBootAppServer({
distPath: 'dist',
port: 9000,
ui: logger,
workerCount: workerCount,

// afterMiddleware won't be called since Fastboot's middleware
// doesn't call next().
beforeMiddleware: app => app.use(logRequests),
});

if (!cluster.isWorker) {
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint:hbs": "ember-template-lint app/templates",
"lint:js": "eslint . --cache",
"lint:deps": "ember dependency-lint",
"prettier": "prettier --write '{app,tests,mirage}/**/*.js'",
"prettier": "prettier --write '**/*.js'",
"start": "./script/ember.sh serve",
"start:live": "./script/ember.sh serve --proxy https://crates.io",
"start:local": "./script/ember.sh serve --proxy http://127.0.0.1:8888",
Expand Down Expand Up @@ -100,6 +100,7 @@
"trailingComma": "all"
},
"dependencies": {
"fastboot-app-server": "^2.0.0"
"fastboot-app-server": "^2.0.0",
"morgan": "^1.9.1"
}
}

0 comments on commit aaacc50

Please sign in to comment.