Skip to content

Commit

Permalink
Flag to skip headers in log files
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlzt committed Apr 3, 2019
1 parent 291f19f commit e00cf2d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func InitFlags(flagset *flag.FlagSet) {
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files")
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
flagset.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages")
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", false, "If true, avoid headers when openning log files")
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")
Expand Down Expand Up @@ -473,6 +474,9 @@ type loggingT struct {

// If true, do not add the prefix headers, useful when used with SetOutput
skipHeaders bool

// If true, do not add the headers to log files
skipLogHeaders bool
}

// buffer holds a byte Buffer for reuse. The zero value is ready for use.
Expand Down Expand Up @@ -901,6 +905,10 @@ func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error {

sb.Writer = bufio.NewWriterSize(sb.file, bufferSize)

if sb.logger.skipLogHeaders {
return nil
}

// Write header.
var buf bytes.Buffer
fmt.Fprintf(&buf, "Log file created at: %s\n", now.Format("2006/01/02 15:04:05"))
Expand Down

0 comments on commit e00cf2d

Please sign in to comment.