Skip to content

Commit

Permalink
Logging: provide command-line control (sourcegraph#55)
Browse files Browse the repository at this point in the history
* Provide -v flag to flip logging on.

* Update explanation of -v.
  • Loading branch information
parkr authored and mholt committed Aug 7, 2017
1 parent a9009b0 commit 6526149
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var configFile string
var storeResults bool
var printLogs bool

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand All @@ -31,6 +32,10 @@ a single checkup and print results to stdout. To
store the results of the check, use --store.`,

Run: func(cmd *cobra.Command, args []string) {
if printLogs {
log.SetOutput(os.Stdout)
}

allHealthy := true
c := loadCheckup()

Expand Down Expand Up @@ -93,4 +98,5 @@ func Execute() {
func init() {
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "checkup.json", "JSON config file")
RootCmd.Flags().BoolVar(&storeResults, "store", false, "Store results")
RootCmd.Flags().BoolVar(&printLogs, "v", false, "Enable logging to standard output")
}
10 changes: 10 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package checkup

import (
"io/ioutil"
"log"
)

func init() {
log.SetOutput(ioutil.Discard)
}

0 comments on commit 6526149

Please sign in to comment.