1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

Add logger

This commit is contained in:
Frédéric Guillot 2017-12-15 18:55:57 -08:00
parent c6d9eb3614
commit 1d8193b892
56 changed files with 228 additions and 192 deletions

View file

@ -6,9 +6,9 @@ package middleware
import (
"context"
"log"
"net/http"
"github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/storage"
)
@ -25,14 +25,14 @@ func (b *BasicAuthMiddleware) Handler(next http.Handler) http.Handler {
username, password, authOK := r.BasicAuth()
if !authOK {
log.Println("[Middleware:BasicAuth] No authentication headers sent")
logger.Debug("[Middleware:BasicAuth] No authentication headers sent")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(errorResponse))
return
}
if err := b.store.CheckPassword(username, password); err != nil {
log.Println("[Middleware:BasicAuth] Invalid username or password:", username)
logger.Info("[Middleware:BasicAuth] Invalid username or password: %s", username)
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(errorResponse))
return
@ -40,13 +40,13 @@ func (b *BasicAuthMiddleware) Handler(next http.Handler) http.Handler {
user, err := b.store.UserByUsername(username)
if err != nil || user == nil {
log.Println("[Middleware:BasicAuth] User not found:", username)
logger.Info("[Middleware:BasicAuth] User not found: %s", username)
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(errorResponse))
return
}
log.Println("[Middleware:BasicAuth] User authenticated:", username)
logger.Info("[Middleware:BasicAuth] User authenticated: %s", username)
b.store.SetLastLogin(user.ID)
ctx := r.Context()