feat: add precise diagnostics and optional client copy logging controls

This commit is contained in:
2026-09-26 18:04:33 +08:00
parent 69585dab61
commit 3bbc6f60d7
44 changed files with 1529 additions and 84 deletions

View File

@@ -2,27 +2,33 @@ package logx
import (
"context"
"errors"
"log"
"log/slog"
"strings"
"time"
"git.yuntuo.hk/k2safe/go-omni/internal/configdiag"
)
// Validate checks configuration without opening files or creating resources.
func (c Config) Validate() error {
func (c Config) Validate() error { _, err := c.validate(); return err }
func (c Config) validate() (*time.Location, error) {
c = normalizeConfig(c)
if _, err := parseLevel(c.Level); err != nil {
return errors.New("logx: invalid level")
return nil, configdiag.New("level", "must be debug, info, warn, warning or error")
}
if c.Format != "json" && c.Format != "text" {
return errors.New("logx: format must be json or text")
return nil, configdiag.New("format", "must be json or text")
}
switch c.Output {
case "stdout", "stderr", "discard", "none":
default:
return errors.New("logx: invalid output")
return nil, configdiag.New("output", "must be stdout, stderr, discard or none")
}
return c.Rotation.validate(c)
if err := c.Rotation.validate(c); err != nil {
return nil, err
}
return logLocation(c.TimeZone)
}
type loggerContextKey struct{}