@zxhy-npm/send-sls-logger 1.1.16 → 1.1.18
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/init.d.ts +5 -4
- package/lib/init.js +11 -8
- package/package.json +3 -2
package/lib/init.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface InitConfig<T extends LogOptions> {
|
|
|
20
20
|
formatResultToBehavior?: boolean;
|
|
21
21
|
}
|
|
22
22
|
export declare function deleteNullOrUndefined(obj: any): any;
|
|
23
|
+
type InputType = number | string | Error | StringObject;
|
|
23
24
|
declare class DefaultLog<T extends LogOptions> {
|
|
24
25
|
opts: {
|
|
25
26
|
host: string;
|
|
@@ -44,10 +45,10 @@ declare class DefaultLog<T extends LogOptions> {
|
|
|
44
45
|
private formatLogData;
|
|
45
46
|
private sendResult;
|
|
46
47
|
private send;
|
|
47
|
-
error: (
|
|
48
|
-
warn: (
|
|
49
|
-
log: (
|
|
50
|
-
info: (
|
|
48
|
+
error: (result: InputType, formatResult: (result: StringObject) => StringObject) => void;
|
|
49
|
+
warn: (result: InputType, formatResult: (result: StringObject) => StringObject) => void;
|
|
50
|
+
log: (result: InputType, formatResult: (result: StringObject) => StringObject) => void;
|
|
51
|
+
info: (result: InputType, formatResult: (result: StringObject) => StringObject) => void;
|
|
51
52
|
}
|
|
52
53
|
export default DefaultLog;
|
|
53
54
|
export type LogClassInterface = InstanceType<typeof DefaultLog>;
|
package/lib/init.js
CHANGED
|
@@ -103,20 +103,23 @@ class DefaultLog {
|
|
|
103
103
|
formatLogData(data, type = 'log') {
|
|
104
104
|
const { defaultLogData, formatFunctionObj } = this;
|
|
105
105
|
const result = { ...defaultLogData, type };
|
|
106
|
-
if (typeof data === '
|
|
107
|
-
Object.assign(result, { data });
|
|
108
|
-
}
|
|
109
|
-
else if (typeof data === 'object') {
|
|
106
|
+
if (typeof data === 'object') {
|
|
110
107
|
Object.assign(result, data);
|
|
111
108
|
}
|
|
109
|
+
else if (typeof data === 'string') {
|
|
110
|
+
Object.assign(result, { data });
|
|
111
|
+
}
|
|
112
112
|
return formatFunctionObj.call(this, result);
|
|
113
113
|
}
|
|
114
114
|
sendResult(type, err, activeFormatResult) {
|
|
115
115
|
const { opts, formatLogData, formatDataMaxLength, userFormatResult, debug, tracker, exclude } = this;
|
|
116
116
|
let data = {};
|
|
117
|
-
if (typeof err === 'string') {
|
|
117
|
+
if (typeof err === 'string' || typeof err === 'number') {
|
|
118
118
|
data.msg = err;
|
|
119
119
|
}
|
|
120
|
+
else if (err instanceof Error) {
|
|
121
|
+
data.msg = err.message;
|
|
122
|
+
}
|
|
120
123
|
else if (typeof err === 'object') {
|
|
121
124
|
data = { ...err };
|
|
122
125
|
}
|
|
@@ -139,9 +142,6 @@ class DefaultLog {
|
|
|
139
142
|
if (getType(userFormatResult) === 'function') {
|
|
140
143
|
formatResultObj = userFormatResult?.(formatResultObj) || formatResultObj;
|
|
141
144
|
}
|
|
142
|
-
if (getType(activeFormatResult) === 'function') {
|
|
143
|
-
formatResultObj = activeFormatResult?.(formatResultObj) || formatResultObj;
|
|
144
|
-
}
|
|
145
145
|
if (isExcludeMsg) {
|
|
146
146
|
debug && console.log(`该日志已被忽略:`, formatResultObj);
|
|
147
147
|
return;
|
|
@@ -166,6 +166,9 @@ class DefaultLog {
|
|
|
166
166
|
});
|
|
167
167
|
Object.assign(formatResultObj, { ext });
|
|
168
168
|
}
|
|
169
|
+
if (getType(activeFormatResult) === 'function') {
|
|
170
|
+
formatResultObj = activeFormatResult?.(formatResultObj) || formatResultObj;
|
|
171
|
+
}
|
|
169
172
|
tracker.send({
|
|
170
173
|
...formatResultObj,
|
|
171
174
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zxhy-npm/send-sls-logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "阿里云sls的logger发送",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf lib && tsc"
|
|
@@ -26,5 +26,6 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@aliyun-sls/web-track-browser": "^0.0.3",
|
|
28
28
|
"@aliyun-sls/web-track-mini": "^0.0.2"
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"repository": "git@gitee.com:howlove/send-sls-logger.git"
|
|
30
31
|
}
|