@@ -15,6 +15,26 @@ type logEntry interface {
15
15
eventType () string
16
16
}
17
17
18
+ type addressLog struct {
19
+ Host string `json:"host"`
20
+ Port int `json:"port"`
21
+ }
22
+
23
+ func (entry addressLog ) String () string {
24
+ return net .JoinHostPort (entry .Host , fmt .Sprint (entry .Port ))
25
+ }
26
+
27
+ func getAddressLog (host string , port int , cfg * config ) interface {} {
28
+ entry := addressLog {
29
+ Host : host ,
30
+ Port : port ,
31
+ }
32
+ if cfg .Logging .SplitHostPort {
33
+ return entry
34
+ }
35
+ return entry .String ()
36
+ }
37
+
18
38
type authAccepted bool
19
39
20
40
func (accepted authAccepted ) String () string {
@@ -98,7 +118,7 @@ func (entry connectionCloseLog) eventType() string {
98
118
}
99
119
100
120
type tcpipForwardLog struct {
101
- Address string `json:"address"`
121
+ Address interface {} `json:"address"`
102
122
}
103
123
104
124
func (entry tcpipForwardLog ) String () string {
@@ -109,7 +129,7 @@ func (entry tcpipForwardLog) eventType() string {
109
129
}
110
130
111
131
type cancelTCPIPForwardLog struct {
112
- Address string `json:"address"`
132
+ Address interface {} `json:"address"`
113
133
}
114
134
115
135
func (entry cancelTCPIPForwardLog ) String () string {
@@ -184,8 +204,8 @@ func (entry sessionInputLog) eventType() string {
184
204
185
205
type directTCPIPLog struct {
186
206
channelLog
187
- From string `json:"from"`
188
- To string `json:"to"`
207
+ From interface {} `json:"from"`
208
+ To interface {} `json:"to"`
189
209
}
190
210
191
211
func (entry directTCPIPLog ) String () string {
@@ -366,19 +386,8 @@ func (context connContext) logEvent(entry logEntry) {
366
386
}
367
387
if context .cfg .Logging .JSON {
368
388
var jsonEntry interface {}
369
- var source interface {}
370
- if context .cfg .Logging .SplitHostPort {
371
- tcpSource := context .RemoteAddr ().(* net.TCPAddr )
372
- source = struct {
373
- Host string `json:"host"`
374
- Port int `json:"port"`
375
- }{
376
- Host : tcpSource .IP .String (),
377
- Port : tcpSource .Port ,
378
- }
379
- } else {
380
- source = context .RemoteAddr ().String ()
381
- }
389
+ tcpSource := context .RemoteAddr ().(* net.TCPAddr )
390
+ source := getAddressLog (tcpSource .IP .String (), tcpSource .Port , context .cfg )
382
391
if context .cfg .Logging .Timestamps {
383
392
jsonEntry = struct {
384
393
Time string `json:"time"`
0 commit comments