jsgar 1.2.2 → 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 +28 -11
- 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
|
/**
|
|
@@ -373,17 +390,17 @@
|
|
|
373
390
|
this.registerHeartbeatHandler((u_milliseconds) => this.log('DEBUG', `Heartbeat received ${u_milliseconds}}`));
|
|
374
391
|
this.registerLogoffHandler(() => this.log('INFO', 'Logoff received'));
|
|
375
392
|
this.registerTopicIntroductionHandler((topicId, name) =>
|
|
376
|
-
this.log('
|
|
393
|
+
this.log('DEBUG', `New server topic: ${name} (Server ID: ${topicId})`));
|
|
377
394
|
this.registerKeyIntroductionHandler((keyId, name, _class) =>
|
|
378
|
-
this.log('
|
|
395
|
+
this.log('DEBUG', `New server key: ${name} (Server ID: ${keyId})`));
|
|
379
396
|
this.registerDeleteKeyHandler((keyId) =>
|
|
380
|
-
this.log('
|
|
397
|
+
this.log('DEBUG', `Delete key: ${this.serverKeyMap.get(keyId) || 'unknown'} (Server ID: ${keyId})`));
|
|
381
398
|
this.registerSubscriptionStatusHandler((name, status) =>
|
|
382
399
|
this.log('INFO', `Subscription ${name} status: ${status}`));
|
|
383
400
|
this.registerDeleteRecordHandler((keyId, topicId) =>
|
|
384
|
-
this.log('
|
|
401
|
+
this.log('DEBUG', `Delete record: ${this.serverKeyMap.get(keyId) || 'unknown'} - ${this.serverTopicMap.get(topicId) || 'unknown'}`));
|
|
385
402
|
this.registerRecordUpdateHandler((keyId, topicId, value) =>
|
|
386
|
-
this.log('
|
|
403
|
+
this.log('DEBUG', `Record update: ${this.serverKeyMap.get(keyId) || 'unknown'} - ${this.serverTopicMap.get(topicId) || 'unknown'} = ${JSON.stringify(value)}`));
|
|
387
404
|
this.registerShutdownHandler(() => this.log('INFO', 'Shutdown received'));
|
|
388
405
|
}
|
|
389
406
|
|