Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,25 @@ type flushSyncWriter interface {
io.Writer
}

// Allow the user to set this variable at build-time, to prefix our flags'
// names with something of their choice.
var FlagPrefix string

func prefix(s string) string {
if FlagPrefix != "" {
return FlagPrefix + s
}

return s
}

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")
flag.BoolVar(&logging.toStderr, prefix("logtostderr"), false, "log to standard error instead of files")
flag.BoolVar(&logging.alsoToStderr, prefix("alsologtostderr"), false, "log to standard error as well as files")
flag.Var(&logging.verbosity, prefix("v"), "log level for V logs")
flag.Var(&logging.stderrThreshold, prefix("stderrthreshold"), "logs at or above this threshold go to stderr")
flag.Var(&logging.vmodule, prefix("vmodule"), "comma-separated list of pattern=N settings for file-filtered logging")
flag.Var(&logging.traceLocation, prefix("log_backtrace_at"), "when logging hits line file:N, emit a stack trace")

// Default stderrThreshold is ERROR.
logging.stderrThreshold = errorLog
Expand Down
2 changes: 1 addition & 1 deletion glog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var logDirs []string

// If non-empty, overrides the choice of directory in which to write logs.
// See createLogDirs for the full list of possible destinations.
var logDir = flag.String("log_dir", "", "If non-empty, write log files in this directory")
var logDir = flag.String(prefix("log_dir"), "", "If non-empty, write log files in this directory")

func createLogDirs() {
if *logDir != "" {
Expand Down