Skip to content

Commit

Permalink
Make command line flags configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh committed Aug 31, 2021
1 parent 9ef845f commit 7d8b5c8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,29 @@ type flushSyncWriter interface {
io.Writer
}

// init sets up the defaults and runs flushDaemon.
func init() {
flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files")
flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
flag.Var(&logging.verbosity, "v", "log level for V logs")
flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")

// Default stderrThreshold is ERROR.
logging.stderrThreshold = errorLog

logging.stderrThreshold = errorLog // Default stderrThreshold is ERROR.
logging.setVState(0, nil, false)
logging.toStderr = true
logging.alsoToStderr = false
go logging.flushDaemon()
}

// InitFlags is for explicitly initializing the flags.
func InitFlags(flagset *flag.FlagSet) {
if flagset == nil {
flagset = flag.CommandLine
}

flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files")
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files")
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
}

// Flush flushes all pending log I/O.
func Flush() {
logging.lockAndFlushAll()
Expand Down

0 comments on commit 7d8b5c8

Please sign in to comment.