egg 2.32.0 → 2.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +6 -0
- package/app/extend/context.js +6 -3
- package/config/config.default.js +3 -0
- package/index.d.ts +10 -2
- package/lib/egg.js +9 -0
- package/package.json +2 -2
package/History.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
|
|
2
|
+
2.33.0 / 2021-12-06
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
**features**
|
|
6
|
+
* [[`0f6589e1d`](http://github.com/eggjs/egg/commit/0f6589e1dc9e538434eb1580327556d5aa264822)] - feat: support better logger timer in precise milliseconds (#4806) (fengmk2 <<fengmk2@gmail.com>>)
|
|
1
7
|
# History
|
|
2
8
|
|
|
3
9
|
## 2021-11-15, Version 2.32.0 @atian25
|
package/app/extend/context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { performance } = require('perf_hooks');
|
|
3
4
|
const delegate = require('delegates');
|
|
4
5
|
const { assign } = require('utility');
|
|
5
6
|
const eggUtils = require('egg-core').utils;
|
|
@@ -219,7 +220,7 @@ const proto = module.exports = {
|
|
|
219
220
|
// e.g.: https://github.com/eggjs/egg-mock/pull/78
|
|
220
221
|
_runInBackground(scope) {
|
|
221
222
|
const ctx = this;
|
|
222
|
-
const start =
|
|
223
|
+
const start = performance.now();
|
|
223
224
|
/* istanbul ignore next */
|
|
224
225
|
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
|
|
225
226
|
// use setImmediate to ensure all sync logic will run async
|
|
@@ -227,11 +228,13 @@ const proto = module.exports = {
|
|
|
227
228
|
// use app.toAsyncFunction to support both generator function and async function
|
|
228
229
|
.then(() => ctx.app.toAsyncFunction(scope)(ctx))
|
|
229
230
|
.then(() => {
|
|
230
|
-
ctx.coreLogger.info('[egg:background] task:%s success (%dms)',
|
|
231
|
+
ctx.coreLogger.info('[egg:background] task:%s success (%dms)',
|
|
232
|
+
taskName, Math.floor((performance.now() - start) * 1000) / 1000);
|
|
231
233
|
})
|
|
232
234
|
.catch(err => {
|
|
233
235
|
// background task process log
|
|
234
|
-
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)',
|
|
236
|
+
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)',
|
|
237
|
+
taskName, Math.floor((performance.now() - start) * 1000) / 1000);
|
|
235
238
|
|
|
236
239
|
// emit error when promise catch, and set err.runInBackground flag
|
|
237
240
|
err.runInBackground = true;
|
package/config/config.default.js
CHANGED
|
@@ -249,6 +249,8 @@ module.exports = appInfo => {
|
|
|
249
249
|
* @property {String} coreLogName - file name of coreLogger
|
|
250
250
|
* @property {String} agentLogName - file name of agent worker log
|
|
251
251
|
* @property {Object} coreLogger - custom config of coreLogger
|
|
252
|
+
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
|
|
253
|
+
* @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
|
|
252
254
|
*/
|
|
253
255
|
config.logger = {
|
|
254
256
|
dir: path.join(appInfo.root, 'logs', appInfo.name),
|
|
@@ -265,6 +267,7 @@ module.exports = appInfo => {
|
|
|
265
267
|
errorLogName: 'common-error.log',
|
|
266
268
|
coreLogger: {},
|
|
267
269
|
allowDebugAtProd: false,
|
|
270
|
+
enablePerformanceTimer: false,
|
|
268
271
|
};
|
|
269
272
|
|
|
270
273
|
/**
|
package/index.d.ts
CHANGED
|
@@ -217,10 +217,12 @@ declare module 'egg' {
|
|
|
217
217
|
export interface EggLoggerConfig extends RemoveSpecProp<EggLoggersOptions, 'type'> {
|
|
218
218
|
/** custom config of coreLogger */
|
|
219
219
|
coreLogger?: Partial<EggLoggerOptions>;
|
|
220
|
-
/** allow debug log at prod, defaults to
|
|
220
|
+
/** allow debug log at prod, defaults to `false` */
|
|
221
221
|
allowDebugAtProd?: boolean;
|
|
222
222
|
/** disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`. */
|
|
223
223
|
disableConsoleAfterReady?: boolean;
|
|
224
|
+
/** using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to `false`. e.g.: logger will set 1.456ms instead of 1ms. */
|
|
225
|
+
enablePerformanceTimer?: boolean;
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
/** Custom Loader Configuration */
|
|
@@ -329,7 +331,8 @@ declare module 'egg' {
|
|
|
329
331
|
* @property {String} coreLogName - file name of coreLogger
|
|
330
332
|
* @property {String} agentLogName - file name of agent worker log
|
|
331
333
|
* @property {Object} coreLogger - custom config of coreLogger
|
|
332
|
-
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to
|
|
334
|
+
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
|
|
335
|
+
* @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
|
|
333
336
|
*/
|
|
334
337
|
logger: EggLoggerConfig;
|
|
335
338
|
|
|
@@ -924,6 +927,11 @@ declare module 'egg' {
|
|
|
924
927
|
*/
|
|
925
928
|
starttime: number;
|
|
926
929
|
|
|
930
|
+
/**
|
|
931
|
+
* Request start timer using `performance.now()`
|
|
932
|
+
*/
|
|
933
|
+
performanceStarttime?: number;
|
|
934
|
+
|
|
927
935
|
/**
|
|
928
936
|
* http request helper base on httpclient, it will auto save httpclient log.
|
|
929
937
|
* Keep the same api with httpclient.request(url, args).
|
package/lib/egg.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { performance } = require('perf_hooks');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
const fs = require('fs');
|
|
5
6
|
const ms = require('ms');
|
|
@@ -547,6 +548,14 @@ class EggApplication extends EggCore {
|
|
|
547
548
|
* @member {Number} Context#starttime
|
|
548
549
|
*/
|
|
549
550
|
context.starttime = Date.now();
|
|
551
|
+
|
|
552
|
+
if (this.config.logger.enablePerformanceTimer) {
|
|
553
|
+
/**
|
|
554
|
+
* Request start timer using `performance.now()`
|
|
555
|
+
* @member {Number} Context#performanceStarttime
|
|
556
|
+
*/
|
|
557
|
+
context.performanceStarttime = performance.now();
|
|
558
|
+
}
|
|
550
559
|
return context;
|
|
551
560
|
}
|
|
552
561
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "A web framework's framework for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"url": "https://github.com/eggjs/egg.git"
|
|
117
117
|
},
|
|
118
118
|
"engines": {
|
|
119
|
-
"node": ">= 8.
|
|
119
|
+
"node": ">= 8.5.0"
|
|
120
120
|
},
|
|
121
121
|
"license": "MIT"
|
|
122
122
|
}
|