summaryrefslogtreecommitdiff
path: root/internal/logging
diff options
context:
space:
mode:
Diffstat (limited to 'internal/logging')
-rw-r--r--internal/logging/chatlogger.go3
-rw-r--r--internal/logging/logging.go14
-rw-r--r--internal/logging/logging_test.go72
3 files changed, 45 insertions, 44 deletions
diff --git a/internal/logging/chatlogger.go b/internal/logging/chatlogger.go
index 2f2fc99..b2d8684 100644
--- a/internal/logging/chatlogger.go
+++ b/internal/logging/chatlogger.go
@@ -14,7 +14,8 @@ func NewChatLogger(provider string) ChatLogger {
func (cl ChatLogger) LogStart(stream bool, model string, temp float64, maxTokens int, stop []string, messages []struct {
Role string
Content string
-}) {
+},
+) {
chatOrStream := "chat"
if stream {
chatOrStream = "stream"
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index f90562f..259ad68 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -8,13 +8,13 @@ import (
// ANSI color utilities shared across Hexai.
const (
- AnsiBgBlack = "\x1b[40m"
- AnsiGrey = "\x1b[90m"
- AnsiCyan = "\x1b[36m"
- AnsiGreen = "\x1b[32m"
- AnsiYellow = "\x1b[33m"
- AnsiRed = "\x1b[31m"
- AnsiReset = "\x1b[0m"
+ AnsiBgBlack = "\x1b[40m"
+ AnsiGrey = "\x1b[90m"
+ AnsiCyan = "\x1b[36m"
+ AnsiGreen = "\x1b[32m"
+ AnsiYellow = "\x1b[33m"
+ AnsiRed = "\x1b[31m"
+ AnsiReset = "\x1b[0m"
)
// AnsiBase is the default style: black background + grey foreground.
diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go
index be8c93f..adeefde 100644
--- a/internal/logging/logging_test.go
+++ b/internal/logging/logging_test.go
@@ -1,48 +1,48 @@
package logging
import (
- "bytes"
- "log"
- "strings"
- "testing"
+ "bytes"
+ "log"
+ "strings"
+ "testing"
)
func TestLogf_WithBindAndPreview(t *testing.T) {
- var buf bytes.Buffer
- l := log.New(&buf, "", 0)
- Bind(l)
+ var buf bytes.Buffer
+ l := log.New(&buf, "", 0)
+ Bind(l)
- SetLogPreviewLimit(5)
- if got := PreviewForLog("abcdef"); got != "abcde…" {
- t.Fatalf("preview truncation failed: %q", got)
- }
- if got := PreviewForLog("abcd"); got != "abcd" {
- t.Fatalf("preview (no trunc) failed: %q", got)
- }
- SetLogPreviewLimit(0)
- if got := PreviewForLog("abcdef"); got != "abcdef" {
- t.Fatalf("preview unlimited failed: %q", got)
- }
+ SetLogPreviewLimit(5)
+ if got := PreviewForLog("abcdef"); got != "abcde…" {
+ t.Fatalf("preview truncation failed: %q", got)
+ }
+ if got := PreviewForLog("abcd"); got != "abcd" {
+ t.Fatalf("preview (no trunc) failed: %q", got)
+ }
+ SetLogPreviewLimit(0)
+ if got := PreviewForLog("abcdef"); got != "abcdef" {
+ t.Fatalf("preview unlimited failed: %q", got)
+ }
- Logf("mod ", "hello %s", "world")
- out := buf.String()
- if !strings.Contains(out, "hello world") || !strings.Contains(out, AnsiBase) || !strings.Contains(out, AnsiReset) {
- t.Fatalf("log output missing parts: %q", out)
- }
+ Logf("mod ", "hello %s", "world")
+ out := buf.String()
+ if !strings.Contains(out, "hello world") || !strings.Contains(out, AnsiBase) || !strings.Contains(out, AnsiReset) {
+ t.Fatalf("log output missing parts: %q", out)
+ }
}
func TestChatLogger_LogStart(t *testing.T) {
- var buf bytes.Buffer
- Bind(log.New(&buf, "", 0))
- SetLogPreviewLimit(3)
- cl := NewChatLogger("prov")
- msgs := []struct{ Role, Content string }{{"user", "abcdef"}, {"assistant", "xyz"}}
- cl.LogStart(true, "m", 0.2, 128, []string{"END"}, msgs)
- out := buf.String()
- if !strings.Contains(out, "stream start model=m") || !strings.Contains(out, "messages=2") {
- t.Fatalf("missing header log: %q", out)
- }
- if !strings.Contains(out, "msg[0] role=user") || !strings.Contains(out, "preview=") {
- t.Fatalf("missing message logs: %q", out)
- }
+ var buf bytes.Buffer
+ Bind(log.New(&buf, "", 0))
+ SetLogPreviewLimit(3)
+ cl := NewChatLogger("prov")
+ msgs := []struct{ Role, Content string }{{"user", "abcdef"}, {"assistant", "xyz"}}
+ cl.LogStart(true, "m", 0.2, 128, []string{"END"}, msgs)
+ out := buf.String()
+ if !strings.Contains(out, "stream start model=m") || !strings.Contains(out, "messages=2") {
+ t.Fatalf("missing header log: %q", out)
+ }
+ if !strings.Contains(out, "msg[0] role=user") || !strings.Contains(out, "preview=") {
+ t.Fatalf("missing message logs: %q", out)
+ }
}