From 58a6c765fe07cdd8ed3b2a3eeef5cddc4ca9094c Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sat, 6 Feb 2021 07:29:22 -0700 Subject: [PATCH] Add trace file to replicate command This commit removes the verbose flag (`-v`) and replaces it with the trace flag (`-trace PATH`). This moves tracing to a separate file instead of writing to STDOUT. --- cmd/litestream/replicate.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/litestream/replicate.go b/cmd/litestream/replicate.go index e214224..300b254 100644 --- a/cmd/litestream/replicate.go +++ b/cmd/litestream/replicate.go @@ -29,7 +29,7 @@ type ReplicateCommand struct { // Run loads all databases specified in the configuration. func (c *ReplicateCommand) Run(ctx context.Context, args []string) (err error) { fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError) - verbose := fs.Bool("v", false, "verbose logging") + tracePath := fs.String("trace", "", "trace path") registerConfigFlag(fs, &c.ConfigPath) fs.Usage = c.Usage if err := fs.Parse(args); err != nil { @@ -56,8 +56,13 @@ func (c *ReplicateCommand) Run(ctx context.Context, args []string) (err error) { } // Enable trace logging. - if *verbose { - litestream.Tracef = log.Printf + if *tracePath != "" { + f, err := os.Create(*tracePath) + if err != nil { + return err + } + defer f.Close() + litestream.Tracef = log.New(f, "", log.LstdFlags|log.LUTC|log.Lshortfile).Printf } // Setup signal handler. @@ -159,8 +164,8 @@ Arguments: Specifies the configuration file. Defaults to %s - -v - Enable verbose logging output. + -trace PATH + Write verbose trace logging to PATH. `[1:], DefaultConfigPath()) }