2019-11-06 11:38:41 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-10 15:31:13 -04:00
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2020-07-01 17:44:59 -04:00
|
|
|
"strings"
|
2020-06-10 15:31:13 -04:00
|
|
|
"time"
|
2019-11-06 11:38:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type LogEntry struct {
|
2020-06-10 15:31:13 -04:00
|
|
|
Time time.Time
|
|
|
|
RemoteAddr net.Addr
|
|
|
|
RequestURL string
|
|
|
|
Status int
|
2019-11-06 11:38:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func writeLogEntry(fp *os.File, entry LogEntry) {
|
|
|
|
var line string
|
2019-11-22 14:51:47 -05:00
|
|
|
line = entry.Time.Format(time.RFC3339)
|
2020-07-01 17:44:59 -04:00
|
|
|
// Trim port from remote address
|
|
|
|
addr := entry.RemoteAddr.String()
|
|
|
|
addr = addr[0:strings.LastIndex(addr, ":")]
|
|
|
|
line += "\t" + addr
|
2019-11-06 11:38:41 -05:00
|
|
|
line += "\t" + strconv.Itoa(entry.Status)
|
|
|
|
line += "\t" + entry.RequestURL
|
|
|
|
line += "\n"
|
|
|
|
fp.WriteString(line)
|
|
|
|
}
|