@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 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: (...args: any[]) => void;
48
- warn: (...args: any[]) => void;
49
- log: (...args: any[]) => void;
50
- info: (...args: any[]) => void;
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 === 'string') {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zxhy-npm/send-sls-logger",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "阿里云sls的logger发送",
5
5
  "scripts": {
6
6
  "build": "rm -rf lib && tsc"