@rabbit-company/logger 5.5.0 → 5.6.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.
Files changed (2) hide show
  1. package/module/logger.js +48 -7
  2. package/package.json +3 -3
package/module/logger.js CHANGED
@@ -129,6 +129,40 @@ class Logger {
129
129
  return this.level >= level;
130
130
  }
131
131
  createLogEntry(message, level, metadata) {
132
+ if (metadata instanceof Error) {
133
+ return {
134
+ message,
135
+ level,
136
+ timestamp: Date.now(),
137
+ metadata: {
138
+ error: {
139
+ name: metadata.name,
140
+ message: metadata.message,
141
+ stack: metadata.stack
142
+ }
143
+ }
144
+ };
145
+ }
146
+ if (metadata && typeof metadata === "object") {
147
+ const processedMetadata = {};
148
+ for (const [key, value] of Object.entries(metadata)) {
149
+ if (value instanceof Error) {
150
+ processedMetadata[key] = {
151
+ name: value.name,
152
+ message: value.message,
153
+ stack: value.stack
154
+ };
155
+ } else {
156
+ processedMetadata[key] = value;
157
+ }
158
+ }
159
+ return {
160
+ message,
161
+ level,
162
+ timestamp: Date.now(),
163
+ metadata: processedMetadata
164
+ };
165
+ }
132
166
  return {
133
167
  message,
134
168
  level,
@@ -277,19 +311,26 @@ class LokiTransport {
277
311
  scheduleSend(immediate = false) {
278
312
  if (this.isSending)
279
313
  return;
280
- if (this.timeoutHandle) {
281
- clearTimeout(this.timeoutHandle);
282
- this.timeoutHandle = undefined;
283
- }
284
- if (this.queue.length > 0 && (immediate || this.queue.length >= this.batchSize)) {
314
+ if (immediate || this.queue.length >= this.batchSize) {
315
+ if (this.timeoutHandle) {
316
+ clearTimeout(this.timeoutHandle);
317
+ this.timeoutHandle = undefined;
318
+ }
285
319
  this.sendBatch();
286
- } else if (this.queue.length > 0) {
287
- this.timeoutHandle = setTimeout(() => this.sendBatch(), this.batchTimeout);
320
+ } else if (this.queue.length > 0 && !this.timeoutHandle) {
321
+ this.timeoutHandle = setTimeout(() => {
322
+ this.timeoutHandle = undefined;
323
+ this.sendBatch();
324
+ }, this.batchTimeout);
288
325
  }
289
326
  }
290
327
  async sendBatch() {
291
328
  if (this.queue.length === 0 || this.isSending)
292
329
  return;
330
+ if (this.timeoutHandle) {
331
+ clearTimeout(this.timeoutHandle);
332
+ this.timeoutHandle = undefined;
333
+ }
293
334
  this.isSending = true;
294
335
  const batchToSend = this.queue.slice(0, this.batchSize);
295
336
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabbit-company/logger",
3
- "version": "5.5.0",
3
+ "version": "5.6.1",
4
4
  "description": "A simple and lightweight logger",
5
5
  "main": "./module/logger.js",
6
6
  "type": "module",
@@ -36,9 +36,9 @@
36
36
  ],
37
37
  "devDependencies": {
38
38
  "@types/bun": "latest",
39
- "bun-plugin-dts": "^0.3.0"
39
+ "bun-plugin-dts": "^0.4.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "typescript": "^5.5.4"
42
+ "typescript": "^5.9.3"
43
43
  }
44
44
  }