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

@@ -22,6 +22,7 @@ import (
// standard stream. File takes precedence over Output and appends to the named
// file.
type Config struct {
TimeZone string `json:"timeZone"` // Empty retains existing timestamp behavior.
Level string `json:"level"`
Format string `json:"format"`
Output string `json:"output"`
@@ -73,7 +74,8 @@ func init() {
// call Close when the process is shutting down.
func New(cfg Config) (*Logger, error) {
cfg = normalizeConfig(cfg)
if err := cfg.Validate(); err != nil {
location, err := cfg.validate()
if err != nil {
return nil, err
}
level, err := parseLevel(cfg.Level)
@@ -95,6 +97,9 @@ func New(cfg Config) (*Logger, error) {
} else {
handler = slog.NewJSONHandler(writer, opts)
}
if location != nil {
handler = zoneHandler{Handler: handler, location: location}
}
logger := slog.New(handler)
if cfg.Service != "" {
logger = logger.With("service", cfg.Service)