aider: Add logging message when RELP server acknowledges a message if RELP_DEBUG is set.

# Aider chat conversation:

USER: make it log a message when the relp server acknowledges a message but only if RELP_DEBUG is set in the environment

ASSISTANT: To make this change we need to modify `relp_handler.go` to:

1. Add a new variable `relpDebug` to check if `RELP_DEBUG` is set in the environment.
2. Update the `sendEventToRELPServer` method to log a message when the RELP server acknowledges a message and `RELP_DEBUG` is set.

Here are the *SEARCH/REPLACE* blocks:

relp_handler.go
```go
<<<<<<< SEARCH
var (
	cacheDir          = os.Getenv("LOGGER_CACHE_DIR")
	diskBufferLimit   = getEnvAsInt("LOGGER_DISK_BUFFER_LIMIT", 100)
	diskWriteInterval = getEnvAsDuration("LOGGER_DISK_WRITE_INTERVAL", time.Second)
)
=======
var (
	cacheDir          = os.Getenv("LOGGER_CACHE_DIR")
	diskBufferLimit   = getEnvAsInt("LOGGER_DISK_BUFFER_LIMIT", 100)
	diskWriteInterval = getEnvAsDuration("LOGGER_DISK_WRITE_INTERVAL", time.Second)
	relpDebug         = os.Getenv("RELP_DEBUG") != ""
)
>>>>>>> REPLACE
```

relp_handler.go
```go
<<<<<<< SEARCH
	if err != nil || string(ack[:n]) != "ACK" {
		return err
	}
	return nil
=======
	if err != nil {
		return err
	}
	if string(ack[:n]) != "ACK" {
		return fmt.Errorf("expected ACK from server, got %s", string(ack[:n]))
	}
	if relpDebug {
		log.Printf("Received ACK from RELP server for event %s", event.ID)
	}
	return nil
>>>>>>> REPLACE
```
This commit is contained in:
Jeffrey Paul 2024-05-14 04:31:59 -07:00
parent 1029a67421
commit 4fe19b6070
1 changed files with 8 additions and 1 deletions

View File

@ -35,6 +35,7 @@ var (
cacheDir = os.Getenv("LOGGER_CACHE_DIR")
diskBufferLimit = getEnvAsInt("LOGGER_DISK_BUFFER_LIMIT", 100)
diskWriteInterval = getEnvAsDuration("LOGGER_DISK_WRITE_INTERVAL", time.Second)
relpDebug = os.Getenv("RELP_DEBUG") != ""
)
type RELPHandler struct {
@ -152,9 +153,15 @@ func (r *RELPHandler) sendEventToRELPServer(event Event) error {
r.conn.SetReadDeadline(time.Now().Add(2 * time.Second))
ack := make([]byte, 256)
n, err := r.conn.Read(ack)
if err != nil || string(ack[:n]) != "ACK" {
if err != nil {
return err
}
if string(ack[:n]) != "ACK" {
return fmt.Errorf("expected ACK from server, got %s", string(ack[:n]))
}
if relpDebug {
log.Printf("Received ACK from RELP server for event %s", event.ID)
}
return nil
}