Skip to content

Commit d63e288

Browse files
Conditional logs
1 parent 8bd06b9 commit d63e288

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/gateway/connection-bun.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
3535
/* Opens a connection with the server and sends the initialization commands. Will throw in case of errors. */
3636
/* eslint-disable @typescript-eslint/no-unused-vars */
3737
connectTransport(config: SQLiteCloudConfig, callback?: ErrorCallback): this {
38-
console.debug(`-> connecting ${config?.host as string}:${config?.port as number}`)
38+
this.log(`-> connecting ${config?.host as string}:${config?.port as number}`)
3939
console.assert(!this.connected, 'BunSocketTransport.connect - connection already established')
4040
this.config = config
4141

@@ -134,9 +134,7 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
134134

135135
// compose commands following SCPC protocol
136136
const formattedCommands = formatCommand(commands)
137-
if (this.config?.verbose) {
138-
console.debug(`-> ${formattedCommands}`)
139-
}
137+
this.log(`-> ${formattedCommands}`)
140138
this.socket.write(formattedCommands)
141139
this.socket.flush()
142140

@@ -168,14 +166,7 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
168166
const hasReceivedEntireCommand = this.buffer.length - this.buffer.indexOf(' ') - 1 >= commandLength ? true : false
169167

170168
if (hasReceivedEntireCommand) {
171-
if (this.config?.verbose) {
172-
let bufferString = this.buffer.toString('utf8')
173-
if (bufferString.length > 1000) {
174-
bufferString = bufferString.substring(0, 100) + '...' + bufferString.substring(bufferString.length - 40)
175-
}
176-
const elapsedMs = new Date().getTime() - this.startedOn.getTime()
177-
console.debug(`<- ${bufferString} (${elapsedMs}ms)`)
178-
}
169+
this.log(`<- ${this.buffer.toString('utf8').slice(0, 1000)} (${new Date().getTime() - this.startedOn.getTime()}ms)`)
179170

180171
// need to decompress this buffer before decoding?
181172
if (dataType === CMD_COMPRESSED) {

0 commit comments

Comments
 (0)