From d3f629f183c8717a968babb800274136a8eecffe Mon Sep 17 00:00:00 2001 From: Richard Palethorpe Date: Thu, 26 Mar 2026 21:16:13 +0000 Subject: [PATCH] feat: Merge repeated log lines in the terminal (#9141) Signed-off-by: Richard Palethorpe --- cmd/local-ai/main.go | 14 ++++++++++++-- core/cli/context/context.go | 7 ++++--- go.mod | 4 ++-- go.sum | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/local-ai/main.go b/cmd/local-ai/main.go index d52ff2be3..00d019f8a 100644 --- a/cmd/local-ai/main.go +++ b/cmd/local-ai/main.go @@ -83,8 +83,18 @@ For documentation and support: cli.CLI.LogLevel = &logLevel } - // Set xlog logger with the desired level and text format - xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), *cli.CLI.LogFormat)) + // Set xlog logger with the desired level and text format. + // xlog auto-enables log deduplication when output is a terminal. + var logOpts []xlog.LoggerOption + if cli.CLI.LogDedupLogs != nil { + if *cli.CLI.LogDedupLogs { + logOpts = append(logOpts, xlog.WithDedup()) + } else { + logOpts = append(logOpts, xlog.WithoutDedup()) + } + } + + xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), *cli.CLI.LogFormat, logOpts...)) // Run the thing! err = ctx.Run(&cli.CLI.Context) diff --git a/core/cli/context/context.go b/core/cli/context/context.go index 2da238d8b..c6d3f1176 100644 --- a/core/cli/context/context.go +++ b/core/cli/context/context.go @@ -1,7 +1,8 @@ package cliContext type Context struct { - Debug bool `env:"LOCALAI_DEBUG,DEBUG" default:"false" hidden:"" help:"DEPRECATED, use --log-level=debug instead. Enable debug logging"` - LogLevel *string `env:"LOCALAI_LOG_LEVEL" enum:"error,warn,info,debug,trace" help:"Set the level of logs to output [${enum}]"` - LogFormat *string `env:"LOCALAI_LOG_FORMAT" default:"default" enum:"default,text,json" help:"Set the format of logs to output [${enum}]"` + Debug bool `env:"LOCALAI_DEBUG,DEBUG" default:"false" hidden:"" help:"DEPRECATED, use --log-level=debug instead. Enable debug logging"` + LogLevel *string `env:"LOCALAI_LOG_LEVEL" enum:"error,warn,info,debug,trace" help:"Set the level of logs to output [${enum}]"` + LogFormat *string `env:"LOCALAI_LOG_FORMAT" default:"default" enum:"default,text,json" help:"Set the format of logs to output [${enum}]"` + LogDedupLogs *bool `env:"LOCALAI_LOG_DEDUP" negatable:"" help:"Deduplicate consecutive identical log lines (auto-detected for terminals, use --log-dedup-logs to force on or --no-log-dedup-logs to force off)"` } diff --git a/go.mod b/go.mod index 5801d62e3..1ab36a633 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/mudler/edgevpn v0.31.1 github.com/mudler/go-processmanager v0.1.0 github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2 - github.com/mudler/xlog v0.0.5 + github.com/mudler/xlog v0.0.6 github.com/onsi/ginkgo/v2 v2.28.1 github.com/onsi/gomega v1.39.1 github.com/openai/openai-go/v3 v3.26.0 @@ -58,6 +58,7 @@ require ( go.opentelemetry.io/otel/metric v1.42.0 go.opentelemetry.io/otel/sdk/metric v1.42.0 google.golang.org/grpc v1.79.1 + google.golang.org/protobuf v1.36.11 gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/postgres v1.6.0 gorm.io/driver/sqlite v1.6.0 @@ -72,7 +73,6 @@ require ( github.com/mattn/go-sqlite3 v1.14.22 // indirect github.com/stretchr/testify v1.11.1 // indirect github.com/tmc/langchaingo v0.1.14 // indirect - google.golang.org/protobuf v1.36.11 // indirect ) require ( diff --git a/go.sum b/go.sum index f41b0fd9d..c5f130e62 100644 --- a/go.sum +++ b/go.sum @@ -682,8 +682,8 @@ github.com/mudler/skillserver v0.0.6 h1:ixz6wUekLdTmbnpAavCkTydDF6UdXAG3ncYufSPK github.com/mudler/skillserver v0.0.6/go.mod h1:z3yFhcL9bSykmmh6xgGu0hyoItd4CnxgtWMEWw8uFJU= github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025 h1:WFLP5FHInarYGXi6B/Ze204x7Xy6q/I4nCZnWEyPHK0= github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025/go.mod h1:QuIFdRstyGJt+MTTkWY+mtD7U6xwjOR6SwKUjmLZtR4= -github.com/mudler/xlog v0.0.5 h1:2unBuVC5rNGhCC86UaA94TElWFml80NL5XLK+kAmNuU= -github.com/mudler/xlog v0.0.5/go.mod h1:39f5vcd05Qd6GWKM8IjyHNQ7AmOx3ZM0YfhfIGhC18U= +github.com/mudler/xlog v0.0.6 h1:3nBV4THK8kY0Y8FDXXvWAnuAJoOyO7EAXteJeAoHUC0= +github.com/mudler/xlog v0.0.6/go.mod h1:3pO/Dsp3ViWl1QLyNtK7VQDJqMlntVu+rm5lP5PkX1g= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=