package main import ( "log/slog" "os" "github.com/vaughan0/go-ini" "go.bigb.es/auxilia/scribe" "sourcecraft.dev/bigbes/sr-ht-ecore/logging" ) // installLogger installs the process-wide slog handler, and it is the daemon's: // cmd/doltsrht/logging.go builds the same scribe handler over the same // sr-ht-ecore policy, so a migration and the daemon that starts after it are // read the same way in the same journal. The file is named after that one for // the same reason. // // Installing it at all is the point rather than the tidiness. brant reports a // migration directory it cannot open with // `slog.Error("failed to create provider", "datasource", a.DataSourceName, ...)` // — the connection string, password and all, at ERR level, on the ordinary path // an installed package takes before its first migration ships. Without this call // that record goes to Go's built-in stderr handler, which knows no mask list, so // the redaction sr-ht-ecore maintains never gets a chance to run. It was the // install that was missing here, not the list: the daemon next door had been // masking a DSN correctly for as long as this binary had been printing one. // // One thing no mask list can fix: brant's own cli.initLogger runs inside // ProviderFromArgs, ahead of that record, and under --json it calls // slog.SetDefault with a plain JSON handler of its own — which throws this one // away and prints the DSN again. Nothing here passes --json and nothing should // start; the default branch only redirects the std log package and leaves the // installed handler alone, which is why the masking holds. // // The verbosity comes from DefaultsWithoutDebugFlag rather than the daemon's // Defaults, and that is the one place the two differ: ecore reads a standalone // -d out of os.Args as SourceHut's debug flag, while here -d is brant's // --dialect and takes a value, so `doltsrht-migrate -d postgres up` would // silently ask for debug logging as well. $LOG_LEVEL and [dolt.sr.ht]log-level // still resolve, which is what an operator debugging an upgrade hook reaches // for. func installLogger(conf ini.File) *slog.Logger { opts := logging.DefaultsWithoutDebugFlag(conf, serviceName) return logging.Install(scribe.NewTintHandler( scribe.WithWriter(os.Stderr), scribe.WithLevel(opts.Level), scribe.WithSource(opts.AddSource), scribe.WithTimeFormat(opts.TimeFormat), // Colour is for a terminal; under systemd or a container's log // collector the escapes are noise in the journal. scribe.WithNoColor(!opts.Color), // The masks are keyed on the attribute path, not on the message, so // they cost nothing in prose and cannot be defeated by a sentence that // happens to contain the word "token". This binary holds exactly one // credential — the connection string — and brant is what prints it. scribe.WithMaskKeys(opts.MaskKeys...), scribe.WithMask(opts.MaskPattern, opts.MaskReplacement), )) }