common.go 511 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package pdebug
  2. import (
  3. "io"
  4. "os"
  5. "sync"
  6. "time"
  7. )
  8. type pdctx struct {
  9. mutex sync.Mutex
  10. indentL int
  11. LogTime bool
  12. Prefix string
  13. Writer io.Writer
  14. }
  15. var emptyMarkerGuard = &markerg{}
  16. type markerg struct {
  17. indentg guard
  18. ctx *pdctx
  19. f string
  20. args []interface{}
  21. start time.Time
  22. errptr *error
  23. }
  24. var DefaultCtx = &pdctx{
  25. LogTime: true,
  26. Prefix: "|DEBUG| ",
  27. Writer: os.Stdout,
  28. }
  29. type guard struct {
  30. cb func()
  31. }
  32. func (g *guard) End() {
  33. if cb := g.cb; cb != nil {
  34. cb()
  35. }
  36. }