refactor(logger): add individual log module
This commit is contained in:
+5
-5
@@ -5,9 +5,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"super-frpc/modules"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -173,7 +173,7 @@ func SendErrorResponse(w http.ResponseWriter, statusCode int, message string) {
|
||||
}
|
||||
jsonResp, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
log.Printf("failed to marshal error response: %v", err)
|
||||
postLog.Error(fmt.Sprintf("failed to marshal error response: %v", err))
|
||||
return
|
||||
}
|
||||
w.Write(jsonResp)
|
||||
@@ -189,7 +189,7 @@ func SendSuccessResponse(w http.ResponseWriter, message string, data interface{}
|
||||
}
|
||||
jsonResp, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
log.Printf("failed to marshal success response: %v", err)
|
||||
postLog.Error(fmt.Sprintf("failed to marshal success response: %v", err))
|
||||
return
|
||||
}
|
||||
w.Write(jsonResp)
|
||||
@@ -276,13 +276,13 @@ func GetClientIP(r *http.Request) string {
|
||||
}
|
||||
|
||||
func LogRequest(r *http.Request, userID int) {
|
||||
log.Printf("[%s] %s %s - UserID: %d - IP: %s",
|
||||
postLog.Info(fmt.Sprintf("[%s] %s %s - UserID: %d - IP: %s",
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
r.Method,
|
||||
r.URL.Path,
|
||||
userID,
|
||||
GetClientIP(r),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
func IntToString(i int) string {
|
||||
|
||||
Reference in New Issue
Block a user