feat(quick-11): add configurable log level via YJ_LOG_LEVEL env var
- Change dev mode default from Debug to Info to prevent stdout flooding - Add resolveLogLevel() function with YJ_LOG_LEVEL env var support - Accept debug/info/warn/error values (case-insensitive) - Prevents neovim display corruption during library scans
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/golang-cz/devslog"
|
"github.com/golang-cz/devslog"
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
@@ -30,12 +31,7 @@ var frontendDistAssets embed.FS
|
|||||||
func main() {
|
func main() {
|
||||||
isDev := dev.IsDev
|
isDev := dev.IsDev
|
||||||
// create sLogger
|
// create sLogger
|
||||||
var loglevel slog.Level
|
loglevel := resolveLogLevel(isDev)
|
||||||
if isDev {
|
|
||||||
loglevel = slog.LevelDebug
|
|
||||||
} else {
|
|
||||||
loglevel = slog.LevelInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
sLogger := slog.New(devslog.NewHandler(os.Stdout, &devslog.Options{
|
sLogger := slog.New(devslog.NewHandler(os.Stdout, &devslog.Options{
|
||||||
HandlerOptions: &slog.HandlerOptions{
|
HandlerOptions: &slog.HandlerOptions{
|
||||||
@@ -98,3 +94,27 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveLogLevel determines the slog level. In dev mode the default
|
||||||
|
// is Info (not Debug) to avoid flooding stdout during library scans.
|
||||||
|
// Set YJ_LOG_LEVEL=debug to restore verbose logging.
|
||||||
|
//
|
||||||
|
// Accepted values: debug, info, warn, error (case-insensitive).
|
||||||
|
// Production builds always default to Info.
|
||||||
|
func resolveLogLevel(_ bool) slog.Level {
|
||||||
|
if env := os.Getenv("YJ_LOG_LEVEL"); env != "" {
|
||||||
|
switch strings.ToLower(env) {
|
||||||
|
case "debug":
|
||||||
|
return slog.LevelDebug
|
||||||
|
case "info":
|
||||||
|
return slog.LevelInfo
|
||||||
|
case "warn":
|
||||||
|
return slog.LevelWarn
|
||||||
|
case "error":
|
||||||
|
return slog.LevelError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: Info for both dev and prod.
|
||||||
|
return slog.LevelInfo
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user