MCPcopy
hub / github.com/nextdns/nextdns / FollowLog

Function FollowLog

host/log_windows.go:93–133  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

91}
92
93func FollowLog(name string) error {
94 lastID := uint64(0)
95 events, err := queryWindowsEvents(name, 1)
96 if err != nil {
97 return err
98 }
99 if len(events) > 0 {
100 lastID = events[0].RecordID
101 }
102
103 ticker := time.NewTicker(2 * time.Second)
104 defer ticker.Stop()
105 for range ticker.C {
106 events, err := queryWindowsEvents(name, 50)
107 if err != nil {
108 return err
109 }
110 var newEvents []windowsEvent
111 for _, e := range events {
112 if e.RecordID > lastID {
113 newEvents = append(newEvents, e)
114 }
115 }
116 if len(newEvents) == 0 {
117 continue
118 }
119 sort.Slice(newEvents, func(i, j int) bool {
120 return newEvents[i].RecordID < newEvents[j].RecordID
121 })
122 for _, e := range newEvents {
123 if _, err := fmt.Fprintln(os.Stdout, e.Text); err != nil {
124 return err
125 }
126 if _, err := fmt.Fprintln(os.Stdout); err != nil {
127 return err
128 }
129 lastID = e.RecordID
130 }
131 }
132 return nil
133}
134
135type windowsEvent struct {
136 RecordID uint64

Callers 1

svcFunction · 0.92

Calls 2

queryWindowsEventsFunction · 0.85
StopMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…