Add trace logging.

This commit is contained in:
Ben Johnson
2021-01-11 10:31:39 -07:00
parent bcdb553267
commit 1fa1313b0b
3 changed files with 24 additions and 0 deletions

View File

@@ -5,8 +5,10 @@ import (
"errors"
"flag"
"fmt"
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
@@ -25,6 +27,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")
registerConfigFlag(fs, &c.ConfigPath)
fs.Usage = c.Usage
if err := fs.Parse(args); err != nil {
@@ -40,6 +43,11 @@ func (c *ReplicateCommand) Run(ctx context.Context, args []string) (err error) {
return err
}
// Enable trace logging.
if *verbose {
litestream.Tracef = log.Printf
}
// Setup signal handler.
ctx, cancel := context.WithCancel(ctx)
ch := make(chan os.Signal, 1)
@@ -119,5 +127,8 @@ Arguments:
-config PATH
Specifies the configuration file. Defaults to %s
-v
Enable verbose logging output.
`[1:], DefaultConfigPath)
}