Skip to content

Commit

Permalink
remove need fields from entry
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Dec 23, 2020
1 parent 3727a04 commit 343ff0d
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var DefaultLogger = Logger{
type Entry struct {
buf []byte
Level Level
need uint32
w Writer
}

Expand Down Expand Up @@ -81,12 +80,6 @@ const TimeFormatUnix = "\x01"
// serialized as Unix timestamp integers in milliseconds.
const TimeFormatUnixMs = "\x02"

const (
needStack = 0b0001
needExit = 0b0010
needPanic = 0b0100
)

// Trace starts a new message with trace level.
func Trace() (e *Entry) {
e = DefaultLogger.header(TraceLevel)
Expand Down Expand Up @@ -289,14 +282,6 @@ func (l *Logger) header(level Level) *Entry {
e := epool.Get().(*Entry)
e.buf = e.buf[:0]
e.Level = level
switch level {
default:
e.need = 0
case FatalLevel:
e.need = needStack | needExit
case PanicLevel:
e.need = needStack | needPanic
}
if l.Writer != nil {
e.w = l.Writer
} else {
Expand Down Expand Up @@ -559,15 +544,6 @@ func (e *Entry) AnErr(key string, err error) *Entry {
return e
}

if e.need&needStack == 0 {
if _, ok := err.(fmt.Formatter); ok {
e.key("stack")
e.buf = append(e.buf, '"')
fmt.Fprintf(escapeWriter{e}, "%+v", err)
e.buf = append(e.buf, '"')
}
}

e.key(key)
if o, ok := err.(LogObjectMarshaler); ok {
o.MarshalLogObject(e)
Expand Down Expand Up @@ -984,7 +960,9 @@ func (e *Entry) Caller(depth int) *Entry {
// Stack enables stack trace printing for the error passed to Err().
func (e *Entry) Stack() *Entry {
if e != nil {
e.need |= needStack
e.buf = append(e.buf, ",\"stack\":\""...)
e.bytes(stacks(false))
e.buf = append(e.buf, '"')
}
return e
}
Expand Down Expand Up @@ -1015,19 +993,15 @@ func (e *Entry) Msg(msg string) {
if msg != "" {
e.buf = append(e.buf, ",\"message\":\""...)
e.string(msg)
if e.need&needStack != 0 {
e.buf = append(e.buf, "\",\"stack\":\""...)
e.bytes(stacks(false))
}
e.buf = append(e.buf, "\"}\n"...)
} else {
e.buf = append(e.buf, '}', '\n')
}
e.w.WriteEntry(e)
if (e.need&needExit != 0) && notTest {
if (e.Level == FatalLevel) && notTest {
os.Exit(255)
}
if (e.need&needPanic != 0) && notTest {
if (e.Level == PanicLevel) && notTest {
panic(msg)
}
if cap(e.buf) <= bbcap {
Expand Down

0 comments on commit 343ff0d

Please sign in to comment.