Skip to content

Commit efde6ca

Browse files
Merge pull request #40 from FireTail-io/ipv6
Ipv6
2 parents 20125ed + 7aa4a72 commit efde6ca

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

logging/default_batch_callback.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"log"
89
"net/http"
910
)
1011

@@ -53,5 +54,8 @@ func getDefaultBatchCallback(options BatchLoggerOptions) func([][]byte) {
5354
break
5455
}
5556
}
57+
if err != nil {
58+
log.Println("Error sending logs to Firetail API: ", err)
59+
}
5660
}
5761
}

middlewares/http/middleware.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"io"
88
"io/ioutil"
9+
"net"
910
"net/http"
1011
"net/http/httptest"
1112
"strings"
@@ -53,14 +54,18 @@ func GetMiddleware(options *Options) (func(next http.Handler) http.Handler, erro
5354
middleware := func(next http.Handler) http.Handler {
5455
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5556
// Create a LogEntry populated with everything we know right now
57+
ip, _, err := net.SplitHostPort(r.RemoteAddr)
58+
if err != nil {
59+
ip = strings.TrimSuffix(strings.TrimPrefix(r.RemoteAddr[:strings.LastIndex(r.RemoteAddr, ":")], "["), "]")
60+
}
5661
logEntry := logging.LogEntry{
5762
Version: logging.The100Alpha,
5863
DateCreated: time.Now().UnixMilli(),
5964
Request: logging.Request{
6065
HTTPProtocol: logging.HTTPProtocol(r.Proto),
6166
Headers: r.Header,
6267
Method: logging.Method(r.Method),
63-
IP: strings.Split(r.RemoteAddr, ":")[0],
68+
IP: ip,
6469
Resource: r.URL.Path, // We'll fill this in later if we have a router
6570
},
6671
}

0 commit comments

Comments
 (0)