@@ -160,11 +160,17 @@ func (s *Server) goScanConnection(connection net.Conn) {
160
160
var scanCloser * ScanCloser
161
161
scanCloser = & ScanCloser {scanner , connection }
162
162
163
+ remoteAddr := connection .RemoteAddr ()
164
+ var client string
165
+ if remoteAddr != nil {
166
+ client = remoteAddr .String ()
167
+ }
168
+
163
169
s .wait .Add (1 )
164
- go s .scan (scanCloser )
170
+ go s .scan (scanCloser , client )
165
171
}
166
172
167
- func (s * Server ) scan (scanCloser * ScanCloser ) {
173
+ func (s * Server ) scan (scanCloser * ScanCloser , client string ) {
168
174
loop:
169
175
for {
170
176
select {
@@ -176,7 +182,7 @@ loop:
176
182
scanCloser .closer .SetReadDeadline (time .Now ().Add (time .Duration (s .readTimeoutMilliseconds ) * time .Millisecond ))
177
183
}
178
184
if scanCloser .Scan () {
179
- s .parser ([]byte (scanCloser .Text ()))
185
+ s .parser ([]byte (scanCloser .Text ()), client )
180
186
} else {
181
187
break loop
182
188
}
@@ -186,14 +192,17 @@ loop:
186
192
s .wait .Done ()
187
193
}
188
194
189
- func (s * Server ) parser (line []byte ) {
195
+ func (s * Server ) parser (line []byte , client string ) {
190
196
parser := s .format .GetParser (line )
191
197
err := parser .Parse ()
192
198
if err != nil {
193
199
s .lastError = err
194
200
}
195
201
196
- go s .handler .Handle (parser .Dump (), int64 (len (line )), err )
202
+ logParts := parser .Dump ()
203
+ logParts ["client" ] = client
204
+
205
+ go s .handler .Handle (logParts , int64 (len (line )), err )
197
206
}
198
207
199
208
//Returns the last error
@@ -290,7 +299,7 @@ func (s *Server) goParseDatagrams() {
290
299
if ! ok {
291
300
return
292
301
}
293
- s .parser (msg .message )
302
+ s .parser (msg .message , msg . client )
294
303
}
295
304
}
296
305
}()
0 commit comments