@youpaichris/logger 6.0.9 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +10 -9
- package/package.json +1 -1
- package/tests.js +2 -1
package/index.js
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
* Chris / QQ:10512
|
6
6
|
*/
|
7
7
|
|
8
|
-
const fs = require('fs');
|
9
8
|
const {createWriteStreamWithDirectories} = require('./utils.js');
|
10
9
|
|
11
10
|
let logFilePath, logFile, successFilePath, successFile, errorFilePath, errorFile, criticalFilePath, criticalFile;
|
@@ -141,7 +140,6 @@ class Logger {
|
|
141
140
|
}
|
142
141
|
|
143
142
|
initLogPath() {
|
144
|
-
|
145
143
|
let e = process.platform === `win32` ? __filename.split("\\") : __filename.split("/");
|
146
144
|
let path = e.slice(0, e.indexOf("node_modules")).join("/");
|
147
145
|
logFilePath = e.at(e.indexOf("node_modules") - 1) === 'logger' ? `log.log` : e.at(e.indexOf("node_modules") - 1) + `.log`;
|
@@ -171,7 +169,7 @@ class Logger {
|
|
171
169
|
...msg,
|
172
170
|
consoleStyles['blue'][1] + consoleStyles['bold'][1] + '\b'
|
173
171
|
);
|
174
|
-
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | INFO | ${pathLine.padEnd(22, " ")}${
|
172
|
+
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | INFO | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n');
|
175
173
|
};
|
176
174
|
|
177
175
|
warn(...msg) {
|
@@ -184,7 +182,7 @@ class Logger {
|
|
184
182
|
...msg,
|
185
183
|
consoleStyles['yellow'][1] + consoleStyles['bold'][1] + '\b'
|
186
184
|
);
|
187
|
-
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | WARNING | ${pathLine.padEnd(22, " ")}${
|
185
|
+
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | WARNING | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n');
|
188
186
|
};
|
189
187
|
|
190
188
|
error(...msg) {
|
@@ -198,7 +196,7 @@ class Logger {
|
|
198
196
|
consoleStyles['red'][1] + consoleStyles['bold'][1] + '\b'
|
199
197
|
);
|
200
198
|
if (this.save) {
|
201
|
-
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | ERROR | ${pathLine.padEnd(22, " ")}${
|
199
|
+
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | ERROR | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n';
|
202
200
|
logFile.write(_msg);
|
203
201
|
errorFile.write(_msg);
|
204
202
|
}
|
@@ -216,7 +214,7 @@ class Logger {
|
|
216
214
|
consoleStyles['green'][1] + consoleStyles['bold'][1] + '\b'
|
217
215
|
);
|
218
216
|
if (this.save) {
|
219
|
-
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | SUCCESS | ${pathLine.padEnd(22, " ")}${
|
217
|
+
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | SUCCESS | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n';
|
220
218
|
logFile.write(_msg);
|
221
219
|
successFile.write(_msg);
|
222
220
|
}
|
@@ -234,7 +232,7 @@ class Logger {
|
|
234
232
|
...msg,
|
235
233
|
consoleStyles['magenta'][1] + consoleStyles['bold'][1] + '\b'
|
236
234
|
);
|
237
|
-
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | DEBUG | ${pathLine.padEnd(22, " ")}${
|
235
|
+
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | DEBUG | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n');
|
238
236
|
|
239
237
|
};
|
240
238
|
|
@@ -248,7 +246,7 @@ class Logger {
|
|
248
246
|
...msg,
|
249
247
|
consoleStyles['cyan'][1] + consoleStyles['bold'][1] + '\b'
|
250
248
|
);
|
251
|
-
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | CALL | ${pathLine.padEnd(22, " ")}${
|
249
|
+
this.save && logFile.write(`${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | CALL | ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n');
|
252
250
|
|
253
251
|
};
|
254
252
|
|
@@ -263,7 +261,7 @@ class Logger {
|
|
263
261
|
consoleStyles['redBG'][1] + consoleStyles['bold'][1] + '\b', consoleStyles['redBG'][1] + consoleStyles['bold'][1] + '\b'
|
264
262
|
);
|
265
263
|
if (this.save) {
|
266
|
-
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | CRITICAL| ${pathLine.padEnd(22, " ")}${
|
264
|
+
let _msg = `${dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date())} | CRITICAL| ${pathLine.padEnd(22, " ")}${msg.map(e => typeof e === 'object' ? JSON.stringify(e) : e).join(" ")}` + '\n';
|
267
265
|
logFile.write(_msg);
|
268
266
|
criticalFile.write(_msg);
|
269
267
|
}
|
@@ -291,6 +289,9 @@ class Logger {
|
|
291
289
|
*/
|
292
290
|
process.on('exit', () => {
|
293
291
|
logFile?.end();
|
292
|
+
successFile?.end();
|
293
|
+
errorFile?.end();
|
294
|
+
criticalFile?.end();
|
294
295
|
});
|
295
296
|
module.exports = Logger;
|
296
297
|
|
package/package.json
CHANGED
package/tests.js
CHANGED