/
msgimpl.go
33 lines (26 loc) · 836 Bytes
/
msgimpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package log
import (
"runtime"
)
type valueIterCallback func(value interface{}) (more bool)
// The minimal interface required for the Msg helper/wrapper to operate on.
type MsgImpl interface {
// Returns the message text. Allows for lazy evaluation/prefixing etc.
Text() string
// Sets the program counters in pc. Having it in the interface may allow us to cache/freeze them
// for serialization etc.
Callers(skip int, pc []uintptr) int
// Iterates over the values as added LIFO.
Values(callback valueIterCallback)
}
// maybe implement finalizer to ensure msgs are sunk
type rootMsgImpl struct {
text func() string
}
func (m rootMsgImpl) Text() string {
return m.text()
}
func (m rootMsgImpl) Callers(skip int, pc []uintptr) int {
return runtime.Callers(skip+2, pc)
}
func (m rootMsgImpl) Values(valueIterCallback) {}