Merge pull request #38 from benbjohnson/trace-flag

Add trace file to replicate command
This commit is contained in:
Ben Johnson
2021-02-06 07:34:02 -07:00
committed by GitHub

View File

@@ -29,7 +29,7 @@ type ReplicateCommand struct {
// Run loads all databases specified in the configuration. // Run loads all databases specified in the configuration.
func (c *ReplicateCommand) Run(ctx context.Context, args []string) (err error) { func (c *ReplicateCommand) Run(ctx context.Context, args []string) (err error) {
fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError) fs := flag.NewFlagSet("litestream-replicate", flag.ContinueOnError)
verbose := fs.Bool("v", false, "verbose logging") tracePath := fs.String("trace", "", "trace path")
registerConfigFlag(fs, &c.ConfigPath) registerConfigFlag(fs, &c.ConfigPath)
fs.Usage = c.Usage fs.Usage = c.Usage
if err := fs.Parse(args); err != nil { 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. // Enable trace logging.
if *verbose { if *tracePath != "" {
litestream.Tracef = log.Printf 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. // Setup signal handler.
@@ -159,8 +164,8 @@ Arguments:
Specifies the configuration file. Specifies the configuration file.
Defaults to %s Defaults to %s
-v -trace PATH
Enable verbose logging output. Write verbose trace logging to PATH.
`[1:], DefaultConfigPath()) `[1:], DefaultConfigPath())
} }