Simplify copies

This commit is contained in:
Olivier Poitrey 2017-09-03 11:01:28 -07:00
parent 26094019c8
commit 3ac71fc58d
1 changed files with 5 additions and 16 deletions

19
log.go
View File

@ -157,7 +157,7 @@ func (l Logger) Output(w io.Writer) Logger {
l2 := New(w) l2 := New(w)
l2.level = l.level l2.level = l.level
l2.sampler = l.sampler l2.sampler = l.sampler
l2.context = make([]byte, len(l.context)) l2.context = make([]byte, len(l.context), cap(l.context))
copy(l2.context, l.context) copy(l2.context, l.context)
return l2 return l2
} }
@ -191,25 +191,14 @@ func (l *Logger) UpdateContext(update func(c Context) Context) {
// Level creates a child logger with the minimum accepted level set to level. // Level creates a child logger with the minimum accepted level set to level.
func (l Logger) Level(lvl Level) Logger { func (l Logger) Level(lvl Level) Logger {
return Logger{ l.level = lvl
w: l.w, return l
level: lvl,
sampler: l.sampler,
context: l.context,
}
} }
// Sample returns a logger with the s sampler. // Sample returns a logger with the s sampler.
func (l Logger) Sample(s Sampler) Logger { func (l Logger) Sample(s Sampler) Logger {
if l.sampler == s { l.sampler = s
return l return l
}
return Logger{
w: l.w,
level: l.level,
sampler: s,
context: l.context,
}
} }
// Debug starts a new message with debug level. // Debug starts a new message with debug level.