Skip to content

Commit

Permalink
add debug level for glog
Browse files Browse the repository at this point in the history
  • Loading branch information
shanks committed Oct 9, 2015
1 parent fca8c88 commit 6b2eef6
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ type severity int32 // sync/atomic int32
// A message written to a high-severity log file is also written to each
// lower-severity log file.
const (
infoLog severity = iota
debugLog severity = iota
infoLog
warningLog
errorLog
fatalLog
numSeverity = 4
numSeverity = 5
)

const severityChar = "IWEF"
const severityChar = "DIWEF"

var severityName = []string{
debugLog: "DEBUG",
infoLog: "INFO",
warningLog: "WARNING",
errorLog: "ERROR",
Expand Down Expand Up @@ -180,10 +182,11 @@ func (s *OutputStats) Bytes() int64 {
// Stats tracks the number of lines of output and number of bytes
// per severity level. Values must be read with atomic.LoadInt64.
var Stats struct {
Info, Warning, Error OutputStats
Debug, Info, Warning, Error OutputStats
}

var severityStats = [numSeverity]*OutputStats{
debugLog: &Stats.Debug,
infoLog: &Stats.Info,
warningLog: &Stats.Warning,
errorLog: &Stats.Error,
Expand Down Expand Up @@ -703,6 +706,8 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
fallthrough
case infoLog:
l.file[infoLog].Write(data)
case debugLog:
l.file[debugLog].Write(data)
}
}
if s == fatalLog {
Expand All @@ -722,7 +727,7 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
// Write the stack trace for all goroutines to the files.
trace := stacks(true)
logExitFunc = func(error) {} // If we get a write error, we'll still exit below.
for log := fatalLog; log >= infoLog; log-- {
for log := fatalLog; log >= debugLog; log-- {
if f := l.file[log]; f != nil { // Can be nil if -logtostderr is set.
f.Write(trace)
}
Expand Down Expand Up @@ -862,7 +867,7 @@ func (l *loggingT) createFiles(sev severity) error {
now := time.Now()
// Files are created in decreasing severity order, so as soon as we find one
// has already been created, we can stop.
for s := sev; s >= infoLog && l.file[s] == nil; s-- {
for s := sev; s >= debugLog && l.file[s] == nil; s-- {
sb := &syncBuffer{
logger: l,
sev: s,
Expand Down Expand Up @@ -895,7 +900,7 @@ func (l *loggingT) lockAndFlushAll() {
// l.mu is held.
func (l *loggingT) flushAll() {
// Flush from fatal down, in case there's trouble flushing.
for s := fatalLog; s >= infoLog; s-- {
for s := fatalLog; s >= debugLog; s-- {
file := l.file[s]
if file != nil {
file.Flush() // ignore error
Expand Down Expand Up @@ -1049,6 +1054,22 @@ func (v Verbose) Infof(format string, args ...interface{}) {
}
}

func Debug(args ...interface{}) {
logging.print(debugLog, args...)
}

func DebugDepth(depth int, args ...interface{}) {
logging.printDepth(debugLog, depth, args...)
}

func Debugln(args ...interface{}) {
logging.println(debugLog, args...)
}

func Debugf(format string, args ...interface{}) {
logging.printf(debugLog, format, args...)
}

// Info logs to the INFO log.
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func Info(args ...interface{}) {
Expand Down

0 comments on commit 6b2eef6

Please sign in to comment.