Skip to content

Commit 6c4e8bc

Browse files
authored
feat: log app start timeline on coreLogger (#5122)
eggjs/core#260
1 parent 94b7d99 commit 6c4e8bc

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/egg.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ class EggApplication extends EggCore {
417417
const rundir = this.config.rundir;
418418
const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`);
419419
fs.writeFileSync(dumpFile, CircularJSON.stringify(items, null, 2));
420+
this.coreLogger.info(this.timing.toString());
420421
// only disable, not clear bootstrap timing data.
421422
this.timing.disable();
422423
// show duration >= ${slowBootActionMinDuration}ms action to warnning log
423424
for (const item of items) {
424-
if (item.duration >= this.config.dump.timing.slowBootActionMinDuration) {
425+
// ignore #0 name: Process Start
426+
if (item.index > 0 && item.duration >= this.config.dump.timing.slowBootActionMinDuration) {
425427
this.coreLogger.warn('[egg:core][slow-boot-action] #%d %dms, name: %s',
426428
item.index, item.duration, item.name);
427429
}
@@ -437,10 +439,11 @@ class EggApplication extends EggCore {
437439

438440
_setupTimeoutTimer() {
439441
const startTimeoutTimer = setTimeout(() => {
442+
this.coreLogger.error(this.timing.toString());
440443
this.coreLogger.error(`${this.type} still doesn't ready after ${this.config.workerStartTimeout} ms.`);
441444
// log unfinished
442-
const json = this.timing.toJSON();
443-
for (const item of json) {
445+
const items = this.timing.toJSON();
446+
for (const item of items) {
444447
if (item.end) continue;
445448
this.coreLogger.error(`unfinished timing item: ${CircularJSON.stringify(item)}`);
446449
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"delegates": "^1.0.0",
2929
"egg-cluster": "^2.0.0",
3030
"egg-cookies": "^2.6.1",
31-
"egg-core": "^5.1.1",
31+
"egg-core": "^5.3.0",
3232
"egg-development": "^2.7.0",
3333
"egg-errors": "^2.3.1",
3434
"egg-i18n": "^2.1.1",

test/app/middleware/override_method.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const utils = require('../../utils');
42

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

3129
it('should delete', () => {
30+
app.mockCsrf();
3231
return app.httpRequest()
3332
.post('/test')
3433
.send({ _method: 'DELETE' })

0 commit comments

Comments
 (0)