ee-core 2.9.2 → 2.10.1
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/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +86 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +58 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
package/loader/index.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
const is = require('is-type-of');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const UtilsCore = require('../core/lib/utils');
|
|
5
|
-
const Ps = require('../ps');
|
|
6
|
-
const Log = require('../log');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 加载单个文件(如果是函数,将被执行)
|
|
12
|
-
*
|
|
13
|
-
* @param {String} filepath - fullpath
|
|
14
|
-
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
15
|
-
* @return {Object} exports
|
|
16
|
-
* @since 1.0.0
|
|
17
|
-
*/
|
|
18
|
-
loadOneFile (filepath, ...inject) {
|
|
19
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
20
|
-
if (!isAbsolute) {
|
|
21
|
-
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
filepath = filepath && this.resolveModule(filepath);
|
|
25
|
-
if (!fs.existsSync(filepath)) {
|
|
26
|
-
let errorMsg = `[ee-core] [loader/index] loadOneFile ${filepath} does not exist`;
|
|
27
|
-
Log.coreLogger.error(errorMsg);
|
|
28
|
-
throw new Error(errorMsg);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const ret = UtilsCore.loadFile(filepath);
|
|
32
|
-
if (is.function(ret) && !is.class(ret) && !UtilsCore.isBytecodeClass(ret)) {
|
|
33
|
-
ret = ret(...inject);
|
|
34
|
-
}
|
|
35
|
-
return ret;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 加载js文件
|
|
40
|
-
*
|
|
41
|
-
* @param {String} filepath - fullpath
|
|
42
|
-
* @return {Any} exports
|
|
43
|
-
* @since 1.0.0
|
|
44
|
-
*/
|
|
45
|
-
loadJsFile (filepath) {
|
|
46
|
-
if (!fs.existsSync(filepath)) {
|
|
47
|
-
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
48
|
-
Log.coreLogger.error(errMsg);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const ret = UtilsCore.loadFile(filepath);
|
|
53
|
-
return ret;
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 加载并运行js文件
|
|
58
|
-
*
|
|
59
|
-
* @param {String} filepath - fullpath
|
|
60
|
-
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
61
|
-
* @return {Any}
|
|
62
|
-
* @since 1.0.0
|
|
63
|
-
*/
|
|
64
|
-
execJsFile (filepath, ...inject) {
|
|
65
|
-
if (!fs.existsSync(filepath)) {
|
|
66
|
-
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
67
|
-
Log.coreLogger.error(errMsg);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let ret = UtilsCore.loadFile(filepath);
|
|
72
|
-
if (is.class(ret) || UtilsCore.isBytecodeClass(ret)) {
|
|
73
|
-
ret = new ret(inject);
|
|
74
|
-
} else if (is.function(ret)) {
|
|
75
|
-
ret = ret(inject);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return ret;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 模块的绝对路径
|
|
83
|
-
* @param {String} filepath - fullpath
|
|
84
|
-
*/
|
|
85
|
-
resolveModule(filepath) {
|
|
86
|
-
let fullpath;
|
|
87
|
-
try {
|
|
88
|
-
fullpath = require.resolve(filepath);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
|
|
91
|
-
// 特殊后缀处理
|
|
92
|
-
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
93
|
-
fullpath = filepath + '.jsc';
|
|
94
|
-
} else if (filepath && filepath.endsWith('.js')) {
|
|
95
|
-
fullpath = filepath + 'c';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
99
|
-
let files = { filepath, fullpath }
|
|
100
|
-
Log.coreLogger.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return fullpath;
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 加载模块(子进程中使用)
|
|
110
|
-
*
|
|
111
|
-
* @param {String} filepath - fullpath
|
|
112
|
-
* @return {Object} exports
|
|
113
|
-
* @since 1.0.0
|
|
114
|
-
*/
|
|
115
|
-
requireModule (filepath, type = '') {
|
|
116
|
-
let fullpath;
|
|
117
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
118
|
-
if (!isAbsolute) {
|
|
119
|
-
filepath = path.join(Ps.getBaseDir(), type, filepath);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
fullpath = this.resolveModule(filepath);
|
|
123
|
-
if (!fs.existsSync(fullpath)) {
|
|
124
|
-
let errorMsg = `[ee-core] [loader] requireModule filepath: ${filepath} does not exist`;
|
|
125
|
-
Log.coreLogger.error(errorMsg);
|
|
126
|
-
}
|
|
127
|
-
const ret = UtilsCore.loadFile(fullpath);
|
|
128
|
-
|
|
129
|
-
return ret;
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 加载jobs模块(子进程中使用)
|
|
134
|
-
*
|
|
135
|
-
* @param {String} filepath - fullpath
|
|
136
|
-
* @return {Object} exports
|
|
137
|
-
* @since 1.0.0
|
|
138
|
-
*/
|
|
139
|
-
requireJobsModule (filepath) {
|
|
140
|
-
const ret = this.requireModule(filepath, 'jobs');
|
|
141
|
-
|
|
142
|
-
return ret;
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 获取electron目录下文件的绝对路径
|
|
147
|
-
* @param {String} filepath - fullpath
|
|
148
|
-
*/
|
|
149
|
-
getFullpath(filepath) {
|
|
150
|
-
let fullpath;
|
|
151
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
152
|
-
if (!isAbsolute) {
|
|
153
|
-
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
fullpath = this.resolveModule(filepath);
|
|
157
|
-
if (!fs.existsSync(fullpath)) {
|
|
158
|
-
throw new Error(`[ee-core] [loader] getFullpath filepath ${fullpath} not exists`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return fullpath;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
1
|
+
const is = require('is-type-of');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const UtilsCore = require('../core/lib/utils');
|
|
5
|
+
const Ps = require('../ps');
|
|
6
|
+
const Log = require('../log');
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 加载单个文件(如果是函数,将被执行)
|
|
12
|
+
*
|
|
13
|
+
* @param {String} filepath - fullpath
|
|
14
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
15
|
+
* @return {Object} exports
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
loadOneFile (filepath, ...inject) {
|
|
19
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
20
|
+
if (!isAbsolute) {
|
|
21
|
+
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
filepath = filepath && this.resolveModule(filepath);
|
|
25
|
+
if (!fs.existsSync(filepath)) {
|
|
26
|
+
let errorMsg = `[ee-core] [loader/index] loadOneFile ${filepath} does not exist`;
|
|
27
|
+
Log.coreLogger.error(errorMsg);
|
|
28
|
+
throw new Error(errorMsg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ret = UtilsCore.loadFile(filepath);
|
|
32
|
+
if (is.function(ret) && !is.class(ret) && !UtilsCore.isBytecodeClass(ret)) {
|
|
33
|
+
ret = ret(...inject);
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 加载js文件
|
|
40
|
+
*
|
|
41
|
+
* @param {String} filepath - fullpath
|
|
42
|
+
* @return {Any} exports
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
*/
|
|
45
|
+
loadJsFile (filepath) {
|
|
46
|
+
if (!fs.existsSync(filepath)) {
|
|
47
|
+
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
48
|
+
Log.coreLogger.error(errMsg);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ret = UtilsCore.loadFile(filepath);
|
|
53
|
+
return ret;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 加载并运行js文件
|
|
58
|
+
*
|
|
59
|
+
* @param {String} filepath - fullpath
|
|
60
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
61
|
+
* @return {Any}
|
|
62
|
+
* @since 1.0.0
|
|
63
|
+
*/
|
|
64
|
+
execJsFile (filepath, ...inject) {
|
|
65
|
+
if (!fs.existsSync(filepath)) {
|
|
66
|
+
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
67
|
+
Log.coreLogger.error(errMsg);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let ret = UtilsCore.loadFile(filepath);
|
|
72
|
+
if (is.class(ret) || UtilsCore.isBytecodeClass(ret)) {
|
|
73
|
+
ret = new ret(inject);
|
|
74
|
+
} else if (is.function(ret)) {
|
|
75
|
+
ret = ret(inject);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return ret;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 模块的绝对路径
|
|
83
|
+
* @param {String} filepath - fullpath
|
|
84
|
+
*/
|
|
85
|
+
resolveModule(filepath) {
|
|
86
|
+
let fullpath;
|
|
87
|
+
try {
|
|
88
|
+
fullpath = require.resolve(filepath);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
|
|
91
|
+
// 特殊后缀处理
|
|
92
|
+
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
93
|
+
fullpath = filepath + '.jsc';
|
|
94
|
+
} else if (filepath && filepath.endsWith('.js')) {
|
|
95
|
+
fullpath = filepath + 'c';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
99
|
+
let files = { filepath, fullpath }
|
|
100
|
+
Log.coreLogger.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return fullpath;
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 加载模块(子进程中使用)
|
|
110
|
+
*
|
|
111
|
+
* @param {String} filepath - fullpath
|
|
112
|
+
* @return {Object} exports
|
|
113
|
+
* @since 1.0.0
|
|
114
|
+
*/
|
|
115
|
+
requireModule (filepath, type = '') {
|
|
116
|
+
let fullpath;
|
|
117
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
118
|
+
if (!isAbsolute) {
|
|
119
|
+
filepath = path.join(Ps.getBaseDir(), type, filepath);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fullpath = this.resolveModule(filepath);
|
|
123
|
+
if (!fs.existsSync(fullpath)) {
|
|
124
|
+
let errorMsg = `[ee-core] [loader] requireModule filepath: ${filepath} does not exist`;
|
|
125
|
+
Log.coreLogger.error(errorMsg);
|
|
126
|
+
}
|
|
127
|
+
const ret = UtilsCore.loadFile(fullpath);
|
|
128
|
+
|
|
129
|
+
return ret;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 加载jobs模块(子进程中使用)
|
|
134
|
+
*
|
|
135
|
+
* @param {String} filepath - fullpath
|
|
136
|
+
* @return {Object} exports
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
139
|
+
requireJobsModule (filepath) {
|
|
140
|
+
const ret = this.requireModule(filepath, 'jobs');
|
|
141
|
+
|
|
142
|
+
return ret;
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 获取electron目录下文件的绝对路径
|
|
147
|
+
* @param {String} filepath - fullpath
|
|
148
|
+
*/
|
|
149
|
+
getFullpath(filepath) {
|
|
150
|
+
let fullpath;
|
|
151
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
152
|
+
if (!isAbsolute) {
|
|
153
|
+
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fullpath = this.resolveModule(filepath);
|
|
157
|
+
if (!fs.existsSync(fullpath)) {
|
|
158
|
+
throw new Error(`[ee-core] [loader] getFullpath filepath ${fullpath} not exists`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return fullpath;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
package/log/index.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
const dayjs = require('dayjs');
|
|
2
|
-
const Logger = require('./logger');
|
|
3
|
-
const EELoggers = Symbol('EeApplication#EELoggers');
|
|
4
|
-
let LogDate = 0;
|
|
5
|
-
|
|
6
|
-
const Log = {
|
|
7
|
-
/**
|
|
8
|
-
* 创建日志实例
|
|
9
|
-
*/
|
|
10
|
-
create(config) {
|
|
11
|
-
this._delCache();
|
|
12
|
-
const eeLog = Logger.create(config);
|
|
13
|
-
|
|
14
|
-
return eeLog;
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* delete cache
|
|
19
|
-
*/
|
|
20
|
-
_delCache() {
|
|
21
|
-
let now = parseInt(dayjs().format('YYYYMMDD'));
|
|
22
|
-
if (LogDate != now) {
|
|
23
|
-
LogDate = now;
|
|
24
|
-
this[EELoggers] = null;
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* logger
|
|
30
|
-
*/
|
|
31
|
-
get logger() {
|
|
32
|
-
this._delCache();
|
|
33
|
-
if (!this[EELoggers]) {
|
|
34
|
-
this[EELoggers] = Logger.create();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this[EELoggers]['logger'] || null;
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* coreLogger
|
|
42
|
-
*/
|
|
43
|
-
get coreLogger () {
|
|
44
|
-
this._delCache();
|
|
45
|
-
if (!this[EELoggers]) {
|
|
46
|
-
this[EELoggers] = Logger.create();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return this[EELoggers]['coreLogger'] || null;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
get error() {
|
|
53
|
-
return this.logger.error.bind(this.logger);
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
get warn() {
|
|
57
|
-
return this.logger.warn.bind(this.logger);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
get info() {
|
|
61
|
-
return this.logger.info.bind(this.logger);
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
get debug() {
|
|
65
|
-
return this.logger.debug.bind(this.logger);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
1
|
+
const dayjs = require('dayjs');
|
|
2
|
+
const Logger = require('./logger');
|
|
3
|
+
const EELoggers = Symbol('EeApplication#EELoggers');
|
|
4
|
+
let LogDate = 0;
|
|
5
|
+
|
|
6
|
+
const Log = {
|
|
7
|
+
/**
|
|
8
|
+
* 创建日志实例
|
|
9
|
+
*/
|
|
10
|
+
create(config) {
|
|
11
|
+
this._delCache();
|
|
12
|
+
const eeLog = Logger.create(config);
|
|
13
|
+
|
|
14
|
+
return eeLog;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* delete cache
|
|
19
|
+
*/
|
|
20
|
+
_delCache() {
|
|
21
|
+
let now = parseInt(dayjs().format('YYYYMMDD'));
|
|
22
|
+
if (LogDate != now) {
|
|
23
|
+
LogDate = now;
|
|
24
|
+
this[EELoggers] = null;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* logger
|
|
30
|
+
*/
|
|
31
|
+
get logger() {
|
|
32
|
+
this._delCache();
|
|
33
|
+
if (!this[EELoggers]) {
|
|
34
|
+
this[EELoggers] = Logger.create();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this[EELoggers]['logger'] || null;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* coreLogger
|
|
42
|
+
*/
|
|
43
|
+
get coreLogger () {
|
|
44
|
+
this._delCache();
|
|
45
|
+
if (!this[EELoggers]) {
|
|
46
|
+
this[EELoggers] = Logger.create();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return this[EELoggers]['coreLogger'] || null;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
get error() {
|
|
53
|
+
return this.logger.error.bind(this.logger);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
get warn() {
|
|
57
|
+
return this.logger.warn.bind(this.logger);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
get info() {
|
|
61
|
+
return this.logger.info.bind(this.logger);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
get debug() {
|
|
65
|
+
return this.logger.debug.bind(this.logger);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
69
|
module.exports = Log;
|
package/log/logger.js
CHANGED
|
@@ -1,81 +1,87 @@
|
|
|
1
|
-
const Loggers = require('egg-logger').EggLoggers;
|
|
2
|
-
const assert = require('assert');
|
|
3
|
-
const dayjs = require('dayjs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const Ps = require('../ps');
|
|
6
|
-
const Conf = require('../config');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
opt
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
const Loggers = require('egg-logger').EggLoggers;
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const dayjs = require('dayjs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const Ps = require('../ps');
|
|
6
|
+
const Conf = require('../config');
|
|
7
|
+
const ConfigCache = require('../config/cache');
|
|
8
|
+
let LogDate = 0;
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 创建
|
|
14
|
+
*/
|
|
15
|
+
create(config = {}) {
|
|
16
|
+
let opt = {};
|
|
17
|
+
|
|
18
|
+
if (Object.keys(config).length == 0) {
|
|
19
|
+
const defaultConfig = {
|
|
20
|
+
logger: {
|
|
21
|
+
type: 'application',
|
|
22
|
+
dir: Ps.getLogDir(),
|
|
23
|
+
encoding: 'utf8',
|
|
24
|
+
env: Ps.env(),
|
|
25
|
+
level: 'INFO',
|
|
26
|
+
consoleLevel: 'INFO',
|
|
27
|
+
disableConsoleAfterReady: !Ps.isDev(),
|
|
28
|
+
outputJSON: false,
|
|
29
|
+
buffer: true,
|
|
30
|
+
appLogName: `ee.log`,
|
|
31
|
+
coreLogName: 'ee-core.log',
|
|
32
|
+
agentLogName: 'ee-agent.log',
|
|
33
|
+
errorLogName: `ee-error.log`,
|
|
34
|
+
coreLogger: {},
|
|
35
|
+
allowDebugAtProd: false,
|
|
36
|
+
enablePerformanceTimer: false,
|
|
37
|
+
rotator: 'none',
|
|
38
|
+
},
|
|
39
|
+
customLogger: {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 先从 cache 中读配置且不能抛出错误,如果没有从文件中读(子进程无法获取 cache)
|
|
43
|
+
let sysConfig = ConfigCache.all(false);
|
|
44
|
+
if (!sysConfig) {
|
|
45
|
+
sysConfig = Conf.all(false);
|
|
46
|
+
}
|
|
47
|
+
opt = Object.assign(defaultConfig, {
|
|
48
|
+
logger: sysConfig.logger,
|
|
49
|
+
customLogger: sysConfig.customLogger || {}
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
opt.logger = config.logger;
|
|
53
|
+
opt.customLogger = config.customLogger;
|
|
54
|
+
}
|
|
55
|
+
// console.log('log---------', opt);
|
|
56
|
+
|
|
57
|
+
assert(Object.keys(opt).length != 0, `logger config is null`);
|
|
58
|
+
|
|
59
|
+
let rotateType = opt.logger.rotator;
|
|
60
|
+
if (rotateType == 'day') {
|
|
61
|
+
this._rotateByDay(opt);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const loggers = new Loggers(opt);
|
|
65
|
+
|
|
66
|
+
return loggers;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 按天分割
|
|
71
|
+
*/
|
|
72
|
+
_rotateByDay(logOpt) {
|
|
73
|
+
let now = parseInt(dayjs().format('YYYYMMDD'));
|
|
74
|
+
if (LogDate != now) {
|
|
75
|
+
LogDate = now;
|
|
76
|
+
let appLogName = logOpt.logger.appLogName;
|
|
77
|
+
let coreLogName = logOpt.logger.coreLogName;
|
|
78
|
+
let errorLogName = logOpt.logger.errorLogName;
|
|
79
|
+
let appLogExtname = path.extname(appLogName);
|
|
80
|
+
let coreLogExtname = path.extname(coreLogName);
|
|
81
|
+
let errorLogExtname = path.extname(errorLogName);
|
|
82
|
+
logOpt.logger.appLogName = path.basename(appLogName, appLogExtname) + '-' + now + appLogExtname;
|
|
83
|
+
logOpt.logger.coreLogName = path.basename(coreLogName, coreLogExtname) + '-' + now + coreLogExtname;
|
|
84
|
+
logOpt.logger.errorLogName = path.basename(errorLogName, errorLogExtname) + '-' + now + errorLogExtname;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
81
87
|
};
|