@@ -111,73 +111,95 @@ func NewLTSVTailer(file string) (*LTSVTailer, error) {
111
111
return & LTSVTailer {t }, nil
112
112
}
113
113
114
+ //nolint:revive // Can't extract anymore functions to reduce complexity
114
115
func (t * Tailer ) Tail (ctx context.Context , data chan <- string ) {
115
116
for {
116
117
select {
117
118
case line := <- t .handle .Lines :
118
- lineContent := t .parseLine (line )
119
+ if line == nil {
120
+ return
121
+ }
122
+
123
+ if line .Err != nil {
124
+ continue
125
+ }
126
+
127
+ lineContent := line .Text
119
128
if lineContent != "" {
120
129
data <- lineContent
121
130
}
122
131
case <- ctx .Done ():
123
132
handleContextDone (ctx )
124
133
134
+ err := t .handle .Stop ()
135
+ if err != nil {
136
+ slog .ErrorContext (ctx , "Error stopping tailer" , "error" , err )
137
+ }
138
+
125
139
return
126
140
}
127
141
}
128
142
}
129
143
130
- func (t * Tailer ) parseLine (line * tail.Line ) string {
131
- if line == nil {
132
- return ""
133
- }
134
-
135
- if line .Err != nil {
136
- return ""
137
- }
138
-
139
- return line .Text
140
- }
141
-
144
+ //nolint:revive // Can't extract anymore functions to reduce complexity
142
145
func (t * PatternTailer ) Tail (ctx context.Context , data chan <- map [string ]string ) {
143
146
for {
144
147
select {
145
148
case line := <- t .handle .Lines :
146
- lineContent := t .parseLine (line )
149
+ if line == nil {
150
+ return
151
+ }
152
+
153
+ if line .Err != nil {
154
+ continue
155
+ }
156
+
157
+ lineContent := t .gc .ParseString (line .Text )
147
158
if lineContent != nil {
148
159
data <- lineContent
149
160
}
150
161
case <- ctx .Done ():
151
162
handleContextDone (ctx )
152
163
153
- return
154
- }
155
- }
156
- }
164
+ err := t . handle . Stop ()
165
+ if err != nil {
166
+ slog . ErrorContext ( ctx , "Error stopping tailer" , "error" , err )
167
+ }
157
168
158
- func (t * PatternTailer ) parseLine (line * tail.Line ) map [string ]string {
159
- if line == nil {
160
- return nil
161
- }
169
+ slog .DebugContext (ctx , "Tailer is done" )
162
170
163
- if line . Err != nil {
164
- return nil
171
+ return
172
+ }
165
173
}
166
-
167
- return t .gc .ParseString (line .Text )
168
174
}
169
175
176
+ //nolint:revive // Can't extract anymore functions to reduce complexity
170
177
func (t * LTSVTailer ) Tail (ctx context.Context , data chan <- map [string ]string ) {
171
178
for {
172
179
select {
173
180
case line := <- t .handle .Lines :
174
- lineText := t .parseLine (line )
181
+ if line == nil {
182
+ return
183
+ }
184
+
185
+ if line .Err != nil {
186
+ continue
187
+ }
188
+
189
+ lineText := t .parse (line .Text )
175
190
if lineText != nil {
176
191
data <- lineText
177
192
}
178
193
case <- ctx .Done ():
179
194
handleContextDone (ctx )
180
195
196
+ err := t .handle .Stop ()
197
+ if err != nil {
198
+ slog .ErrorContext (ctx , "Error stopping tailer" , "error" , err )
199
+ }
200
+
201
+ slog .DebugContext (ctx , "Tailer is done" )
202
+
181
203
return
182
204
}
183
205
}
@@ -199,18 +221,6 @@ func (t *LTSVTailer) parse(line string) map[string]string {
199
221
return lineMap
200
222
}
201
223
202
- func (t * LTSVTailer ) parseLine (line * tail.Line ) map [string ]string {
203
- if line == nil {
204
- return nil
205
- }
206
-
207
- if line .Err != nil {
208
- return nil
209
- }
210
-
211
- return t .parse (line .Text )
212
- }
213
-
214
224
func handleContextDone (ctx context.Context ) {
215
225
ctxErr := ctx .Err ()
216
226
switch ctxErr {
@@ -219,5 +229,4 @@ func handleContextDone(ctx context.Context) {
219
229
case context .Canceled :
220
230
slog .DebugContext (ctx , "Tailer forcibly canceled" , "error" , ctxErr )
221
231
}
222
- slog .DebugContext (ctx , "Tailer is done" )
223
232
}
0 commit comments