@jayfong/x-server 2.2.11 → 2.2.13
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/lib/_cjs/services/log.js +14 -7
- package/lib/services/log.d.ts +1 -0
- package/lib/services/log.js +14 -7
- package/package.json +1 -1
package/lib/_cjs/services/log.js
CHANGED
|
@@ -28,25 +28,32 @@ class LogService {
|
|
|
28
28
|
}, logFile => logFile);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
getLogFile(date) {
|
|
32
|
+
const year = date.getFullYear();
|
|
33
|
+
const month = date.getMonth() + 1;
|
|
34
|
+
return _path.default.join(_x.x.dataDir, `log/${year}/${month < 10 ? `0${month}` : month}.log`);
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
get logFile() {
|
|
32
|
-
|
|
33
|
-
const year = now.getFullYear();
|
|
34
|
-
const month = now.getMonth() + 1;
|
|
35
|
-
return _path.default.join(_x.x.dataDir, `log/${year}/${month}.log`);
|
|
38
|
+
return this.getLogFile(new Date());
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
parseLogLineText(text) {
|
|
39
|
-
const [time, level, title, desc] = text.split(this.separator);
|
|
42
|
+
const [time, level, title, ...desc] = text.split(this.separator);
|
|
40
43
|
return {
|
|
41
44
|
time: time,
|
|
42
45
|
level: level,
|
|
43
46
|
title: title,
|
|
44
|
-
desc:
|
|
47
|
+
desc: desc.reduce((res, item) => {
|
|
48
|
+
const i = item.indexOf(':');
|
|
49
|
+
res[item.substring(0, i)] = item.substring(i + 1);
|
|
50
|
+
return res;
|
|
51
|
+
}, {})
|
|
45
52
|
};
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
log(payload) {
|
|
49
|
-
this.getLogWriter(this.logFile).write(`${(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss')
|
|
56
|
+
this.getLogWriter(this.logFile).write(`${[(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...Object.keys(payload.desc || {}).map(key => `${key}:${payload.desc[key]}`)].join(this.separator).replace(/[\r\n]+/g, ' ')}\n`);
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
info(title, desc) {
|
package/lib/services/log.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare type LogServicePayloadWithTime = LogServicePayload & {
|
|
|
11
11
|
export declare class LogService implements BaseService {
|
|
12
12
|
serviceName: string;
|
|
13
13
|
private separator;
|
|
14
|
+
getLogFile(date: Date): string;
|
|
14
15
|
private get logFile();
|
|
15
16
|
private getLogWriter;
|
|
16
17
|
parseLogLineText(text: string): LogServicePayloadWithTime;
|
package/lib/services/log.js
CHANGED
|
@@ -15,25 +15,32 @@ export class LogService {
|
|
|
15
15
|
}, logFile => logFile);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
getLogFile(date) {
|
|
19
|
+
const year = date.getFullYear();
|
|
20
|
+
const month = date.getMonth() + 1;
|
|
21
|
+
return path.join(x.dataDir, `log/${year}/${month < 10 ? `0${month}` : month}.log`);
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
get logFile() {
|
|
19
|
-
|
|
20
|
-
const year = now.getFullYear();
|
|
21
|
-
const month = now.getMonth() + 1;
|
|
22
|
-
return path.join(x.dataDir, `log/${year}/${month}.log`);
|
|
25
|
+
return this.getLogFile(new Date());
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
parseLogLineText(text) {
|
|
26
|
-
const [time, level, title, desc] = text.split(this.separator);
|
|
29
|
+
const [time, level, title, ...desc] = text.split(this.separator);
|
|
27
30
|
return {
|
|
28
31
|
time: time,
|
|
29
32
|
level: level,
|
|
30
33
|
title: title,
|
|
31
|
-
desc:
|
|
34
|
+
desc: desc.reduce((res, item) => {
|
|
35
|
+
const i = item.indexOf(':');
|
|
36
|
+
res[item.substring(0, i)] = item.substring(i + 1);
|
|
37
|
+
return res;
|
|
38
|
+
}, {})
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
log(payload) {
|
|
36
|
-
this.getLogWriter(this.logFile).write(`${formatDate(new Date(), 'yyyy-mm-dd hh:ii:ss')
|
|
43
|
+
this.getLogWriter(this.logFile).write(`${[formatDate(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...Object.keys(payload.desc || {}).map(key => `${key}:${payload.desc[key]}`)].join(this.separator).replace(/[\r\n]+/g, ' ')}\n`);
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
info(title, desc) {
|