@zxhy-npm/send-sls-logger 0.0.1 → 1.0.1
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/index.d.ts +3 -69
- package/lib/index.js +9 -6
- package/lib/init.d.ts +54 -0
- package/lib/init.js +127 -129
- package/lib/mini.d.ts +3 -71
- package/lib/mini.js +9 -6
- package/package.json +32 -28
- package/readme.md +6 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,70 +1,4 @@
|
|
|
1
1
|
import { WebTrackerBrowserOptions } from "@aliyun-sls/web-track-browser";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
8
|
-
type FormatResult = (result: any) => any;
|
|
9
|
-
|
|
10
|
-
interface initConfig {
|
|
11
|
-
debug?: boolean;
|
|
12
|
-
/** 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等 */
|
|
13
|
-
defaultData?: StringObject;
|
|
14
|
-
/** 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志 */
|
|
15
|
-
defaultExclude?: string[];
|
|
16
|
-
options?: WebTrackerBrowserOptions;
|
|
17
|
-
/** 最大字符长度,如果关键字里包含token,则不进行截断 */
|
|
18
|
-
strMaxLength?: number;
|
|
19
|
-
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
20
|
-
userFormatResult?: FormatResult;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export = slsLog;
|
|
24
|
-
export as namespace slsLog;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* PC端sls日志组件,使用init初始化项目,填入 options(host、project、logstore);
|
|
28
|
-
* 在后续使用的时候,直接调用error|warn|log|into向sls发送日志
|
|
29
|
-
*/
|
|
30
|
-
declare namespace slsLog {
|
|
31
|
-
/**
|
|
32
|
-
* @name 发送error日志
|
|
33
|
-
* 接收两个参数,
|
|
34
|
-
* @param log string | StringObject
|
|
35
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
36
|
-
* */
|
|
37
|
-
function error(str: string | StringObject, format?: FormatResult): void;
|
|
38
|
-
/**
|
|
39
|
-
* @name 发送警告日志
|
|
40
|
-
* 接收两个参数,
|
|
41
|
-
* @param log string | StringObject
|
|
42
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
43
|
-
* */
|
|
44
|
-
function warn(str: string | StringObject, format?: FormatResult): void;
|
|
45
|
-
/**
|
|
46
|
-
* @name 发送普通日志
|
|
47
|
-
* 接收两个参数,
|
|
48
|
-
* @param log string | StringObject
|
|
49
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
50
|
-
* */
|
|
51
|
-
function log(str: string | StringObject, format?: FormatResult): void;
|
|
52
|
-
/**
|
|
53
|
-
* @name 发送普通日志
|
|
54
|
-
* 接收两个参数,
|
|
55
|
-
* @param log string | StringObject
|
|
56
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
57
|
-
* */
|
|
58
|
-
function info(str: string | StringObject, format?: FormatResult): void;
|
|
59
|
-
/**
|
|
60
|
-
* @name 初始化init
|
|
61
|
-
* @description 可以多次调用,在发送日志之前,一定要初始化过 options(host、project、logstore) 内容
|
|
62
|
-
* @param debug 是否开启debug模式
|
|
63
|
-
* @param defaultData 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等
|
|
64
|
-
* @param defaultExclude 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志
|
|
65
|
-
* @param options host、project、logstore
|
|
66
|
-
* @param strMaxLength 是否开启debug模式 最大字符长度,如果关键字里包含token,则不进行截断
|
|
67
|
-
* @param userFormatResult 对最终发送的日志进行兜底处理,只能在init中使用
|
|
68
|
-
*/
|
|
69
|
-
function init(config: initConfig): void;
|
|
70
|
-
}
|
|
2
|
+
import DefaultLog, { InitConfig } from "./init";
|
|
3
|
+
declare const SLSLog: (config: InitConfig<WebTrackerBrowserOptions>) => DefaultLog<WebTrackerBrowserOptions>;
|
|
4
|
+
export default SLSLog;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const web_track_browser_1 = __importDefault(require("@aliyun-sls/web-track-browser"));
|
|
7
|
+
const init_1 = __importDefault(require("./init"));
|
|
8
|
+
const SLSLog = (config) => new init_1.default(web_track_browser_1.default, config);
|
|
9
|
+
exports.default = SLSLog;
|
package/lib/init.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
interface StringObject {
|
|
2
|
+
[name: string]: any;
|
|
3
|
+
}
|
|
4
|
+
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
5
|
+
type FormatResult = (result: any) => any;
|
|
6
|
+
interface LogOptions {
|
|
7
|
+
host: string;
|
|
8
|
+
project: string;
|
|
9
|
+
logstore: string;
|
|
10
|
+
time?: number;
|
|
11
|
+
count?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface InitConfig<T extends LogOptions> {
|
|
14
|
+
/** 是否开启debug模式 */
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
/** 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等 */
|
|
17
|
+
defaultData?: StringObject;
|
|
18
|
+
/** 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志 */
|
|
19
|
+
defaultExclude?: string[];
|
|
20
|
+
options?: T;
|
|
21
|
+
/** 最大字符长度,如果关键字里包含token,则不进行截断 */
|
|
22
|
+
strMaxLength?: number;
|
|
23
|
+
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
24
|
+
userFormatResult?: FormatResult;
|
|
25
|
+
}
|
|
26
|
+
declare class DefaultLog<T extends LogOptions> {
|
|
27
|
+
opts: {
|
|
28
|
+
host: string;
|
|
29
|
+
project: string;
|
|
30
|
+
logstore: string;
|
|
31
|
+
time: number;
|
|
32
|
+
count: number;
|
|
33
|
+
};
|
|
34
|
+
private defaultLogData;
|
|
35
|
+
private exclude;
|
|
36
|
+
private tracker;
|
|
37
|
+
private userFormatResult?;
|
|
38
|
+
private debug;
|
|
39
|
+
private maxLength;
|
|
40
|
+
private Tracker;
|
|
41
|
+
constructor(Tracker: new (config: T) => any, config: InitConfig<T>);
|
|
42
|
+
/** init 可以多次调用,最好在初次,填入 options 内容 */
|
|
43
|
+
init(config: InitConfig<T>): void;
|
|
44
|
+
private formatDataMaxLength;
|
|
45
|
+
private formatFunctionObj;
|
|
46
|
+
private formatLogData;
|
|
47
|
+
private sendResult;
|
|
48
|
+
private send;
|
|
49
|
+
error: (...args: any[]) => void;
|
|
50
|
+
warn: (...args: any[]) => void;
|
|
51
|
+
log: (...args: any[]) => void;
|
|
52
|
+
info: (...args: any[]) => void;
|
|
53
|
+
}
|
|
54
|
+
export default DefaultLog;
|
package/lib/init.js
CHANGED
|
@@ -1,131 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
project: "", // Project名称。
|
|
4
|
-
logstore: "", // Logstore名称。
|
|
5
|
-
time: 5, // 发送日志的时间间隔,默认是10秒。
|
|
6
|
-
count: 10, // 发送日志的数量大小,默认是10条。
|
|
7
|
-
};
|
|
8
|
-
const defaultLogData = {};
|
|
9
|
-
const exclude = [];
|
|
10
|
-
let tracker;
|
|
11
|
-
let userFormatResult;
|
|
12
|
-
let debug;
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
const getType = (val) => {
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
let maxLength = 200;
|
|
19
|
-
const formatDataMaxLength = (data) => {
|
|
20
|
-
if (getType(data) === "object") {
|
|
21
|
-
return Object.keys(data).reduce((curr, key) => {
|
|
22
|
-
curr[key] = /token/.test(key)
|
|
23
|
-
? data[key]
|
|
24
|
-
: formatDataMaxLength(data[key]);
|
|
25
|
-
return curr;
|
|
26
|
-
}, {});
|
|
27
|
-
} else if (getType(data) === "array") {
|
|
28
|
-
return data.map((i) => formatDataMaxLength(i));
|
|
29
|
-
} else if (getType(data) === "string" && data.length > maxLength) {
|
|
30
|
-
return `${data.slice(0, maxLength)}...${data.length - maxLength}个字已忽略`;
|
|
31
|
-
} else {
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const formatFunctionObj = (data) => {
|
|
37
|
-
if (getType(data) === "object") {
|
|
38
|
-
return Object.keys(data).reduce((curr, key) => {
|
|
39
|
-
curr[key] = formatFunctionObj(data[key]);
|
|
40
|
-
return curr;
|
|
41
|
-
}, {});
|
|
42
|
-
} else if (getType(data) === "array") {
|
|
43
|
-
return data.map((i) => formatFunctionObj(i));
|
|
44
|
-
} else if (getType(data) === "function") {
|
|
45
|
-
return data();
|
|
46
|
-
} else {
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const formatLogData = (data, type = "log") => {
|
|
51
|
-
const result = { ...defaultLogData, type };
|
|
52
|
-
if (typeof data === "string") {
|
|
53
|
-
Object.assign(result, { data });
|
|
54
|
-
} else if (typeof data === "object") {
|
|
55
|
-
Object.assign(result, data);
|
|
56
|
-
}
|
|
57
|
-
return formatFunctionObj(result);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const send = (type) => {
|
|
61
|
-
return function (err, activeFormatResult) {
|
|
62
|
-
let data = {};
|
|
63
|
-
if (typeof err === "string") {
|
|
64
|
-
data.msg = err;
|
|
65
|
-
} else if (typeof err === "object") {
|
|
66
|
-
data = { ...err };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const result = formatLogData(data, type);
|
|
70
|
-
const isExcludeMsg = Object.keys(result).find((key) => {
|
|
71
|
-
return exclude.find((i) => new RegExp(i, "g").test(result[key]));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (!opts.host || !opts.project || !opts.logstore) {
|
|
75
|
-
return console.warn("日志初始化需要配置options", result);
|
|
76
|
-
}
|
|
77
|
-
let formatResultObj = formatDataMaxLength(result);
|
|
78
|
-
|
|
79
|
-
if (getType(userFormatResult) === "function") {
|
|
80
|
-
formatResultObj = userFormatResult(formatResultObj) || formatResultObj;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (getType(activeFormatResult) === "function") {
|
|
84
|
-
formatResultObj = activeFormatResult(formatResultObj) || formatResultObj;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (isExcludeMsg) {
|
|
88
|
-
debug && console.log(`logger ${type}`, formatResultObj);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
tracker.send(formatResultObj);
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const error = send("error");
|
|
96
|
-
const warn = send("warn");
|
|
97
|
-
const log = send("info");
|
|
98
|
-
const info = send("info");
|
|
99
|
-
|
|
100
|
-
const logInit = (Tracker) => {
|
|
101
|
-
return (config) => {
|
|
102
|
-
const {
|
|
103
|
-
defaultData = {},
|
|
104
|
-
defaultExclude = [],
|
|
105
|
-
options = {},
|
|
106
|
-
strMaxLength = maxLength,
|
|
107
|
-
debug: defaultDebug = debug,
|
|
108
|
-
userFormatResult: defaultUserFormatResult = userFormatResult,
|
|
109
|
-
} = config;
|
|
110
|
-
|
|
111
|
-
if (defaultDebug !== undefined) {
|
|
112
|
-
debug = defaultDebug;
|
|
113
|
-
}
|
|
114
|
-
userFormatResult = defaultUserFormatResult;
|
|
115
|
-
Object.assign(defaultLogData, defaultData);
|
|
116
|
-
Object.assign(opts, options);
|
|
117
|
-
if (options.host && options.logstore && options.project) {
|
|
118
|
-
tracker = new Tracker(opts);
|
|
119
|
-
}
|
|
120
|
-
maxLength = strMaxLength;
|
|
121
|
-
exclude.push(...defaultExclude);
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export default {
|
|
126
|
-
error,
|
|
127
|
-
warn,
|
|
128
|
-
log,
|
|
129
|
-
info,
|
|
130
|
-
logInit,
|
|
4
|
+
return Object.prototype.toString.call(val).toLocaleLowerCase().slice(8, -1);
|
|
131
5
|
};
|
|
6
|
+
const defaultMaxLength = 200;
|
|
7
|
+
class DefaultLog {
|
|
8
|
+
opts = {
|
|
9
|
+
host: '',
|
|
10
|
+
project: '',
|
|
11
|
+
logstore: '',
|
|
12
|
+
time: 5,
|
|
13
|
+
count: 10, // 发送日志的数量大小,默认是10条。
|
|
14
|
+
};
|
|
15
|
+
defaultLogData = {};
|
|
16
|
+
exclude = [];
|
|
17
|
+
tracker;
|
|
18
|
+
userFormatResult;
|
|
19
|
+
debug = false;
|
|
20
|
+
maxLength = 200;
|
|
21
|
+
Tracker;
|
|
22
|
+
constructor(Tracker, config) {
|
|
23
|
+
this.Tracker = Tracker;
|
|
24
|
+
this.init(config);
|
|
25
|
+
}
|
|
26
|
+
/** init 可以多次调用,最好在初次,填入 options 内容 */
|
|
27
|
+
init(config) {
|
|
28
|
+
const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug = false, userFormatResult: defaultUserFormatResult = (_) => _, } = config;
|
|
29
|
+
if (defaultDebug !== undefined) {
|
|
30
|
+
this.debug = defaultDebug;
|
|
31
|
+
}
|
|
32
|
+
this.userFormatResult = defaultUserFormatResult;
|
|
33
|
+
Object.assign(this.defaultLogData, defaultData);
|
|
34
|
+
Object.assign(this.opts, options);
|
|
35
|
+
if (options?.host && options.logstore && options.project) {
|
|
36
|
+
this.tracker = new this.Tracker(options);
|
|
37
|
+
}
|
|
38
|
+
this.maxLength = strMaxLength;
|
|
39
|
+
this.exclude.push(...defaultExclude);
|
|
40
|
+
}
|
|
41
|
+
formatDataMaxLength(data) {
|
|
42
|
+
const { formatDataMaxLength, maxLength } = this;
|
|
43
|
+
if (getType(data) === 'object') {
|
|
44
|
+
return Object.keys(data).reduce((curr, key) => {
|
|
45
|
+
curr[key] = /token/.test(key) ? data[key] : formatDataMaxLength.call(this, data[key]);
|
|
46
|
+
return curr;
|
|
47
|
+
}, {});
|
|
48
|
+
}
|
|
49
|
+
else if (getType(data) === 'array') {
|
|
50
|
+
return data.map((i) => formatDataMaxLength.call(this, i));
|
|
51
|
+
}
|
|
52
|
+
else if (getType(data) === 'string' && data.length > maxLength) {
|
|
53
|
+
return `${data.slice(0, maxLength)}...${data.length - maxLength}个字已忽略`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
formatFunctionObj(data) {
|
|
60
|
+
const { formatFunctionObj } = this;
|
|
61
|
+
if (getType(data) === 'object') {
|
|
62
|
+
return Object.keys(data).reduce((curr, key) => {
|
|
63
|
+
curr[key] = formatFunctionObj.call(this, data[key]);
|
|
64
|
+
return curr;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
else if (getType(data) === 'array') {
|
|
68
|
+
return data.map((i) => formatFunctionObj.call(this, i));
|
|
69
|
+
}
|
|
70
|
+
else if (getType(data) === 'function') {
|
|
71
|
+
return data();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return data;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
formatLogData(data, type = 'log') {
|
|
78
|
+
console.log('formatLogData', this);
|
|
79
|
+
const { defaultLogData, formatFunctionObj } = this;
|
|
80
|
+
const result = { ...defaultLogData, type };
|
|
81
|
+
if (typeof data === 'string') {
|
|
82
|
+
Object.assign(result, { data });
|
|
83
|
+
}
|
|
84
|
+
else if (typeof data === 'object') {
|
|
85
|
+
Object.assign(result, data);
|
|
86
|
+
}
|
|
87
|
+
return formatFunctionObj.call(this, result);
|
|
88
|
+
}
|
|
89
|
+
sendResult(type, err, activeFormatResult) {
|
|
90
|
+
const { opts, formatLogData, formatDataMaxLength, userFormatResult, debug, tracker, exclude } = this;
|
|
91
|
+
let data = {};
|
|
92
|
+
if (typeof err === 'string') {
|
|
93
|
+
data.msg = err;
|
|
94
|
+
}
|
|
95
|
+
else if (typeof err === 'object') {
|
|
96
|
+
data = { ...err };
|
|
97
|
+
}
|
|
98
|
+
const result = formatLogData.call(this, data, type);
|
|
99
|
+
const isExcludeMsg = Object.keys(result).find((key) => {
|
|
100
|
+
return exclude.find((i) => new RegExp(i, 'g').test(result[key]));
|
|
101
|
+
});
|
|
102
|
+
if (!opts.host || !opts.project || !opts.logstore) {
|
|
103
|
+
return console.warn('日志初始化需要配置options', result);
|
|
104
|
+
}
|
|
105
|
+
let formatResultObj = formatDataMaxLength.call(this, result);
|
|
106
|
+
if (getType(userFormatResult) === 'function') {
|
|
107
|
+
formatResultObj = userFormatResult?.(formatResultObj) || formatResultObj;
|
|
108
|
+
}
|
|
109
|
+
if (getType(activeFormatResult) === 'function') {
|
|
110
|
+
formatResultObj = activeFormatResult?.(formatResultObj) || formatResultObj;
|
|
111
|
+
}
|
|
112
|
+
if (isExcludeMsg) {
|
|
113
|
+
debug && console.log(`logger ${type}`, formatResultObj);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
tracker.send(formatResultObj);
|
|
117
|
+
}
|
|
118
|
+
send(type) {
|
|
119
|
+
const self = this;
|
|
120
|
+
return (...args) => {
|
|
121
|
+
this.sendResult.call(self, type, ...args);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
error = this.send('error');
|
|
125
|
+
warn = this.send('warn');
|
|
126
|
+
log = this.send('info');
|
|
127
|
+
info = this.send('info');
|
|
128
|
+
}
|
|
129
|
+
exports.default = DefaultLog;
|
package/lib/mini.d.ts
CHANGED
|
@@ -1,71 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
7
|
-
type FormatResult = (result: any) => any;
|
|
8
|
-
|
|
9
|
-
/** init 可以多次调用,最好在初次,填入 options 内容 */
|
|
10
|
-
interface initConfig {
|
|
11
|
-
/** 是否开启debug模式 */
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
/** 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等 */
|
|
14
|
-
defaultData?: StringObject;
|
|
15
|
-
/** 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志 */
|
|
16
|
-
defaultExclude?: string[];
|
|
17
|
-
options?: WebTrackerMiniOptions;
|
|
18
|
-
/** 最大字符长度,如果关键字里包含token,则不进行截断 */
|
|
19
|
-
strMaxLength?: number;
|
|
20
|
-
/** 对最终发送的日志进行兜底处理,只能在init中使用 */
|
|
21
|
-
userFormatResult?: FormatResult;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export = miniLog;
|
|
25
|
-
export as namespace miniLog;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 小程序日志,使用init初始化项目,填入 options(host、project、logstore),init可以多次调用,填入defaultData等默认信息;
|
|
29
|
-
* 在后续使用的时候,直接调用error|warn|log|into向sls发送日志
|
|
30
|
-
*/
|
|
31
|
-
declare namespace miniLog {
|
|
32
|
-
/**
|
|
33
|
-
* @name 发送error日志
|
|
34
|
-
* 接收两个参数,
|
|
35
|
-
* @param log string | StringObject
|
|
36
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
37
|
-
* */
|
|
38
|
-
function error(str: string | StringObject, format?: FormatResult): void;
|
|
39
|
-
/**
|
|
40
|
-
* @name 发送警告日志
|
|
41
|
-
* 接收两个参数,
|
|
42
|
-
* @param log string | StringObject
|
|
43
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
44
|
-
* */
|
|
45
|
-
function warn(str: string | StringObject, format?: FormatResult): void;
|
|
46
|
-
/**
|
|
47
|
-
* @name 发送普通日志
|
|
48
|
-
* 接收两个参数,
|
|
49
|
-
* @param log string | StringObject
|
|
50
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
51
|
-
* */
|
|
52
|
-
function log(str: string | StringObject, format?: FormatResult): void;
|
|
53
|
-
/**
|
|
54
|
-
* @name 发送普通日志
|
|
55
|
-
* 接收两个参数,
|
|
56
|
-
* @param log string | StringObject
|
|
57
|
-
* @param format 整理即将发送的,返回要发送的日志结果
|
|
58
|
-
* */
|
|
59
|
-
function info(str: string | StringObject, format?: FormatResult): void;
|
|
60
|
-
/**
|
|
61
|
-
* @name 初始化init
|
|
62
|
-
* @description 可以多次调用,在发送日志之前,一定要初始化过 options(host、project、logstore) 内容
|
|
63
|
-
* @param debug 是否开启debug模式
|
|
64
|
-
* @param defaultData 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等
|
|
65
|
-
* @param defaultExclude 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志
|
|
66
|
-
* @param options host、project、logstore
|
|
67
|
-
* @param strMaxLength 是否开启debug模式 最大字符长度,如果关键字里包含token,则不进行截断
|
|
68
|
-
* @param userFormatResult 对最终发送的日志进行兜底处理,只能在init中使用
|
|
69
|
-
*/
|
|
70
|
-
function init(config: initConfig): void;
|
|
71
|
-
}
|
|
1
|
+
import DefaultLog, { InitConfig } from "./init";
|
|
2
|
+
declare const MiniInit: (config: InitConfig<any>) => DefaultLog<import("@aliyun-sls/web-track-mini").WebTrackerMiniOptions>;
|
|
3
|
+
export default MiniInit;
|
package/lib/mini.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const web_track_mini_1 = __importDefault(require("@aliyun-sls/web-track-mini"));
|
|
7
|
+
const init_1 = __importDefault(require("./init"));
|
|
8
|
+
const MiniInit = (config) => new init_1.default(web_track_mini_1.default, config);
|
|
9
|
+
exports.default = MiniInit;
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"name": "@zxhy-npm/send-sls-logger",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "阿里云sls的logger发送",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "rm -rf lib && tsc"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./lib/index.js",
|
|
15
|
+
"./mini": "./lib/mini.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"logger",
|
|
19
|
+
"sls"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"author": "liukai",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"esbuild": "^0.17.8",
|
|
28
|
+
"typescript": "^4.9.5"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@aliyun-sls/web-track-browser": "^0.0.3",
|
|
32
|
+
"@aliyun-sls/web-track-mini": "^0.0.2"
|
|
33
|
+
}
|
|
30
34
|
}
|
package/readme.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
## PC 使用方式
|
|
2
2
|
|
|
3
3
|
```javascript
|
|
4
|
-
import
|
|
4
|
+
import SLSLog from '@zxhy-npm/send-sls-logger';
|
|
5
|
+
|
|
6
|
+
const slsLog = SLSLog({});
|
|
5
7
|
slsLog.init({
|
|
6
8
|
defaultData: logDefaultData, // 默认带的数据
|
|
7
9
|
defaultExclude: ["模拟器", "ResizeObserver"], // 需要排除的数据
|
|
@@ -20,7 +22,9 @@ slsLog.info({ msg: "这是一条默认日志" });
|
|
|
20
22
|
## 小程序 使用方式
|
|
21
23
|
|
|
22
24
|
```javascript
|
|
23
|
-
import
|
|
25
|
+
import MiniLog from "@zxhy-npm/send-sls-logger/lib/mini";
|
|
26
|
+
|
|
27
|
+
const miniLog = MiniLog({});
|
|
24
28
|
miniLog.init({
|
|
25
29
|
defaultData: logDefaultData, // 默认带的数据
|
|
26
30
|
defaultExclude: ["模拟器", "ResizeObserver"], // 需要排除的数据
|