all repos — flounder @ 13bb0d3c427d66d8d1e717fd5a4bc59bac5088bf

A small site builder for the Gemini protocol

Improve gemini log formatting
alex wennerberg alex@alexwennerberg.com
Sat, 02 Jan 2021 10:54:34 -0800
commit

13bb0d3c427d66d8d1e717fd5a4bc59bac5088bf

parent

2dff9268624c71e83dc10145e6eb29058f3f0fb2

2 files changed, 14 insertions(+), 2 deletions(-)

jump to
M gemini.gogemini.go

@@ -53,7 +53,7 @@ return buff.String()

} func gmiIndex(w *gmi.ResponseWriter, r *gmi.Request) { - log.Println("Index request") + logGemini(r) // TODO move into wrapper t, err := template.ParseFiles("templates/index.gmi") if err != nil { log.Fatal(err)

@@ -79,6 +79,7 @@ t.Execute(w, data)

} func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { + logGemini(r) // TODO move into wrapper userName := filepath.Clean(strings.Split(r.URL.Host, ".")[0]) // clean probably unnecessary fileName := filepath.Clean(r.URL.Path) if fileName == "/" {

@@ -87,7 +88,6 @@ } else if strings.HasPrefix(fileName, "/"+HiddenFolder) {

w.WriteStatus(gmi.StatusNotFound) return } - log.Println("Request for gemini file", fileName, "for user", userName) fullPath := path.Join(c.FilesDirectory, userName, fileName) if fileName == "/gemlog" { // temp hack _, err := os.Stat(path.Join(fullPath, "index.gmi"))
M log.golog.go

@@ -1,8 +1,11 @@

package main import ( + "fmt" + gmi "git.sr.ht/~adnano/go-gemini" "github.com/gorilla/handlers" "io" + "log" "net" "net/http" "net/url"

@@ -144,3 +147,12 @@

// Parse logs and write to database // Anonymize user and IP? + +func logGemini(r *gmi.Request) { + line := fmt.Sprintf("gemini %s - [%s] %s %s\n", r.RemoteAddr.String(), + time.Now().Format("02/Jan/2006:15:04:05 -0700"), + r.URL.Host, + r.URL.Path) + buf := []byte(line) + log.Writer().Write(buf) +}