set_debug.go 778 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package files
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/calmh/syncthing/cid"
  6. )
  7. type logEntry struct {
  8. time time.Time
  9. method string
  10. cid uint
  11. node string
  12. nfiles int
  13. }
  14. func (l logEntry) String() string {
  15. return fmt.Sprintf("%v: %s cid:%d node:%s nfiles:%d", l.time, l.method, l.cid, l.node, l.nfiles)
  16. }
  17. var (
  18. debugLog [10]logEntry
  19. debugNext int
  20. cm *cid.Map
  21. )
  22. func SetCM(m *cid.Map) {
  23. cm = m
  24. }
  25. func log(method string, id uint, nfiles int) {
  26. e := logEntry{
  27. time: time.Now(),
  28. method: method,
  29. cid: id,
  30. nfiles: nfiles,
  31. }
  32. if cm != nil {
  33. e.node = cm.Name(id)
  34. }
  35. debugLog[debugNext] = e
  36. debugNext = (debugNext + 1) % len(debugLog)
  37. }
  38. func printLog() {
  39. l.Debugln("--- Consistency error ---")
  40. for _, e := range debugLog {
  41. l.Debugln(e)
  42. }
  43. }