10000 Fix tailing multiple log files · sargath/symfony-cli@8b9f6cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b9f6cd

Browse files
committed
Fix tailing multiple log files
Because the goroutine is started within a for loop we need to pass the applog variable to the closure. Otherwise, it references the last one in the loop. Explaination: https://riptutorial.com/go/example/3897/using-closures-with-goroutines-in-a-loop Fixes: - https://github.com/symfony/cli/issues/488
1 parent de8827d commit 8b9f6cd

File tree

Collapse file tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

local/logs/tailer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (tailer *Tailer) Watch(pidFile *pid.PidFile) error {
120120
if err := inotify.Watch(dir, watcherChan, inotify.Create); err != nil {
121121
return errors.Wrap(err, "unable to watch the applog directory")
122122
}
123-
go func() {
123+
go func(applog string) {
124124
for {
125125
e := <-watcherChan
126126
if e.Path() != applog {
@@ -141,7 +141,7 @@ func (tailer *Tailer) Watch(pidFile *pid.PidFile) error {
141141
}
142142
}()
143143
}
144-
}()
144+
}(applog)
145145
watcherChan <- logFileEvent(applog)
146146
}
147147
}

0 commit comments

Comments
 (0)
0