jsgar 1.2.3 → 1.2.4
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/dist/gar.umd.js +23 -6
- package/package.json +1 -1
package/dist/gar.umd.js
CHANGED
|
@@ -38,8 +38,10 @@
|
|
|
38
38
|
* @param {string} wsEndpoint - WebSocket endpoint (e.g., "ws://localhost:8765")
|
|
39
39
|
* @param {string} user - Client username for identification
|
|
40
40
|
* @param {number} [heartbeatInterval=4000] - Heartbeat interval in milliseconds
|
|
41
|
+
* @param {boolean} [allowSelfSignedCertificate=false] - Allow self-signed certificates
|
|
42
|
+
* @param {string} [logLevel='INFO'] - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
41
43
|
*/
|
|
42
|
-
constructor(wsEndpoint, user, heartbeatInterval = 4000, allowSelfSignedCertificate = false) {
|
|
44
|
+
constructor(wsEndpoint, user, heartbeatInterval = 4000, allowSelfSignedCertificate = false, logLevel = 'INFO') {
|
|
43
45
|
this.wsEndpoint = wsEndpoint;
|
|
44
46
|
this.websocket = null;
|
|
45
47
|
this.messageQueue = [];
|
|
@@ -70,18 +72,33 @@
|
|
|
70
72
|
this.allowSelfSignedCertificate = allowSelfSignedCertificate;
|
|
71
73
|
this.exitCode = 0;
|
|
72
74
|
|
|
75
|
+
// Initialize log levels and set logLevel
|
|
76
|
+
this.logLevels = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'];
|
|
77
|
+
this.logLevel = logLevel.toUpperCase();
|
|
78
|
+
if (!this.logLevels.includes(this.logLevel)) {
|
|
79
|
+
console.warn(`Invalid logLevel "${logLevel}" provided; defaulting to INFO`);
|
|
80
|
+
this.logLevel = 'INFO';
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
this.registerDefaultHandlers();
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
/**
|
|
77
|
-
* Log messages with a specific level.
|
|
78
|
-
* @param {string} level - Log level (DEBUG, INFO, WARNING, ERROR)
|
|
87
|
+
* Log messages with a specific level, only if the level is at or above the configured logLevel.
|
|
88
|
+
* @param {string} level - Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
79
89
|
* @param {string} message - Message to log
|
|
80
|
-
* @param
|
|
90
|
+
* @param {...any} args - Additional arguments
|
|
81
91
|
*/
|
|
82
92
|
log(level, message, ...args) {
|
|
83
|
-
const
|
|
84
|
-
|
|
93
|
+
const levelUpper = level.toUpperCase();
|
|
94
|
+
if (!this.logLevels.includes(levelUpper)) {
|
|
95
|
+
console.warn(`Invalid log level "${level}" in log call`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.logLevels.indexOf(levelUpper) >= this.logLevels.indexOf(this.logLevel)) {
|
|
99
|
+
const timestamp = new Date().toISOString();
|
|
100
|
+
console.log(`${timestamp} ${levelUpper} gar.js - ${message}`, ...args);
|
|
101
|
+
}
|
|
85
102
|
}
|
|
86
103
|
|
|
87
104
|
/**
|