@warlock.js/logger 4.0.128 → 4.0.129
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/cjs/cron-parser.d.ts +98 -0
- package/cjs/cron-parser.d.ts.map +1 -0
- package/cjs/cron-parser.js +193 -0
- package/cjs/cron-parser.js.map +1 -0
- package/cjs/index.d.ts +43 -5
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/job.d.ts +332 -0
- package/cjs/job.d.ts.map +1 -0
- package/cjs/job.js +616 -0
- package/cjs/job.js.map +1 -0
- package/cjs/log-channel.d.ts +2 -2
- package/cjs/logger.d.ts +1 -1
- package/cjs/scheduler.d.ts +182 -0
- package/cjs/scheduler.d.ts.map +1 -0
- package/cjs/scheduler.js +316 -0
- package/cjs/scheduler.js.map +1 -0
- package/cjs/types.d.ts +58 -89
- package/cjs/types.d.ts.map +1 -1
- package/cjs/utils.d.ts +3 -0
- package/cjs/utils.d.ts.map +1 -0
- package/esm/cron-parser.d.ts +98 -0
- package/esm/cron-parser.d.ts.map +1 -0
- package/esm/cron-parser.js +193 -0
- package/esm/cron-parser.js.map +1 -0
- package/esm/index.d.ts +43 -5
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/job.d.ts +332 -0
- package/esm/job.d.ts.map +1 -0
- package/esm/job.js +616 -0
- package/esm/job.js.map +1 -0
- package/esm/log-channel.d.ts +2 -2
- package/esm/logger.d.ts +1 -1
- package/esm/scheduler.d.ts +182 -0
- package/esm/scheduler.d.ts.map +1 -0
- package/esm/scheduler.js +316 -0
- package/esm/scheduler.js.map +1 -0
- package/esm/types.d.ts +58 -89
- package/esm/types.d.ts.map +1 -1
- package/esm/utils.d.ts +3 -0
- package/esm/utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/cjs/channels/console-log.js +0 -47
- package/cjs/channels/console-log.js.map +0 -1
- package/cjs/channels/file-log.js +0 -272
- package/cjs/channels/file-log.js.map +0 -1
- package/cjs/channels/json-file-log.js +0 -102
- package/cjs/channels/json-file-log.js.map +0 -1
- package/cjs/log-channel.js +0 -88
- package/cjs/log-channel.js.map +0 -1
- package/cjs/logger.js +0 -112
- package/cjs/logger.js.map +0 -1
- package/cjs/utils/capture-unhandled-errors.js +0 -12
- package/cjs/utils/capture-unhandled-errors.js.map +0 -1
- package/cjs/utils/clear-message.js +0 -9
- package/cjs/utils/clear-message.js.map +0 -1
- package/esm/channels/console-log.js +0 -47
- package/esm/channels/console-log.js.map +0 -1
- package/esm/channels/file-log.js +0 -272
- package/esm/channels/file-log.js.map +0 -1
- package/esm/channels/json-file-log.js +0 -102
- package/esm/channels/json-file-log.js.map +0 -1
- package/esm/log-channel.js +0 -88
- package/esm/log-channel.js.map +0 -1
- package/esm/logger.js +0 -112
- package/esm/logger.js.map +0 -1
- package/esm/utils/capture-unhandled-errors.js +0 -12
- package/esm/utils/capture-unhandled-errors.js.map +0 -1
- package/esm/utils/clear-message.js +0 -9
- package/esm/utils/clear-message.js.map +0 -1
package/esm/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,UAU1C"}
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict';var copper=require('@mongez/copper'),logChannel=require('../log-channel.js');class ConsoleLog extends logChannel.LogChannel {
|
|
2
|
-
/**
|
|
3
|
-
* {@inheritdoc}
|
|
4
|
-
*/
|
|
5
|
-
name = "console";
|
|
6
|
-
/**
|
|
7
|
-
* Determine if channel is logging in terminal
|
|
8
|
-
*/
|
|
9
|
-
terminal = true;
|
|
10
|
-
/**
|
|
11
|
-
* {@inheritdoc}
|
|
12
|
-
*/
|
|
13
|
-
log(data) {
|
|
14
|
-
const { module, action, message, type: level } = data;
|
|
15
|
-
if (!this.shouldBeLogged(data))
|
|
16
|
-
return;
|
|
17
|
-
// display date and time with milliseconds
|
|
18
|
-
const date = new Date().toISOString(); // i.e 2021-01-01T00:00:00.000Z
|
|
19
|
-
switch (level) {
|
|
20
|
-
case "debug":
|
|
21
|
-
// add a debug icon
|
|
22
|
-
console.log(copper.colors.magentaBright("⚙"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.magentaBright(message));
|
|
23
|
-
break;
|
|
24
|
-
case "info":
|
|
25
|
-
// add an info icon
|
|
26
|
-
console.log(copper.colors.blueBright("ℹ"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.blueBright(message));
|
|
27
|
-
break;
|
|
28
|
-
case "warn":
|
|
29
|
-
// add a warning icon
|
|
30
|
-
console.log(copper.colors.yellow("⚠"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.yellowBright(message));
|
|
31
|
-
break;
|
|
32
|
-
case "error":
|
|
33
|
-
// add an error icon
|
|
34
|
-
console.log(copper.colors.red("✗"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.redBright(message));
|
|
35
|
-
break;
|
|
36
|
-
case "success":
|
|
37
|
-
// add a success icon
|
|
38
|
-
console.log(copper.colors.green("✓"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.greenBright(message));
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
console.log("[log]", copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), message);
|
|
42
|
-
}
|
|
43
|
-
if (typeof message === "object") {
|
|
44
|
-
console.log(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}exports.ConsoleLog=ConsoleLog;//# sourceMappingURL=console-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console-log.js","sources":["../../src/channels/console-log.ts"],"sourcesContent":[null],"names":["LogChannel","colors"],"mappings":"0FAIM,MAAO,UAAW,SAAQA,qBAAkC,CAAA;AAChE;;AAEG;IACI,IAAI,GAAG,SAAS,CAAC;AAExB;;AAEG;IACI,QAAQ,GAAG,IAAI,CAAC;AAEvB;;AAEG;AACI,IAAA,GAAG,CAAC,IAAiB,EAAA;AAC1B,QAAA,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEtD,QAAA,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO;;QAGvC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACtC,QAAA,QAAQ,KAAK;AACX,YAAA,KAAK,OAAO;;gBAEV,OAAO,CAAC,GAAG,CACTC,aAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EACzBA,aAAM,CAAC,MAAM,CAAC,CAAI,CAAA,EAAA,IAAI,GAAG,CAAC,EAC1BA,aAAM,CAAC,IAAI,CAAC,CAAI,CAAA,EAAA,MAAM,GAAG,CAAC,EAC1BA,aAAM,CAAC,OAAO,CAAC,CAAI,CAAA,EAAA,MAAM,GAAG,CAAC,EAC7BA,aAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAC9B,CAAC;gBACF,MAAM;AACR,YAAA,KAAK,MAAM;;gBAET,OAAO,CAAC,GAAG,CACTA,aAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EACtBA,aAAM,CAAC,MAAM,CAAC,CAAI,CAAA,EAAA,IAAI,GAAG,CAAC,EAC1BA,aAAM,CAAC,IAAI,CAAC,CAAI,CAAA,EAAA,MAAM,GAAG,CAAC,EAC1BA,aAAM,CAAC,OAAO,CA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O,CAAC,GAAG,CACT,OAAO,EACPA,aAAM,CAAC,MAAM,CAAC,IAAI,IAAI,CAAA,CAAA,CAAG,CAAC,EAC1BA,aAAM,CAAC,IAAI,CAAC,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,CAAG,CAAC,EAC1BA,aAAM,CAAC,OAAO,CAAC,CAAA,CAAA,EAAI,MAAM,CAAG,CAAA,CAAA,CAAC,EAC7B,OAAO,CACR,CAAC;AACL,SAAA;AAED,QAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,YAAA,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtB,SAAA;KACF;AACF"}
|
package/cjs/channels/file-log.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
'use strict';var fs$1=require('@mongez/fs'),dayjs=require('dayjs'),fs=require('fs'),os=require('os'),path=require('path'),logChannel=require('../log-channel.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dayjs__default=/*#__PURE__*/_interopDefault(dayjs);var fs__default=/*#__PURE__*/_interopDefault(fs);var path__default=/*#__PURE__*/_interopDefault(path);class FileLog extends logChannel.LogChannel {
|
|
2
|
-
/**
|
|
3
|
-
* {@inheritdoc}
|
|
4
|
-
*/
|
|
5
|
-
name = "file";
|
|
6
|
-
/**
|
|
7
|
-
* Messages buffer
|
|
8
|
-
*/
|
|
9
|
-
messages = [];
|
|
10
|
-
/**
|
|
11
|
-
* Grouped messages
|
|
12
|
-
*/
|
|
13
|
-
groupedMessages = {};
|
|
14
|
-
/**
|
|
15
|
-
* Default channel configurations
|
|
16
|
-
*/
|
|
17
|
-
defaultConfigurations = {
|
|
18
|
-
storagePath: process.cwd() + "/storage/logs",
|
|
19
|
-
rotate: true,
|
|
20
|
-
name: "app",
|
|
21
|
-
extension: "log",
|
|
22
|
-
chunk: "single",
|
|
23
|
-
maxMessagesToWrite: 100,
|
|
24
|
-
filter: () => true,
|
|
25
|
-
maxFileSize: 10 * 1024 * 1024,
|
|
26
|
-
get rotateFileName() {
|
|
27
|
-
return dayjs__default.default().format("DD-MM-YYYY");
|
|
28
|
-
},
|
|
29
|
-
dateFormat: {
|
|
30
|
-
date: "DD-MM-YYYY",
|
|
31
|
-
time: "HH:mm:ss",
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Last write time
|
|
36
|
-
*/
|
|
37
|
-
lastWriteTime = Date.now();
|
|
38
|
-
/**
|
|
39
|
-
* A flag to determine if the file is being written
|
|
40
|
-
*/
|
|
41
|
-
isWriting = false;
|
|
42
|
-
/**
|
|
43
|
-
* Check file size for file rotation
|
|
44
|
-
*/
|
|
45
|
-
async checkAndRotateFile(filePath = this.filePath) {
|
|
46
|
-
if (!this.config("rotate"))
|
|
47
|
-
return;
|
|
48
|
-
try {
|
|
49
|
-
const stats = await fs__default.default.promises.stat(filePath);
|
|
50
|
-
if (stats.size >= this.config("maxFileSize")) {
|
|
51
|
-
await this.rotateLogFile();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (error.code === "ENOENT") {
|
|
56
|
-
// File doesn't exist, this can be normal if it's a new file
|
|
57
|
-
console.log("Log file does not exist, will be created on first write.");
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
console.error("Error checking log file:", error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Rotate log file
|
|
66
|
-
*/
|
|
67
|
-
async rotateLogFile() {
|
|
68
|
-
const fileName = `${this.fileName}-${this.config("rotateFileName")}-${Date.now()}`;
|
|
69
|
-
const extension = this.extension;
|
|
70
|
-
const rotatedFilePath = path__default.default.join(this.storagePath, `${fileName}.${extension}`);
|
|
71
|
-
await fs__default.default.promises.rename(this.filePath, rotatedFilePath).catch(error => {
|
|
72
|
-
console.error("Error rotating file:", error);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Flush messages
|
|
77
|
-
*/
|
|
78
|
-
initMessageFlush() {
|
|
79
|
-
setInterval(() => {
|
|
80
|
-
if (this.messages.length > 0 &&
|
|
81
|
-
(this.messages.length >= this.maxMessagesToWrite ||
|
|
82
|
-
Date.now() - this.lastWriteTime > 5000)) {
|
|
83
|
-
this.writeMessagesToFile();
|
|
84
|
-
}
|
|
85
|
-
}, 5000); // Periodic check
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get file path
|
|
89
|
-
*/
|
|
90
|
-
get filePath() {
|
|
91
|
-
const fileName = this.fileName;
|
|
92
|
-
const extension = this.extension;
|
|
93
|
-
return path__default.default.join(this.storagePath, `${fileName}.${extension}`);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get max messages
|
|
97
|
-
*/
|
|
98
|
-
get maxMessagesToWrite() {
|
|
99
|
-
return this.config("maxMessagesToWrite");
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Get file name
|
|
103
|
-
*/
|
|
104
|
-
get fileName() {
|
|
105
|
-
const debugLevel = this.config("chunk");
|
|
106
|
-
switch (debugLevel) {
|
|
107
|
-
case "single":
|
|
108
|
-
default:
|
|
109
|
-
return this.config("name");
|
|
110
|
-
case "daily":
|
|
111
|
-
return dayjs__default.default().format("DD-MM-YYYY");
|
|
112
|
-
case "hourly":
|
|
113
|
-
return dayjs__default.default().format("DD-MM-YYYY-HH");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Get file extension
|
|
118
|
-
*/
|
|
119
|
-
get extension() {
|
|
120
|
-
return this.config("extension");
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get content
|
|
124
|
-
*/
|
|
125
|
-
get content() {
|
|
126
|
-
return this.messages.map(message => message.content).join(os.EOL) + os.EOL;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get storage path
|
|
130
|
-
*/
|
|
131
|
-
get storagePath() {
|
|
132
|
-
return this.config("storagePath");
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* {@inheritdoc}
|
|
136
|
-
*/
|
|
137
|
-
async init() {
|
|
138
|
-
const logsDirectory = this.storagePath;
|
|
139
|
-
await fs$1.ensureDirectoryAsync(logsDirectory);
|
|
140
|
-
this.initMessageFlush();
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* {@inheritdoc}
|
|
144
|
-
*/
|
|
145
|
-
async log(data) {
|
|
146
|
-
const { module, action, message, type: level } = data;
|
|
147
|
-
if (!this.shouldBeLogged(data))
|
|
148
|
-
return;
|
|
149
|
-
const { date: dateFormat, time } = this.getDateAndTimeFormat();
|
|
150
|
-
const date = dayjs__default.default().format(dateFormat + " " + time);
|
|
151
|
-
let content = `[${date}] [${level}] [${module}][${action}]: `;
|
|
152
|
-
let stack;
|
|
153
|
-
// check if message is an instance of Error
|
|
154
|
-
if (message instanceof Error) {
|
|
155
|
-
// in that case we need to store the error message and stack trace
|
|
156
|
-
content += message.message + os.EOL;
|
|
157
|
-
content += `[trace]` + os.EOL;
|
|
158
|
-
content += message.stack;
|
|
159
|
-
stack = message.stack;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
content += message;
|
|
163
|
-
}
|
|
164
|
-
this.messages.push({
|
|
165
|
-
content,
|
|
166
|
-
level,
|
|
167
|
-
date,
|
|
168
|
-
module,
|
|
169
|
-
action,
|
|
170
|
-
stack,
|
|
171
|
-
});
|
|
172
|
-
await this.checkIfMessagesShouldBeWritten(); // Immediate check on buffer size
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Check if messages should be written
|
|
176
|
-
*/
|
|
177
|
-
async checkIfMessagesShouldBeWritten() {
|
|
178
|
-
if (this.messages.length >= this.maxMessagesToWrite ||
|
|
179
|
-
Date.now() - this.lastWriteTime > 5000) {
|
|
180
|
-
await this.writeMessagesToFile();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Should be called after messages are saved
|
|
185
|
-
*/
|
|
186
|
-
onSave() {
|
|
187
|
-
this.messages = [];
|
|
188
|
-
this.groupedMessages = {};
|
|
189
|
-
this.isWriting = false;
|
|
190
|
-
this.lastWriteTime = Date.now();
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Check if messages should be grouped
|
|
194
|
-
*/
|
|
195
|
-
get messagedShouldBeGrouped() {
|
|
196
|
-
return Number(this.config("groupBy")?.length) > 0;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Write messages to the file
|
|
200
|
-
*/
|
|
201
|
-
async writeMessagesToFile() {
|
|
202
|
-
if (this.messages.length === 0 || this.isWriting || !this.isInitialized)
|
|
203
|
-
return;
|
|
204
|
-
this.isWriting = true;
|
|
205
|
-
if (this.messagedShouldBeGrouped) {
|
|
206
|
-
return await this.writeGroupedMessagesToFile();
|
|
207
|
-
}
|
|
208
|
-
await this.checkAndRotateFile(); // Ensure we check file size before writing
|
|
209
|
-
try {
|
|
210
|
-
await this.write(this.filePath, this.content);
|
|
211
|
-
this.onSave();
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
console.error("Failed to write log:", error);
|
|
215
|
-
// Implement fallback logic here
|
|
216
|
-
this.isWriting = false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Write grouped messages to the file
|
|
221
|
-
*/
|
|
222
|
-
async writeGroupedMessagesToFile() {
|
|
223
|
-
// first step, is to group the messages
|
|
224
|
-
this.prepareGroupedMessages();
|
|
225
|
-
// now each key in the grouped messages, represents the directory path that should extend the storage path
|
|
226
|
-
for (const key in this.groupedMessages) {
|
|
227
|
-
const directoryPath = path__default.default.join(this.storagePath, key);
|
|
228
|
-
await fs$1.ensureDirectoryAsync(directoryPath);
|
|
229
|
-
const filePath = path__default.default.join(directoryPath, `${this.fileName}.${this.extension}`);
|
|
230
|
-
await this.checkAndRotateFile(filePath); // Ensure we check file size before writing
|
|
231
|
-
const content = this.groupedMessages[key].map(message => message.content).join(os.EOL) +
|
|
232
|
-
os.EOL;
|
|
233
|
-
try {
|
|
234
|
-
await this.write(filePath, content);
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
console.error("Failed to write log:", error);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
this.onSave();
|
|
241
|
-
this.isWriting = false;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Prepare grouped messages
|
|
245
|
-
*/
|
|
246
|
-
prepareGroupedMessages() {
|
|
247
|
-
this.messages.forEach(message => {
|
|
248
|
-
const key = this.config("groupBy")
|
|
249
|
-
.map(groupKey => encodeURIComponent(message[groupKey]))
|
|
250
|
-
.join("/");
|
|
251
|
-
this.groupedMessages[key] = this.groupedMessages[key] || [];
|
|
252
|
-
this.groupedMessages[key].push(message);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Start writing to the file
|
|
257
|
-
*/
|
|
258
|
-
async write(filePath, content) {
|
|
259
|
-
return new Promise((resolve, reject) => {
|
|
260
|
-
const writer = fs__default.default.createWriteStream(filePath, { flags: "a" });
|
|
261
|
-
writer.write(content, error => {
|
|
262
|
-
writer.end();
|
|
263
|
-
if (error) {
|
|
264
|
-
reject(error);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
resolve(true);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}exports.FileLog=FileLog;//# sourceMappingURL=file-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-log.js","sources":["../../src/channels/file-log.ts"],"sourcesContent":[null],"names":["LogChannel","dayjs","fs","path","EOL","ensureDirectoryAsync"],"mappings":"gYAmFM,MAAO,OAAQ,SAAQA,qBAAyB,CAAA;AACpD;;AAEG;IACI,IAAI,GAAG,MAAM,CAAC;AAErB;;AAEG;IACO,QAAQ,GAAiB,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AAA,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAE;AAChC,iBAAA,GAAG,CAAC,QAAQ,IAAI,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;iBACtD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEb,YAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YAC5D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1C,SAAC,CAAC,CAAC;KACJ;AAED;;AAEG;AACO,IAAA,MAAM,KAAK,CAAC,QAAgB,EAAE,OAAe,EAAA;QACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACrC,YAAA,MAAM,MAAM,GAAGF,mBAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AAE9D,YAAA,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,IAAG;gBAC5B,MAAM,CAAC,GAAG,EAAE,CAAC;AACb,gBAAA,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,KAAK,CAAC,CAAC;AACf,iBAAA;AAAM,qBAAA;oBACL,OAAO,CAAC,IAAI,CAAC,CAAC;AACf,iBAAA;AACH,aAAC,CAAC,CAAC;AACL,SAAC,CAAC,CAAC;KACJ;AACF"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';var fs=require('@mongez/fs'),dayjs=require('dayjs'),path=require('path'),fileLog=require('./file-log.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dayjs__default=/*#__PURE__*/_interopDefault(dayjs);var path__default=/*#__PURE__*/_interopDefault(path);class JSONFileLog extends fileLog.FileLog {
|
|
2
|
-
/**
|
|
3
|
-
* {@inheritdoc}
|
|
4
|
-
*/
|
|
5
|
-
name = "fileJson";
|
|
6
|
-
/**
|
|
7
|
-
* Get file extension
|
|
8
|
-
*/
|
|
9
|
-
get extension() {
|
|
10
|
-
return "json";
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get initial file contents
|
|
14
|
-
*/
|
|
15
|
-
get initialFileContents() {
|
|
16
|
-
return {
|
|
17
|
-
messages: this.messages,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* {@inheritdoc}
|
|
22
|
-
*/
|
|
23
|
-
async log(data) {
|
|
24
|
-
let stack;
|
|
25
|
-
if (data.message instanceof Error) {
|
|
26
|
-
stack = data.message.stack?.split("\n");
|
|
27
|
-
data.message = data.message.message;
|
|
28
|
-
}
|
|
29
|
-
const { module, action, message, type: level } = data;
|
|
30
|
-
if (!this.shouldBeLogged(data))
|
|
31
|
-
return;
|
|
32
|
-
const { date: dateFormat, time } = this.getDateAndTimeFormat();
|
|
33
|
-
const date = dayjs__default.default().format(dateFormat + " " + time);
|
|
34
|
-
this.messages.push({
|
|
35
|
-
content: message,
|
|
36
|
-
level,
|
|
37
|
-
date,
|
|
38
|
-
module,
|
|
39
|
-
action,
|
|
40
|
-
stack,
|
|
41
|
-
});
|
|
42
|
-
await this.checkIfMessagesShouldBeWritten(); // Immediate check on buffer size
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Write messages to the file
|
|
46
|
-
*/
|
|
47
|
-
async writeMessagesToFile() {
|
|
48
|
-
if (this.messages.length === 0 || this.isWriting)
|
|
49
|
-
return;
|
|
50
|
-
this.isWriting = true;
|
|
51
|
-
if (this.messagedShouldBeGrouped) {
|
|
52
|
-
return await this.writeGroupedMessagesToFile();
|
|
53
|
-
}
|
|
54
|
-
await this.checkAndRotateFile(); // Ensure file rotation is handled
|
|
55
|
-
let fileContents;
|
|
56
|
-
if (await fs.fileExistsAsync(this.filePath)) {
|
|
57
|
-
try {
|
|
58
|
-
fileContents = await fs.getJsonFileAsync(this.filePath);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("Error reading log file, reinitializing:", error);
|
|
62
|
-
fileContents = { messages: [] }; // Reinitialize the file if corrupted
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
fileContents = { messages: [] }; // Reinitialize the file if corrupted
|
|
67
|
-
}
|
|
68
|
-
fileContents.messages.push(...this.messages);
|
|
69
|
-
try {
|
|
70
|
-
await fs.putJsonFileAsync(this.filePath, fileContents, { spaces: 2 });
|
|
71
|
-
this.onSave();
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error("Failed to write log:", error);
|
|
75
|
-
// Implement fallback logic here
|
|
76
|
-
this.isWriting = false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Write grouped messages to the file
|
|
81
|
-
*/
|
|
82
|
-
async writeGroupedMessagesToFile() {
|
|
83
|
-
// first step, is to group the messages
|
|
84
|
-
this.prepareGroupedMessages();
|
|
85
|
-
// now each key in the grouped messages, represents the directory path that should extend the storage path
|
|
86
|
-
for (const key in this.groupedMessages) {
|
|
87
|
-
const directoryPath = path__default.default.join(this.storagePath, key);
|
|
88
|
-
await fs.ensureDirectoryAsync(directoryPath);
|
|
89
|
-
const filePath = path__default.default.join(directoryPath, `${this.fileName}.${this.extension}`);
|
|
90
|
-
await this.checkAndRotateFile(filePath); // Ensure we check file size before writing
|
|
91
|
-
const content = this.groupedMessages[key];
|
|
92
|
-
try {
|
|
93
|
-
await fs.putJsonFileAsync(filePath, content, { spaces: 2 });
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error("Failed to write log:", error);
|
|
97
|
-
this.isWriting = false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
this.onSave();
|
|
101
|
-
}
|
|
102
|
-
}exports.JSONFileLog=JSONFileLog;//# sourceMappingURL=json-file-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-file-log.js","sources":["../../src/channels/json-file-log.ts"],"sourcesContent":[null],"names":["FileLog","dayjs","fileExistsAsync","getJsonFileAsync","putJsonFileAsync","path","ensureDirectoryAsync"],"mappings":"oSAWM,MAAO,WAAY,SAAQA,eAAO,CAAA;AACtC;;AAEG;IACI,IAAI,GAAG,UAAU,CAAC;AAEzB;;AAEG;AACH,IAAA,IAAW,SAAS,GAAA;AAClB,QAAA,OAAO,MAAM,CAAC;KACf;AAED;;AAEG;AACH,IAAA,IAAc,mBAAmB,GAAA;QAC/B,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;KACH;AAED;;AAEG;IACI,MAAM,GAAG,CAAC,IAAiB,EAAA;AAChC,QAAA,IAAI,KAA2B,CAAC;AAEhC,QAAA,IAAI,IAAI,CAAC,OAAO,YAAY,KAAK,EAAE;YACjC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;AACrC,SAAA;AAED,QAAA,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEtD,QAAA,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO;AAEvC,QAAA,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;AAE/D,QAAA,MAAM,IAAI,GAAGC,sBAAK,EAAE,CAAC,MAAM,CAAC,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;AAErD,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;AACjB,YAAA,OAAO,EAAE,OAAO;YAChB,KAAK;YACL,IAAI;YACJ,MAAM;YACN,MAAM;YACN,K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* Determine if channel is logging in terminal
|
|
12
|
-
*/
|
|
13
|
-
terminal = false;
|
|
14
|
-
/**
|
|
15
|
-
* Default Configurations
|
|
16
|
-
*/
|
|
17
|
-
defaultConfigurations = {};
|
|
18
|
-
/**
|
|
19
|
-
* Channel configurations
|
|
20
|
-
*/
|
|
21
|
-
channelConfigurations = {}; //
|
|
22
|
-
/**
|
|
23
|
-
* Determine whether the channel is fully initialized
|
|
24
|
-
*/
|
|
25
|
-
isInitialized = false;
|
|
26
|
-
/**
|
|
27
|
-
* Constructor
|
|
28
|
-
*/
|
|
29
|
-
constructor(configurations) {
|
|
30
|
-
if (configurations) {
|
|
31
|
-
this.setConfigurations(configurations);
|
|
32
|
-
}
|
|
33
|
-
setTimeout(async () => {
|
|
34
|
-
if (this.init) {
|
|
35
|
-
await this.init();
|
|
36
|
-
}
|
|
37
|
-
this.isInitialized = true;
|
|
38
|
-
}, 0);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get config value
|
|
42
|
-
*/
|
|
43
|
-
config(key) {
|
|
44
|
-
return (this.channelConfigurations[key] ?? (this.defaultConfigurations ?? {})[key]);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Set configurations
|
|
48
|
-
*/
|
|
49
|
-
setConfigurations(configurations) {
|
|
50
|
-
this.channelConfigurations = {
|
|
51
|
-
...this.channelConfigurations,
|
|
52
|
-
...configurations,
|
|
53
|
-
};
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Determine if the message should be logged
|
|
58
|
-
*/
|
|
59
|
-
shouldBeLogged(data) {
|
|
60
|
-
// check for debug mode
|
|
61
|
-
const allowedLevels = this.config("levels");
|
|
62
|
-
if (allowedLevels?.length && !allowedLevels.includes(data.type))
|
|
63
|
-
return false;
|
|
64
|
-
const filter = this.config("filter");
|
|
65
|
-
if (filter) {
|
|
66
|
-
return filter(data);
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get date and time formats
|
|
72
|
-
*/
|
|
73
|
-
getDateAndTimeFormat() {
|
|
74
|
-
const dateFormat = this.config("dateFormat");
|
|
75
|
-
const date = dateFormat?.date ?? "DD-MM-YYYY";
|
|
76
|
-
const time = dateFormat?.time ?? "HH:mm:ss";
|
|
77
|
-
return { date, time };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* get basic configurations with the given ones
|
|
81
|
-
*/
|
|
82
|
-
withBasicConfigurations(configurations) {
|
|
83
|
-
return {
|
|
84
|
-
filter: () => true,
|
|
85
|
-
...configurations,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}exports.LogChannel=LogChannel;//# sourceMappingURL=log-channel.js.map
|
package/cjs/log-channel.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-channel.js","sources":["../src/log-channel.ts"],"sourcesContent":[null],"names":[],"mappings":"mBAEsB,UAAU,CAAA;AAI9B;;AAEG;AACI,IAAA,IAAI,CAAU;AAErB;;AAEG;AACI,IAAA,WAAW,CAAU;AAE5B;;AAEG;IACI,QAAQ,GAAG,KAAK,CAAC;AAExB;;AAEG;IACO,qBAAqB,GAAY,EAAa,CAAC;AAEzD;;AAEG;AACO,IAAA,qBAAqB,GAAY,EAAa,CAAC;AAEzD;;AAEG;IACO,aAAa,GAAG,KAAK,CAAC;AAEhC;;AAEG;AACH,IAAA,WAAA,CAAmB,cAAwB,EAAA;AACzC,QAAA,IAAI,cAAc,EAAE;AAClB,YAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;AACxC,SAAA;QAED,UAAU,CAAC,YAAW;YACpB,IAAI,IAAI,CAAC,IAAI,EAAE;AACb,gBAAA,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;AACnB,aAAA;AAED,YAAA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;SAC3B,EAAE,CAAC,CAAC,CAAC;KACP;AAOD;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B;AACF"}
|
package/cjs/logger.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';var reinforcements=require('@mongez/reinforcements'),clearMessage=require('./utils/clear-message.js');class Logger {
|
|
2
|
-
/**
|
|
3
|
-
* Current channel
|
|
4
|
-
*/
|
|
5
|
-
channels = [];
|
|
6
|
-
id = "logger-" + reinforcements.Random.string(32);
|
|
7
|
-
/**
|
|
8
|
-
* Add a new channel
|
|
9
|
-
*/
|
|
10
|
-
addChannel(channel) {
|
|
11
|
-
this.channels.push(channel);
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Set base configurations
|
|
16
|
-
*/
|
|
17
|
-
configure(config) {
|
|
18
|
-
this.channels = config.channels;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Set channels
|
|
23
|
-
*/
|
|
24
|
-
setChannels(channels) {
|
|
25
|
-
this.channels = channels;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Normalize log data to a single object
|
|
30
|
-
*/
|
|
31
|
-
normalizeLogData(dataOrModule, action, message = "", level) {
|
|
32
|
-
if (typeof dataOrModule === "object") {
|
|
33
|
-
// If level is provided, override type
|
|
34
|
-
return {
|
|
35
|
-
type: (level || dataOrModule.type || "info"),
|
|
36
|
-
module: dataOrModule.module,
|
|
37
|
-
action: dataOrModule.action,
|
|
38
|
-
message: dataOrModule.message,
|
|
39
|
-
...(dataOrModule.context ? { context: dataOrModule.context } : {}),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
type: (level || "info"),
|
|
44
|
-
module: dataOrModule,
|
|
45
|
-
action: action,
|
|
46
|
-
message,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Make log
|
|
51
|
-
*/
|
|
52
|
-
async log(data) {
|
|
53
|
-
for (const channel of this.channels) {
|
|
54
|
-
if (channel.terminal === false) {
|
|
55
|
-
data.message = clearMessage.clearMessage(data.message);
|
|
56
|
-
}
|
|
57
|
-
channel.log(data);
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Make debug log
|
|
63
|
-
*/
|
|
64
|
-
debug(dataOrModule, action, message = "") {
|
|
65
|
-
const data = this.normalizeLogData(dataOrModule, action, message, "debug");
|
|
66
|
-
return this.log(data);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Make info log
|
|
70
|
-
*/
|
|
71
|
-
info(dataOrModule, action, message = "") {
|
|
72
|
-
const data = this.normalizeLogData(dataOrModule, action, message, "info");
|
|
73
|
-
return this.log(data);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Make warn log
|
|
77
|
-
*/
|
|
78
|
-
warn(dataOrModule, action, message = "") {
|
|
79
|
-
const data = this.normalizeLogData(dataOrModule, action, message, "warn");
|
|
80
|
-
return this.log(data);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Make error log
|
|
84
|
-
*/
|
|
85
|
-
error(dataOrModule, action, message = "") {
|
|
86
|
-
const data = this.normalizeLogData(dataOrModule, action, message, "error");
|
|
87
|
-
return this.log(data);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Make success log
|
|
91
|
-
*/
|
|
92
|
-
success(dataOrModule, action, message = "") {
|
|
93
|
-
const data = this.normalizeLogData(dataOrModule, action, message, "success");
|
|
94
|
-
return this.log(data);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Get channel by name
|
|
98
|
-
*/
|
|
99
|
-
channel(name) {
|
|
100
|
-
return this.channels.find(channel => channel.name === name);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const logger = new Logger();
|
|
104
|
-
const log = (data) => {
|
|
105
|
-
return logger.log(data);
|
|
106
|
-
};
|
|
107
|
-
log.info = logger.info.bind(logger);
|
|
108
|
-
log.debug = logger.debug.bind(logger);
|
|
109
|
-
log.warn = logger.warn.bind(logger);
|
|
110
|
-
log.error = logger.error.bind(logger);
|
|
111
|
-
log.success = logger.success.bind(logger);
|
|
112
|
-
log.channel = logger.channel.bind(logger);exports.Logger=Logger;exports.log=log;exports.logger=logger;//# sourceMappingURL=logger.js.map
|