Skip to content

Commit 4077c26

Browse files
authored
reduce some logging for prod release (#2440)
1 parent 38163e7 commit 4077c26

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: 2
2+
13
linters:
24
disable:
35
- unused

pkg/aiusechat/openai/openai-backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/launchdarkly/eventsource"
2020
"github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore"
2121
"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
22+
"github.com/wavetermdev/waveterm/pkg/util/logutil"
2223
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
2324
"github.com/wavetermdev/waveterm/pkg/wcore"
2425
"github.com/wavetermdev/waveterm/pkg/web/sse"
@@ -503,7 +504,7 @@ func parseOpenAIHTTPError(resp *http.Response) error {
503504
return fmt.Errorf("openai %s: failed to read error response: %v", resp.Status, err)
504505
}
505506

506-
log.Printf("full error: %s\n", body)
507+
logutil.DevPrintf("openai full error: %s\n", body)
507508

508509
// Try to parse as OpenAI error format first
509510
var errorResp openAIErrorResponse
@@ -836,8 +837,7 @@ func handleOpenAIEvent(
836837
return nil, nil
837838

838839
default:
839-
// log unknown events for debugging
840-
log.Printf("OpenAI: unknown event: %s, data: %s", eventName, data)
840+
logutil.DevPrintf("OpenAI: unknown event: %s, data: %s", eventName, data)
841841
return nil, nil
842842
}
843843
}

pkg/aiusechat/openai/openai-convertmessage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/google/uuid"
1919
"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
2020
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
21+
"github.com/wavetermdev/waveterm/pkg/wavebase"
2122
)
2223

2324
const (
@@ -129,6 +130,9 @@ func ConvertToolDefinitionToOpenAI(tool uctypes.ToolDefinition) OpenAIRequestToo
129130
}
130131

131132
func debugPrintReq(req *OpenAIRequest, endpoint string) {
133+
if !wavebase.IsDevMode() {
134+
return
135+
}
132136
var toolNames []string
133137
for _, tool := range req.Tools {
134138
toolNames = append(toolNames, tool.Name)

pkg/aiusechat/usechat.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/wavetermdev/waveterm/pkg/telemetry"
2323
"github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata"
2424
"github.com/wavetermdev/waveterm/pkg/util/ds"
25+
"github.com/wavetermdev/waveterm/pkg/util/logutil"
2526
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
2627
"github.com/wavetermdev/waveterm/pkg/waveobj"
2728
"github.com/wavetermdev/waveterm/pkg/web/sse"
@@ -143,7 +144,6 @@ func shouldUsePremium() bool {
143144
}
144145

145146
func updateRateLimit(info *uctypes.RateLimitInfo) {
146-
log.Printf("updateRateLimit: %#v\n", info)
147147
if info == nil {
148148
return
149149
}
@@ -234,7 +234,7 @@ func processToolCall(toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpt
234234
}
235235

236236
inputJSON, _ := json.Marshal(toolCall.Input)
237-
log.Printf("TOOLUSE name=%s id=%s input=%s approval=%q\n", toolCall.Name, toolCall.ID, utilfn.TruncateString(string(inputJSON), 40), toolCall.ToolUseData.Approval)
237+
logutil.DevPrintf("TOOLUSE name=%s id=%s input=%s approval=%q\n", toolCall.Name, toolCall.ID, utilfn.TruncateString(string(inputJSON), 40), toolCall.ToolUseData.Approval)
238238

239239
if toolCall.ToolUseData.Status == uctypes.ToolUseStatusError {
240240
errorMsg := toolCall.ToolUseData.ErrorMessage
@@ -349,7 +349,6 @@ func processToolCalls(stopReason *uctypes.WaveStopReason, chatOpts uctypes.WaveC
349349
}
350350

351351
func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctypes.WaveChatOpts) (*uctypes.AIMetrics, error) {
352-
log.Printf("RunAIChat\n")
353352
if !activeChats.SetUnless(chatOpts.ChatId, true) {
354353
return nil, fmt.Errorf("chat %s is already running", chatOpts.ChatId)
355354
}
@@ -488,7 +487,6 @@ func ResolveToolCall(toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpt
488487
}
489488

490489
func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, message *uctypes.AIMessage, chatOpts uctypes.WaveChatOpts) error {
491-
log.Printf("WaveAIPostMessageWrap\n")
492490
startTime := time.Now()
493491

494492
// Convert AIMessage to Anthropic chat message
@@ -531,7 +529,7 @@ func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, me
531529
}
532530
}
533531
}
534-
log.Printf("metrics: requests=%d tools=%d premium=%d proxy=%d images=%d pdfs=%d textdocs=%d textlen=%d duration=%dms error=%v\n",
532+
log.Printf("WaveAI call metrics: requests=%d tools=%d premium=%d proxy=%d images=%d pdfs=%d textdocs=%d textlen=%d duration=%dms error=%v\n",
535533
metrics.RequestCount, metrics.ToolUseCount, metrics.PremiumReqCount, metrics.ProxyReqCount,
536534
metrics.ImageCount, metrics.PDFCount, metrics.TextDocCount, metrics.TextLen, metrics.RequestDuration, metrics.HadError)
537535

pkg/util/logutil/logutil.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2025, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package logutil
5+
6+
import (
7+
"log"
8+
9+
"github.com/wavetermdev/waveterm/pkg/wavebase"
10+
)
11+
12+
// DevPrintf logs using log.Printf only if running in dev mode
13+
func DevPrintf(format string, v ...any) {
14+
if wavebase.IsDevMode() {
15+
log.Printf(format, v...)
16+
}
17+
}

0 commit comments

Comments
 (0)