Implemented logging to file

This commit is contained in:
Jason Streifling 2024-02-24 11:41:01 +01:00
parent 280e88a526
commit f3c8cd6fa5
2 changed files with 15 additions and 2 deletions

View File

@ -16,12 +16,15 @@ func HandleLogin(db *data.DB) http.HandlerFunc {
id, err := db.GetID(user)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
// TODO: und nun?
return
}
if err := db.CheckPassword(id, pass); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else {
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
}
@ -36,8 +39,9 @@ func HandleFinishedEdit(f *feed.Feed) http.HandlerFunc {
content, err := data.ConvertToHTML(mdContent)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Panicln(err)
return
}
feed.AddToFeed(f, title, desc, content)
@ -92,6 +96,7 @@ func HandleAddUser(db *data.DB) http.HandlerFunc {
if err := db.AddUser(user, pass, first, last, writer, editor, admin); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
template.Must(template.ParseFiles("web/templates/editor.html")).Execute(w, nil)
}

View File

@ -4,6 +4,7 @@ import (
"html/template"
"log"
"net/http"
"os"
"streifling.com/jason/cpolis/cmd/data"
"streifling.com/jason/cpolis/cmd/feed"
@ -11,6 +12,13 @@ import (
)
func main() {
logFile, err := os.Create("tmp/cpolis.log")
if err != nil {
log.Fatalln(err)
}
defer logFile.Close()
log.SetOutput(logFile)
db, err := data.OpenDB("cpolis")
if err != nil {
log.Fatalln(err)