// Watch is a blocking function that writes to the channel all new created log entries.
// The client should cancel the ctx to signal stopping writing to the channel and free resources.
Watch is a blocking function that writes to the channel all new created log entries.
The client should cancel the ctx to signal stopping writing to the channel and free resources.
// Watch is a blocking function that writes to the channel all new created log entries . // The client should cancel the ctx to signal stopping writing to the channel and free resources .
func (cl *Logger) Watch(ctx context.Context, c chan<- ffs.LogEntry) error {
	cl.lock.Lock()
	ic := make(chan ffs.LogEntry, 20)
	cl.watchers = append(cl.watchers, ic)
	cl.lock.Unlock()
	stop := false
	for !stop {
		select {
		case <-ctx.Done():
			stop = true
		case l, ok := <-ic:
			if !ok {
				return fmt.Errorf("cidlogger was closed with a listening client")
			}
			c <- l
		}
	}
	cl.lock.Lock()
	defer cl.lock.Unlock()
	for i := range cl.watchers {
		if cl.watchers[i] == ic {
			cl.watchers = append(cl.watchers[:i], cl.watchers[i+1:]...)
			break
		}
	}
	return nil
}
func ( cl * Logger ) Watch ( ctx context . Context , c chan <- ffs . LogEntry ) error { cl . lock . Lock ( ) ic := make ( chan ffs . LogEntry , 20 ) cl . watchers = append ( cl . watchers , ic ) cl . lock . Unlock ( ) stop := false for ! stop { select { case <- ctx . Done ( ) : stop = true case l , ok := <- ic : if ! ok { return fmt . Errorf ( " " ) } c <- l } } cl . lock . Lock ( ) defer cl . lock . Unlock ( ) for i := range cl . watchers { if cl . watchers [ i ] == ic { cl . watchers = append ( cl . watchers [ : i ] , cl . watchers [ i + 1 : ] ... ) break } } return nil }
Watch is a blocking function that writes to the channel all new created log entries.
Watch is a blocking function that writes to the channel all new created log entries .