@midwayjs/web 3.0.1 → 3.0.5
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/config/config.default.js +0 -1
- package/dist/base.js +2 -1
- package/dist/configuration.js +19 -0
- package/dist/framework/web.d.ts +1 -1
- package/dist/framework/web.js +16 -6
- package/dist/logger.d.ts +2 -5
- package/dist/logger.js +1 -22
- package/package.json +8 -6
package/config/config.default.js
CHANGED
package/dist/base.js
CHANGED
|
@@ -114,7 +114,8 @@ const createAppWorkerLoader = () => {
|
|
|
114
114
|
appDir: this.appDir,
|
|
115
115
|
baseDir: this.baseDir,
|
|
116
116
|
ignore: ['**/app/extend/**'],
|
|
117
|
-
|
|
117
|
+
application: this.app,
|
|
118
|
+
}).then(_ => {
|
|
118
119
|
debug('[egg]: global context: init complete');
|
|
119
120
|
});
|
|
120
121
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -72,6 +72,25 @@ EggConfiguration = __decorate([
|
|
|
72
72
|
},
|
|
73
73
|
egg: {
|
|
74
74
|
dumpConfig: true,
|
|
75
|
+
contextLoggerFormat: info => {
|
|
76
|
+
const ctx = info.ctx;
|
|
77
|
+
// format: '[$userId/$ip/$traceId/$use_ms $method $url]'
|
|
78
|
+
const userId = ctx.userId || '-';
|
|
79
|
+
const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
|
|
80
|
+
const use = Date.now() - ctx.startTime;
|
|
81
|
+
const label = userId +
|
|
82
|
+
'/' +
|
|
83
|
+
ctx.ip +
|
|
84
|
+
'/' +
|
|
85
|
+
traceId +
|
|
86
|
+
'/' +
|
|
87
|
+
use +
|
|
88
|
+
'ms ' +
|
|
89
|
+
ctx.method +
|
|
90
|
+
' ' +
|
|
91
|
+
ctx.url;
|
|
92
|
+
return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
|
|
93
|
+
},
|
|
75
94
|
},
|
|
76
95
|
},
|
|
77
96
|
test: {
|
package/dist/framework/web.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
|
|
|
26
26
|
getFrameworkType(): MidwayFrameworkType;
|
|
27
27
|
run(): Promise<void>;
|
|
28
28
|
getLogger(name?: string): any;
|
|
29
|
-
setContextLoggerClass(
|
|
29
|
+
setContextLoggerClass(): void;
|
|
30
30
|
generateMiddleware(middlewareId: any): Promise<any>;
|
|
31
31
|
beforeStop(): Promise<void>;
|
|
32
32
|
}
|
package/dist/framework/web.js
CHANGED
|
@@ -16,7 +16,6 @@ const router_1 = require("@eggjs/router");
|
|
|
16
16
|
const logger_1 = require("@midwayjs/logger");
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const util_1 = require("util");
|
|
19
|
-
const logger_2 = require("../logger");
|
|
20
19
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
21
20
|
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
22
21
|
constructor(app) {
|
|
@@ -69,6 +68,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
69
68
|
if (!this.isClusterMode) {
|
|
70
69
|
await this.initSingleProcessEgg();
|
|
71
70
|
}
|
|
71
|
+
else {
|
|
72
|
+
// get app in cluster mode
|
|
73
|
+
this.app = options['application'];
|
|
74
|
+
}
|
|
72
75
|
// not found middleware
|
|
73
76
|
const notFound = async (ctx, next) => {
|
|
74
77
|
await next();
|
|
@@ -136,8 +139,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
136
139
|
}, ['createAnonymousContext']);
|
|
137
140
|
// if use midway logger will be use midway custom context logger
|
|
138
141
|
debug(`[egg]: overwrite BaseContextLoggerClass to "${processType}"`);
|
|
139
|
-
this.setContextLoggerClass(
|
|
140
|
-
logger_2.MidwayEggContextLogger);
|
|
142
|
+
this.setContextLoggerClass();
|
|
141
143
|
}
|
|
142
144
|
async loadMidwayController() {
|
|
143
145
|
await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
|
|
@@ -211,9 +213,17 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
211
213
|
}
|
|
212
214
|
return this.appLogger;
|
|
213
215
|
}
|
|
214
|
-
setContextLoggerClass(
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
setContextLoggerClass() {
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
218
|
+
const self = this;
|
|
219
|
+
class MidwayEggContextLogger extends logger_1.MidwayContextLogger {
|
|
220
|
+
constructor(ctx, appLogger) {
|
|
221
|
+
super(ctx, appLogger, {
|
|
222
|
+
contextFormat: self.contextLoggerFormat,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
this.app.ContextLogger = MidwayEggContextLogger;
|
|
217
227
|
}
|
|
218
228
|
async generateMiddleware(middlewareId) {
|
|
219
229
|
const mwIns = await this.getApplicationContext().getAsync(middlewareId);
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ILogger
|
|
2
|
-
import { Application
|
|
1
|
+
import { ILogger } from '@midwayjs/logger';
|
|
2
|
+
import { Application } from 'egg';
|
|
3
3
|
declare class MidwayLoggers extends Map<string, ILogger> {
|
|
4
4
|
app: Application;
|
|
5
5
|
/**
|
|
@@ -29,8 +29,5 @@ declare class MidwayLoggers extends Map<string, ILogger> {
|
|
|
29
29
|
reload(): void;
|
|
30
30
|
}
|
|
31
31
|
export declare const createLoggers: (app: Application, processType: 'agent' | 'app') => MidwayLoggers;
|
|
32
|
-
export declare class MidwayEggContextLogger extends MidwayContextLogger<Context> {
|
|
33
|
-
formatContextLabel(): string;
|
|
34
|
-
}
|
|
35
32
|
export {};
|
|
36
33
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createLoggers = void 0;
|
|
4
4
|
const logger_1 = require("@midwayjs/logger");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fs_1 = require("fs");
|
|
@@ -171,25 +171,4 @@ const createLoggers = (app, processType) => {
|
|
|
171
171
|
return loggers;
|
|
172
172
|
};
|
|
173
173
|
exports.createLoggers = createLoggers;
|
|
174
|
-
class MidwayEggContextLogger extends logger_1.MidwayContextLogger {
|
|
175
|
-
formatContextLabel() {
|
|
176
|
-
const ctx = this.ctx;
|
|
177
|
-
// format: '[$userId/$ip/$traceId/$use_ms $method $url]'
|
|
178
|
-
const userId = ctx.userId || '-';
|
|
179
|
-
const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
|
|
180
|
-
const use = Date.now() - ctx.startTime;
|
|
181
|
-
return (userId +
|
|
182
|
-
'/' +
|
|
183
|
-
ctx.ip +
|
|
184
|
-
'/' +
|
|
185
|
-
traceId +
|
|
186
|
-
'/' +
|
|
187
|
-
use +
|
|
188
|
-
'ms ' +
|
|
189
|
-
ctx.method +
|
|
190
|
-
' ' +
|
|
191
|
-
ctx.url);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.MidwayEggContextLogger = MidwayEggContextLogger;
|
|
195
174
|
//# sourceMappingURL=logger.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -27,12 +27,14 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/decorator": "^3.0.
|
|
31
|
-
"@midwayjs/logger": "^2.
|
|
32
|
-
"@midwayjs/mock": "^3.0.
|
|
30
|
+
"@midwayjs/decorator": "^3.0.4",
|
|
31
|
+
"@midwayjs/logger": "^2.15.0",
|
|
32
|
+
"@midwayjs/mock": "^3.0.5",
|
|
33
|
+
"axios": "^0.25.0",
|
|
33
34
|
"dayjs": "1.10.7",
|
|
34
35
|
"egg-logger": "2.7.1",
|
|
35
36
|
"egg-mock": "4.2.0",
|
|
37
|
+
"egg-scripts": "2.15.2",
|
|
36
38
|
"egg-socket.io": "4.1.6",
|
|
37
39
|
"egg-view-nunjucks": "2.3.0",
|
|
38
40
|
"fake-egg": "1.0.0",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
48
|
"@eggjs/router": "^2.0.0",
|
|
47
|
-
"@midwayjs/core": "^3.0.
|
|
49
|
+
"@midwayjs/core": "^3.0.4",
|
|
48
50
|
"egg": "^2.28.0",
|
|
49
51
|
"find-up": "5.0.0",
|
|
50
52
|
"mkdirp": "^1.0.4"
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
"engines": {
|
|
58
60
|
"node": ">=12"
|
|
59
61
|
},
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "9b17898f10faeef2e7f1011eaea67f1d0b085261"
|
|
61
63
|
}
|