1 | const logUpdate = require("log-update");
|
2 |
|
3 | module.exports = log;
|
4 |
|
5 | function log(msg, ...rest) {
|
6 | const date = new Date().toLocaleString();
|
7 |
|
8 | console.log("[" + date + "] - " + msg, ...rest);
|
9 | }
|
10 |
|
11 | log.update = function (msg) {
|
12 | const date = new Date().toLocaleString();
|
13 | logUpdate("[" + date + "] - " + msg);
|
14 | };
|
15 |
|
16 | log.clear = function () {
|
17 | logUpdate.clear();
|
18 | };
|
19 |
|
20 | let logList = [];
|
21 |
|
22 | log.save = function (msg) {
|
23 | logList.push(msg);
|
24 | };
|
25 | log.flush = function () {
|
26 | if (logList.length) {
|
27 | logList.forEach(msg => console.log(msg));
|
28 | logList = [];
|
29 | }
|
30 | };
|
31 |
|
32 | log.msg = function (msg) {
|
33 | const date = new Date().toLocaleString();
|
34 | return "[" + date + "] - " + msg;
|
35 | };
|