msgimpl.go 836 B

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