Skip to content

Commit d3f629f

Browse files
authored
feat: Merge repeated log lines in the terminal (#9141)
Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent b1aa707 commit d3f629f

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

cmd/local-ai/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,18 @@ For documentation and support:
8383
cli.CLI.LogLevel = &logLevel
8484
}
8585

86-
// Set xlog logger with the desired level and text format
87-
xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), *cli.CLI.LogFormat))
86+
// Set xlog logger with the desired level and text format.
87+
// xlog auto-enables log deduplication when output is a terminal.
88+
var logOpts []xlog.LoggerOption
89+
if cli.CLI.LogDedupLogs != nil {
90+
if *cli.CLI.LogDedupLogs {
91+
logOpts = append(logOpts, xlog.WithDedup())
92+
} else {
93+
logOpts = append(logOpts, xlog.WithoutDedup())
94+
}
95+
}
96+
97+
xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), *cli.CLI.LogFormat, logOpts...))
8898

8999
// Run the thing!
90100
err = ctx.Run(&cli.CLI.Context)

core/cli/context/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cliContext
22

33
type Context struct {
4-
Debug bool `env:"LOCALAI_DEBUG,DEBUG" default:"false" hidden:"" help:"DEPRECATED, use --log-level=debug instead. Enable debug logging"`
5-
LogLevel *string `env:"LOCALAI_LOG_LEVEL" enum:"error,warn,info,debug,trace" help:"Set the level of logs to output [${enum}]"`
6-
LogFormat *string `env:"LOCALAI_LOG_FORMAT" default:"default" enum:"default,text,json" help:"Set the format of logs to output [${enum}]"`
4+
Debug bool `env:"LOCALAI_DEBUG,DEBUG" default:"false" hidden:"" help:"DEPRECATED, use --log-level=debug instead. Enable debug logging"`
5+
LogLevel *string `env:"LOCALAI_LOG_LEVEL" enum:"error,warn,info,debug,trace" help:"Set the level of logs to output [${enum}]"`
6+
LogFormat *string `env:"LOCALAI_LOG_FORMAT" default:"default" enum:"default,text,json" help:"Set the format of logs to output [${enum}]"`
7+
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)"`
78
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/mudler/edgevpn v0.31.1
3737
github.com/mudler/go-processmanager v0.1.0
3838
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2
39-
github.com/mudler/xlog v0.0.5
39+
github.com/mudler/xlog v0.0.6
4040
github.com/onsi/ginkgo/v2 v2.28.1
4141
github.com/onsi/gomega v1.39.1
4242
github.com/openai/openai-go/v3 v3.26.0
@@ -58,6 +58,7 @@ require (
5858
go.opentelemetry.io/otel/metric v1.42.0
5959
go.opentelemetry.io/otel/sdk/metric v1.42.0
6060
google.golang.org/grpc v1.79.1
61+
google.golang.org/protobuf v1.36.11
6162
gopkg.in/yaml.v3 v3.0.1
6263
gorm.io/driver/postgres v1.6.0
6364
gorm.io/driver/sqlite v1.6.0
@@ -72,7 +73,6 @@ require (
7273
github.com/mattn/go-sqlite3 v1.14.22 // indirect
7374
github.com/stretchr/testify v1.11.1 // indirect
7475
github.com/tmc/langchaingo v0.1.14 // indirect
75-
google.golang.org/protobuf v1.36.11 // indirect
7676
)
7777

7878
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ github.com/mudler/skillserver v0.0.6 h1:ixz6wUekLdTmbnpAavCkTydDF6UdXAG3ncYufSPK
682682
github.com/mudler/skillserver v0.0.6/go.mod h1:z3yFhcL9bSykmmh6xgGu0hyoItd4CnxgtWMEWw8uFJU=
683683
github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025 h1:WFLP5FHInarYGXi6B/Ze204x7Xy6q/I4nCZnWEyPHK0=
684684
github.com/mudler/water v0.0.0-20250808092830-dd90dcf09025/go.mod h1:QuIFdRstyGJt+MTTkWY+mtD7U6xwjOR6SwKUjmLZtR4=
685-
github.com/mudler/xlog v0.0.5 h1:2unBuVC5rNGhCC86UaA94TElWFml80NL5XLK+kAmNuU=
686-
github.com/mudler/xlog v0.0.5/go.mod h1:39f5vcd05Qd6GWKM8IjyHNQ7AmOx3ZM0YfhfIGhC18U=
685+
github.com/mudler/xlog v0.0.6 h1:3nBV4THK8kY0Y8FDXXvWAnuAJoOyO7EAXteJeAoHUC0=
686+
github.com/mudler/xlog v0.0.6/go.mod h1:3pO/Dsp3ViWl1QLyNtK7VQDJqMlntVu+rm5lP5PkX1g=
687687
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
688688
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
689689
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=

0 commit comments

Comments
 (0)