logging improved
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
func email(id, text string) error {
|
||||
smtpServer := os.Getenv("SMTP_SERVER")
|
||||
fmt.Println("DEBUG", smtpServer)
|
||||
auth := smtp.PlainAuth("", os.Getenv("SMTP_USER"), os.Getenv("SMTP_PASSWORD"), smtpServer)
|
||||
to := []string{os.Getenv("NOTEHUB_ADMIN_EMAIL")}
|
||||
msg := []byte("Subject: note reported\r\n\r\n" +
|
||||
|
||||
@@ -67,10 +67,10 @@ func md2html(c echo.Context, name string) (*Note, int) {
|
||||
path := "assets/markdown/" + name + ".md"
|
||||
mdContent, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
c.Logger().Errorf("couldn't open markdown page %q: %v", path, err)
|
||||
c.Logger().Errorf("couldn't open markdown page %s: %v", path, err)
|
||||
code := http.StatusServiceUnavailable
|
||||
return responsePage(code), code
|
||||
}
|
||||
c.Logger().Debugf("rendering markdown page %q", name)
|
||||
c.Logger().Debugf("rendering markdown page %s", name)
|
||||
return &Note{Title: name, Content: mdTmplHTML(mdContent)}, http.StatusOK
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
var err error
|
||||
ads, err = ioutil.ReadFile(adsFName)
|
||||
if err != nil {
|
||||
e.Logger.Errorf("couldn't read file %q: %v", adsFName, err)
|
||||
e.Logger.Errorf("couldn't read file %s: %v", adsFName, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ func main() {
|
||||
if fraudelent(n) {
|
||||
n.Ads = mdTmplHTML(ads)
|
||||
}
|
||||
c.Logger().Debugf("/%q requested; response code: %d", n.ID, code)
|
||||
c.Logger().Debugf("/%s requested; response code: %d", n.ID, code)
|
||||
return c.Render(code, "Note", n)
|
||||
})
|
||||
|
||||
e.GET("/:id/export", func(c echo.Context) error {
|
||||
n, code := load(c, db)
|
||||
c.Logger().Debugf("/%q/export requested; response code: %d", n.ID, code)
|
||||
c.Logger().Debugf("/%s/export requested; response code: %d", n.ID, code)
|
||||
return c.String(code, n.Text)
|
||||
})
|
||||
|
||||
@@ -94,13 +94,13 @@ func main() {
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
e.Renderer.Render(buf, "Stats", n, c)
|
||||
n.Content = template.HTML(buf.String())
|
||||
c.Logger().Debugf("/%q/stats requested; response code: %d", n.ID, code)
|
||||
c.Logger().Debugf("/%s/stats requested; response code: %d", n.ID, code)
|
||||
return c.Render(code, "Note", n)
|
||||
})
|
||||
|
||||
e.GET("/:id/edit", func(c echo.Context) error {
|
||||
n, code := load(c, db)
|
||||
c.Logger().Debugf("/%q/edit requested; response code: %d", n.ID, code)
|
||||
c.Logger().Debugf("/%s/edit requested; response code: %d", n.ID, code)
|
||||
return c.Render(code, "Form", n)
|
||||
})
|
||||
|
||||
@@ -146,7 +146,7 @@ func main() {
|
||||
c.Logger().Errorf("POST /note error: %d", code)
|
||||
return c.Render(code, "Note", responsePage(code, err.Error()))
|
||||
}
|
||||
c.Logger().Debugf("note %q saved", n.ID)
|
||||
c.Logger().Debugf("note %s saved", n.ID)
|
||||
return c.Redirect(http.StatusMovedPermanently, "/"+n.ID)
|
||||
})
|
||||
|
||||
|
||||
+5
-5
@@ -41,7 +41,7 @@ func save(c echo.Context, db *sql.DB, n *Note) (*Note, error) {
|
||||
}
|
||||
|
||||
func update(c echo.Context, db *sql.DB, n *Note) (*Note, error) {
|
||||
c.Logger().Debugf("updating note %q", n.ID)
|
||||
c.Logger().Debugf("updating note %s", n.ID)
|
||||
if n.Password == "" {
|
||||
return nil, errorBadRequest
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func update(c echo.Context, db *sql.DB, n *Note) (*Note, error) {
|
||||
tx.Rollback()
|
||||
return nil, errorUnathorised
|
||||
}
|
||||
c.Logger().Debugf("updating note %q; committing transaction", n.ID)
|
||||
c.Logger().Debugf("updating note %s; committing transaction", n.ID)
|
||||
return n, tx.Commit()
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ func insert(c echo.Context, db *sql.DB, n *Note) (*Note, error) {
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
if strings.HasPrefix(err.Error(), "UNIQUE constraint failed") {
|
||||
c.Logger().Infof("collision on id %q", id)
|
||||
c.Logger().Infof("collision on id %s", id)
|
||||
return save(c, db, n)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
n.ID = id
|
||||
c.Logger().Debugf("inserting new note %q; commiting transaction", n.ID)
|
||||
c.Logger().Debugf("inserting new note %s; commiting transaction", n.ID)
|
||||
return n, tx.Commit()
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func randId() string {
|
||||
|
||||
func load(c echo.Context, db *sql.DB) (*Note, int) {
|
||||
q := c.Param("id")
|
||||
c.Logger().Debugf("loading note %q", q)
|
||||
c.Logger().Debugf("loading note %s", q)
|
||||
stmt, _ := db.Prepare("select * from notes where id = ?")
|
||||
defer stmt.Close()
|
||||
row := stmt.QueryRow(q)
|
||||
|
||||
Reference in New Issue
Block a user