Added initial attempt at reporting proper IPs in logs
This commit is contained in:
parent
cfbffb6dab
commit
3d560ef770
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.27.0"
|
||||
var Version = "0.28.0"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
13
cmd/web.go
13
cmd/web.go
|
@ -293,11 +293,22 @@ func serveStaticFile(w http.ResponseWriter, r *http.Request, paths []string) err
|
|||
w.Write(buf)
|
||||
|
||||
if Verbose {
|
||||
remoteAddr := ""
|
||||
cfIP := w.Header().Get("Cf-Connecting-Ip")
|
||||
xRealIp := w.Header().Get("X-Real-Ip")
|
||||
if cfIP != "" {
|
||||
remoteAddr = cfIP
|
||||
} else if xRealIp != "" {
|
||||
remoteAddr = xRealIp
|
||||
} else {
|
||||
remoteAddr = r.RemoteAddr
|
||||
}
|
||||
|
||||
fmt.Printf("%v | Served %v (%v) to %v in %v\n",
|
||||
startTime.Format(LogDate),
|
||||
filePath,
|
||||
humanReadableSize(len(buf)),
|
||||
r.RemoteAddr,
|
||||
remoteAddr,
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue