Skip to content

Commit

Permalink
feat: log app start timeline on coreLogger (#5122)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 13, 2023
1 parent 94b7d99 commit 6c4e8bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,13 @@ class EggApplication extends EggCore {
const rundir = this.config.rundir;
const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`);
fs.writeFileSync(dumpFile, CircularJSON.stringify(items, null, 2));
this.coreLogger.info(this.timing.toString());
// only disable, not clear bootstrap timing data.
this.timing.disable();
// show duration >= ${slowBootActionMinDuration}ms action to warnning log
for (const item of items) {
if (item.duration >= this.config.dump.timing.slowBootActionMinDuration) {
// ignore #0 name: Process Start
if (item.index > 0 && item.duration >= this.config.dump.timing.slowBootActionMinDuration) {
this.coreLogger.warn('[egg:core][slow-boot-action] #%d %dms, name: %s',
item.index, item.duration, item.name);
}
Expand All @@ -437,10 +439,11 @@ class EggApplication extends EggCore {

_setupTimeoutTimer() {
const startTimeoutTimer = setTimeout(() => {
this.coreLogger.error(this.timing.toString());
this.coreLogger.error(`${this.type} still doesn't ready after ${this.config.workerStartTimeout} ms.`);
// log unfinished
const json = this.timing.toJSON();
for (const item of json) {
const items = this.timing.toJSON();
for (const item of items) {
if (item.end) continue;
this.coreLogger.error(`unfinished timing item: ${CircularJSON.stringify(item)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"delegates": "^1.0.0",
"egg-cluster": "^2.0.0",
"egg-cookies": "^2.6.1",
"egg-core": "^5.1.1",
"egg-core": "^5.3.0",
"egg-development": "^2.7.0",
"egg-errors": "^2.3.1",
"egg-i18n": "^2.1.1",
Expand Down
3 changes: 1 addition & 2 deletions test/app/middleware/override_method.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const utils = require('../../utils');

describe('test/app/middleware/override_method.test.js', () => {
Expand Down Expand Up @@ -29,6 +27,7 @@ describe('test/app/middleware/override_method.test.js', () => {
});

it('should delete', () => {
app.mockCsrf();
return app.httpRequest()
.post('/test')
.send({ _method: 'DELETE' })
Expand Down

0 comments on commit 6c4e8bc

Please sign in to comment.