@jayfong/x-server 2.40.0 → 2.40.2
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 +3 -3
- package/lib/services/log.d.ts +5 -3
- package/lib/services/log.js +3 -3
- package/package.json +1 -1
package/lib/_cjs/services/log.js
CHANGED
|
@@ -27,15 +27,15 @@ class LogService {
|
|
|
27
27
|
get logFile() {
|
|
28
28
|
return this.getLogFile(new Date());
|
|
29
29
|
}
|
|
30
|
-
parseLogLineText(text,
|
|
30
|
+
parseLogLineText(text, keysMap = {}) {
|
|
31
31
|
const [time, level, title, ...desc] = text.split(this.separator);
|
|
32
32
|
return {
|
|
33
33
|
time: time,
|
|
34
34
|
level: level,
|
|
35
35
|
title: title,
|
|
36
36
|
desc: desc.reduce((res, item, index) => {
|
|
37
|
-
if (
|
|
38
|
-
res[
|
|
37
|
+
if (keysMap[title]) {
|
|
38
|
+
res[keysMap[title][index]] = item;
|
|
39
39
|
} else {
|
|
40
40
|
const i = item.indexOf(':');
|
|
41
41
|
res[item.substring(0, i)] = item.substring(i + 1);
|
package/lib/services/log.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Merge } from 'vtils/types';
|
|
1
2
|
import { BaseService } from './base';
|
|
2
3
|
export type LogServiceLevel = 'error' | 'info' | 'success';
|
|
3
4
|
export type LogServiceDesc = Record<string, any> | any[];
|
|
@@ -6,16 +7,17 @@ export type LogServicePayload = {
|
|
|
6
7
|
title: string;
|
|
7
8
|
desc?: LogServiceDesc;
|
|
8
9
|
};
|
|
9
|
-
export type
|
|
10
|
+
export type LogServiceLogItem<K extends string = string> = Merge<LogServicePayload, {
|
|
10
11
|
time: string;
|
|
11
|
-
|
|
12
|
+
desc: Record<K, any>;
|
|
13
|
+
}>;
|
|
12
14
|
export declare class LogService implements BaseService {
|
|
13
15
|
serviceName: string;
|
|
14
16
|
private separator;
|
|
15
17
|
getLogFile(date: Date): string;
|
|
16
18
|
private get logFile();
|
|
17
19
|
private getLogWriter;
|
|
18
|
-
parseLogLineText(text: string,
|
|
20
|
+
parseLogLineText<K extends string = string>(text: string, keysMap?: Record<string, string[]>): LogServiceLogItem<K>;
|
|
19
21
|
private log;
|
|
20
22
|
info(title: string, desc?: LogServiceDesc): void;
|
|
21
23
|
success(title: string, desc?: LogServiceDesc): void;
|
package/lib/services/log.js
CHANGED
|
@@ -22,15 +22,15 @@ export class LogService {
|
|
|
22
22
|
get logFile() {
|
|
23
23
|
return this.getLogFile(new Date());
|
|
24
24
|
}
|
|
25
|
-
parseLogLineText(text,
|
|
25
|
+
parseLogLineText(text, keysMap = {}) {
|
|
26
26
|
const [time, level, title, ...desc] = text.split(this.separator);
|
|
27
27
|
return {
|
|
28
28
|
time: time,
|
|
29
29
|
level: level,
|
|
30
30
|
title: title,
|
|
31
31
|
desc: desc.reduce((res, item, index) => {
|
|
32
|
-
if (
|
|
33
|
-
res[
|
|
32
|
+
if (keysMap[title]) {
|
|
33
|
+
res[keysMap[title][index]] = item;
|
|
34
34
|
} else {
|
|
35
35
|
const i = item.indexOf(':');
|
|
36
36
|
res[item.substring(0, i)] = item.substring(i + 1);
|