mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add logger
This commit is contained in:
parent
c6d9eb3614
commit
1d8193b892
56 changed files with 228 additions and 192 deletions
|
@ -5,9 +5,9 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
"github.com/miniflux/miniflux/server/middleware"
|
||||
"github.com/miniflux/miniflux/server/route"
|
||||
|
@ -63,11 +63,11 @@ func (c *Context) LoggedUser() *model.User {
|
|||
var err error
|
||||
c.user, err = c.store.UserByID(c.UserID())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
logger.Fatal("[Context] %v", err)
|
||||
}
|
||||
|
||||
if c.user == nil {
|
||||
log.Fatalln("Unable to find user from context")
|
||||
logger.Fatal("Unable to find user from context")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (c *Context) CsrfToken() string {
|
|||
return v.(string)
|
||||
}
|
||||
|
||||
log.Println("No CSRF token in context!")
|
||||
logger.Error("No CSRF token in context!")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/helper"
|
||||
"github.com/miniflux/miniflux/locale"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/server/middleware"
|
||||
"github.com/miniflux/miniflux/server/template"
|
||||
"github.com/miniflux/miniflux/storage"
|
||||
|
@ -34,7 +34,7 @@ type Handler struct {
|
|||
func (h *Handler) Use(f HandlerFunc) http.Handler {
|
||||
return h.middleware.WrapFunc(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer helper.ExecutionTime(time.Now(), r.URL.Path)
|
||||
log.Println(r.Method, r.URL.Path)
|
||||
logger.Debug("[HTTP] %s %s", r.Method, r.URL.Path)
|
||||
|
||||
ctx := NewContext(w, r, h.store, h.router)
|
||||
request := NewRequest(w, r)
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/server/template"
|
||||
)
|
||||
|
||||
|
@ -30,7 +30,7 @@ func (h *HTMLResponse) ServerError(err error) {
|
|||
h.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logger.Error("[Internal Server Error] %v", err)
|
||||
h.writer.Write([]byte("Internal Server Error: " + err.Error()))
|
||||
} else {
|
||||
h.writer.Write([]byte("Internal Server Error"))
|
||||
|
@ -43,7 +43,7 @@ func (h *HTMLResponse) BadRequest(err error) {
|
|||
h.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logger.Error("[Bad Request] %v", err)
|
||||
h.writer.Write([]byte("Bad Request: " + err.Error()))
|
||||
} else {
|
||||
h.writer.Write([]byte("Bad Request"))
|
||||
|
|
|
@ -7,8 +7,9 @@ package core
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
)
|
||||
|
||||
// JSONResponse handles JSON responses.
|
||||
|
@ -39,7 +40,7 @@ func (j *JSONResponse) NoContent() {
|
|||
|
||||
// BadRequest sends a JSON response with the status code 400.
|
||||
func (j *JSONResponse) BadRequest(err error) {
|
||||
log.Println("[API:BadRequest]", err)
|
||||
logger.Error("[Bad Request] %v", err)
|
||||
j.writer.WriteHeader(http.StatusBadRequest)
|
||||
j.commonHeaders()
|
||||
|
||||
|
@ -50,7 +51,7 @@ func (j *JSONResponse) BadRequest(err error) {
|
|||
|
||||
// NotFound sends a JSON response with the status code 404.
|
||||
func (j *JSONResponse) NotFound(err error) {
|
||||
log.Println("[API:NotFound]", err)
|
||||
logger.Error("[Not Found] %v", err)
|
||||
j.writer.WriteHeader(http.StatusNotFound)
|
||||
j.commonHeaders()
|
||||
j.writer.Write(j.encodeError(err))
|
||||
|
@ -58,7 +59,7 @@ func (j *JSONResponse) NotFound(err error) {
|
|||
|
||||
// ServerError sends a JSON response with the status code 500.
|
||||
func (j *JSONResponse) ServerError(err error) {
|
||||
log.Println("[API:ServerError]", err)
|
||||
logger.Error("[Internal Server Error] %v", err)
|
||||
j.writer.WriteHeader(http.StatusInternalServerError)
|
||||
j.commonHeaders()
|
||||
|
||||
|
@ -69,7 +70,7 @@ func (j *JSONResponse) ServerError(err error) {
|
|||
|
||||
// Forbidden sends a JSON response with the status code 403.
|
||||
func (j *JSONResponse) Forbidden() {
|
||||
log.Println("[API:Forbidden]")
|
||||
logger.Info("[API:Forbidden]")
|
||||
j.writer.WriteHeader(http.StatusForbidden)
|
||||
j.commonHeaders()
|
||||
j.writer.Write(j.encodeError(errors.New("Access Forbidden")))
|
||||
|
@ -88,7 +89,7 @@ func (j *JSONResponse) encodeError(err error) []byte {
|
|||
tmp := errorMsg{ErrorMessage: err.Error()}
|
||||
data, err := json.Marshal(tmp)
|
||||
if err != nil {
|
||||
log.Println("encodeError:", err)
|
||||
logger.Error("encoding error: %v", err)
|
||||
}
|
||||
|
||||
return data
|
||||
|
@ -97,7 +98,7 @@ func (j *JSONResponse) encodeError(err error) []byte {
|
|||
func (j *JSONResponse) toJSON(v interface{}) []byte {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
log.Println("Unable to convert interface to JSON:", err)
|
||||
logger.Error("encoding error: %v", err)
|
||||
return []byte("")
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ package core
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
)
|
||||
|
||||
// Request is a thin wrapper around "http.Request".
|
||||
|
@ -68,7 +68,7 @@ func (r *Request) IntegerParam(param string) (int64, error) {
|
|||
vars := mux.Vars(r.request)
|
||||
value, err := strconv.Atoi(vars[param])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
logger.Error("[IntegerParam] %v", err)
|
||||
return 0, fmt.Errorf("%s parameter is not an integer", param)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue