refactor(logger): add individual log module

This commit is contained in:
2026-02-26 11:56:35 +08:00
parent 3d6f657242
commit 3c2a2fd826
4 changed files with 119 additions and 23 deletions
+5 -5
View File
@@ -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 {