mm_os 3.2.3 → 3.2.5

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.
@@ -1,169 +0,0 @@
1
- /**
2
- * 日志类
3
- */
4
- class Log {
5
- /**
6
- * 构造函数
7
- * @param {Object} config 配置参数
8
- */
9
- constructor(config) {
10
- this.config = {
11
- filename: '/log/output.log',
12
- console: false
13
- };
14
- this.init(config);
15
- }
16
- }
17
-
18
- /**
19
- * 初始化
20
- * @returns {Object} 配置参数
21
- */
22
- Log.prototype.init = function(config) {
23
- Object.assign(this.config, config);
24
- this.config.filename.addDir();
25
- }
26
-
27
- /**
28
- * 清空日志
29
- * @returns {String} 返回日志内容
30
- */
31
- Log.prototype.clear = function() {
32
- var file = this.config.filename;
33
- if(file.hasFile()){
34
- file.delFile();
35
- return true;
36
- }
37
- return false;
38
- }
39
-
40
- /**
41
- * 加载日志
42
- * @returns {String} 返回日志内容
43
- */
44
- Log.prototype.load = function() {
45
- return this.config.filename.loadText() || "";
46
- }
47
-
48
- /**
49
- * 保存日志
50
- * @param {String} text 日志
51
- */
52
- Log.prototype.save = function(text) {
53
- return this.config.filename.saveText(text);
54
- }
55
-
56
- /**
57
- * 读取日志指定条
58
- * @param {Number} index 索引,默认为最后一条
59
- */
60
- Log.prototype.read = function(index = -1) {
61
- var text = this.load();
62
- var arr = text.split(/\n\[/);
63
- if (index < 0) {
64
- index = arr.length - 1;
65
- }
66
- var str = arr[index];
67
- if (index == 0) {
68
- return str;
69
- }
70
- return "[" + str;
71
- }
72
-
73
- /**
74
- * 获取日志列表
75
- * @returns {Array} 返回日志列表
76
- */
77
- Log.prototype.list = function() {
78
- var text = this.load();
79
- var arr = text.split(/\n\[/);
80
- return arr.map((str, i) => {
81
- if (i == 0) {
82
- return str;
83
- }
84
- return "[" + str;
85
- });
86
- }
87
-
88
- /**
89
- * 添加日志
90
- * @param {String} type 日志类型
91
- * @param {String} tag 日志标签
92
- * @param {Object} arg 其他要输出的信息
93
- */
94
- Log.prototype.add = function(type, tag, ...arg) {
95
- var now = new Date();
96
- var datetime = now.toStr('yyyy-MM-dd hh:mm:ss');
97
- var list = new Array(arg);
98
- var content = "";
99
- for (var i = 0; i < list.length; i++) {
100
- var o = list[i];
101
- content += " " + o.toString();
102
- }
103
- var str = `\n[${datetime}] [${type}] ${tag} -` + content;
104
- var text = this.load();
105
- text += str;
106
- this.save(text.trim());
107
- }
108
-
109
- /**
110
- * @description 信息
111
- * @param {String} tag 日志标签
112
- * @param {Object} arg 其他要输出的信息
113
- */
114
- Log.prototype.debug = function(tag, ...arg) {
115
- if (this.config.console) {
116
- console.log(tag, ...arg);
117
- }
118
- this.add('debug', tag, ...arg);
119
- };
120
-
121
- /**
122
- * @description 信息
123
- * @param {String} tag 日志标签
124
- * @param {Object} arg 其他要输出的信息
125
- */
126
- Log.prototype.info = function(tag, ...arg) {
127
- if (this.config.console) {
128
- console.info(tag.blue, ...arg);
129
- }
130
- this.add('info', tag, ...arg);
131
- };
132
-
133
- /**
134
- * @description 信息
135
- * @param {String} tag 日志标签
136
- * @param {Object} arg 其他要输出的信息
137
- */
138
- Log.prototype.warn = function(tag, ...arg) {
139
- if (this.config.console) {
140
- console.warn(tag.yellow, ...arg);
141
- }
142
- this.add('warn', tag, ...arg);
143
- };
144
-
145
- /**
146
- * @description 信息
147
- * @param {String} tag 日志标签
148
- * @param {Object} arg 其他要输出的信息
149
- */
150
- Log.prototype.error = function(tag, ...arg) {
151
- if (this.config.console) {
152
- console.error(tag.red, ...arg);
153
- }
154
- this.add('error', tag, ...arg);
155
- };
156
-
157
- /**
158
- * @description 成功
159
- * @param {String} tag 日志标签
160
- * @param {Object} arg 其他要输出的信息
161
- */
162
- Log.prototype.success = function(tag, ...arg) {
163
- if (this.config.console) {
164
- console.success(tag.green, ...arg);
165
- }
166
- this.add('debug', tag, ...arg);
167
- };
168
-
169
- module.exports = Log;