Implement handlers to normalise how logging is handled
This commit is contained in:
@@ -5,12 +5,10 @@ import (
|
||||
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/cli/version"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
// Run the app. This is the main app entry point
|
||||
func Run() error {
|
||||
util.Log("Running")
|
||||
root.Cmd.Version(version.Version)
|
||||
_, err := root.Cmd.Parse(os.Args[1:])
|
||||
return err
|
||||
|
||||
@@ -2,15 +2,15 @@ package info
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("info", "Display information about OONI Probe")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Info")
|
||||
log.Info("Info")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package list
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("list", "List measurements")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Listing")
|
||||
log.Info("Listing")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package nettest
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("nettest", "Run a specific nettest")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Nettest")
|
||||
log.Info("Nettest")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package root
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/cli"
|
||||
ooni "github.com/openobservatory/gooni"
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/openobservatory/gooni/internal/log/handlers/batch"
|
||||
"github.com/openobservatory/gooni/internal/log/handlers/cli"
|
||||
"github.com/prometheus/common/version"
|
||||
)
|
||||
|
||||
@@ -20,11 +21,17 @@ var Init func() (*ooni.Config, *ooni.Context, error)
|
||||
|
||||
func init() {
|
||||
configPath := Cmd.Flag("config", "Set a custom config file path").Short('c').String()
|
||||
verbose := Cmd.Flag("verbose", "Enable verbose log output.").Short('v').Bool()
|
||||
|
||||
isVerbose := Cmd.Flag("verbose", "Enable verbose log output.").Short('v').Bool()
|
||||
isBatch := Cmd.Flag("batch", "Enable batch command line usage.").Bool()
|
||||
|
||||
Cmd.PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
log.SetHandler(cli.Default)
|
||||
if *verbose {
|
||||
if *isBatch {
|
||||
log.SetHandler(batch.Default)
|
||||
} else {
|
||||
log.SetHandler(cli.Default)
|
||||
}
|
||||
if *isVerbose {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Debugf("ooni version %s", version.Version)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
"github.com/openobservatory/gooni/nettests"
|
||||
"github.com/openobservatory/gooni/nettests/groups"
|
||||
)
|
||||
@@ -18,7 +17,7 @@ func init() {
|
||||
nettestGroup := cmd.Arg("name", "the nettest group to run").Required().String()
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Starting %s", *nettestGroup)
|
||||
log.Infof("Starting %s", *nettestGroup)
|
||||
_, ctx, err := root.Init()
|
||||
if err != nil {
|
||||
log.Errorf("%s", err)
|
||||
@@ -37,7 +36,7 @@ func init() {
|
||||
}
|
||||
|
||||
for _, nt := range group.Nettests {
|
||||
ctl := nettests.NewController(ctx)
|
||||
ctl := nettests.NewController(ctx, result)
|
||||
nt.Run(ctl)
|
||||
// XXX
|
||||
// 1. Generate the summary
|
||||
|
||||
@@ -2,15 +2,15 @@ package nettest
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("show", "Show a specific measurement")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Show")
|
||||
log.Info("Show")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package upload
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kingpin"
|
||||
"github.com/apex/log"
|
||||
"github.com/openobservatory/gooni/internal/cli/root"
|
||||
"github.com/openobservatory/gooni/internal/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := root.Command("upload", "Upload a specific measurement")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
util.Log("Uploading")
|
||||
log.Info("Uploading")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user