From 8b3e0ebf8aab4071ef7721121f04081c32a5c9da Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 21 Dec 2025 21:21:59 +0100 Subject: [PATCH] chore: allow to set local-ai log format, default to custom one (#7679) Signed-off-by: Ettore Di Giacinto --- backend/go/local-store/main.go | 3 ++- cmd/local-ai/main.go | 2 +- core/cli/context/context.go | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/go/local-store/main.go b/backend/go/local-store/main.go index cdead5ac6..f06dfa6f5 100644 --- a/backend/go/local-store/main.go +++ b/backend/go/local-store/main.go @@ -4,6 +4,7 @@ package main import ( "flag" + "os" grpc "github.com/mudler/LocalAI/pkg/grpc" "github.com/mudler/xlog" @@ -14,7 +15,7 @@ var ( ) func main() { - xlog.SetLogger(xlog.NewLogger(xlog.LogLevel("info"), "text")) + xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(os.Getenv("LOCALAI_LOG_LEVEL")), os.Getenv("LOCALAI_LOG_FORMAT"))) flag.Parse() diff --git a/cmd/local-ai/main.go b/cmd/local-ai/main.go index b9fde7d9f..9d5cb3fba 100644 --- a/cmd/local-ai/main.go +++ b/cmd/local-ai/main.go @@ -72,7 +72,7 @@ Version: ${version} } // Set xlog logger with the desired level and text format - xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), "text")) + xlog.SetLogger(xlog.NewLogger(xlog.LogLevel(*cli.CLI.LogLevel), *cli.CLI.LogFormat)) // Run the thing! err = ctx.Run(&cli.CLI.Context) diff --git a/core/cli/context/context.go b/core/cli/context/context.go index 061d27503..2da238d8b 100644 --- a/core/cli/context/context.go +++ b/core/cli/context/context.go @@ -1,6 +1,7 @@ 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}]"` + 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}]"` }