@zxhy-npm/send-sls-logger 1.1.17 → 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 +8 -5
- package/package.json +1 -1
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
|
}
|