(type: MessageSenderType, message: string)
| 239 | } |
| 240 | |
| 241 | async logMessage(type: MessageSenderType, message: string): Promise<void> { |
| 242 | if (!this.initialized || this.sessionId === undefined) { |
| 243 | console.debug( |
| 244 | 'Logger not initialized or session ID missing. Cannot log message.', |
| 245 | ); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | // The messageId used here is the instance's idea of the next ID. |
| 250 | // _updateLogFile will verify and potentially recalculate based on the file's actual state. |
| 251 | const newEntryObject: LogEntry = { |
| 252 | sessionId: this.sessionId, |
| 253 | messageId: this.messageId, // This will be recalculated in _updateLogFile |
| 254 | type, |
| 255 | message, |
| 256 | timestamp: new Date().toISOString(), |
| 257 | }; |
| 258 | |
| 259 | try { |
| 260 | const writtenEntry = await this._updateLogFile(newEntryObject); |
| 261 | if (writtenEntry) { |
| 262 | // If an entry was actually written (not a duplicate skip), |
| 263 | // then this instance can increment its idea of the next messageId for this session. |
| 264 | this.messageId = writtenEntry.messageId + 1; |
| 265 | } |
| 266 | } catch (_error) { |
| 267 | // Error already logged by _updateLogFile or _readLogFile |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | private _checkpointPath(tag: string): string { |
| 272 | if (!tag.length) { |
no test coverage detected