@icgio/icg-utils 1.8.1 → 1.8.2

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,12 +1,21 @@
1
1
  class RateLimitedLogger {
2
2
  constructor(defaultLimit = 1000) {
3
- this.defaultLimit = defaultLimit // Default time in milliseconds
4
- this.lastLogTime = 0
3
+ this.defaultLimit = defaultLimit // Shared default limit for log and error
4
+ this.lastLogTime = 0 // Tracks the last log or error time
5
5
  }
6
+
6
7
  log(message, limit = this.defaultLimit) {
8
+ this._rateLimitedOutput(console.log, message, limit)
9
+ }
10
+
11
+ error(message, limit = this.defaultLimit) {
12
+ this._rateLimitedOutput(console.error, message, limit)
13
+ }
14
+
15
+ _rateLimitedOutput(outputFunction, message, limit) {
7
16
  const now = Date.now()
8
17
  if (now - this.lastLogTime >= limit) {
9
- console.log(message)
18
+ outputFunction(message)
10
19
  this.lastLogTime = now
11
20
  }
12
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {