1
1
Fork 0
mirror of https://tildegit.org/solderpunk/molly-brown synced 2024-05-27 13:46:04 +02:00
molly-brown/logging.go

30 lines
529 B
Go
Raw Normal View History

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