feat: Use reqData to load log info

This commit is contained in:
Roi Feng
2025-04-28 21:52:42 -04:00
parent c0524c56e7
commit af4af7346a
3 changed files with 19 additions and 22 deletions

View File

@ -1,7 +1,5 @@
package dataType
import "server_torii/internal/utils"
type UserRequest struct {
RemoteIP string
Uri string
@ -36,5 +34,4 @@ type HTTPFloodRule struct {
type SharedMemory struct {
HTTPFloodSpeedLimitCounter *Counter
HTTPFloodSameURILimitCounter *Counter
Logger *utils.LogxManager
}

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"path/filepath"
"server_torii/internal/dataType"
"sync"
"time"
@ -71,43 +72,43 @@ func (m *LogxManager) openLogFile(path string) *os.File {
return f
}
func (m *LogxManager) LogInfo(ip, host, uri, ua, msg, msg2 string) {
lg := m.getLogger(host)
func (m *LogxManager) LogInfo(reqData dataType.UserRequest, msg, msg2 string) {
lg := m.getLogger(reqData.Host)
line := fmt.Sprintf("%s - - [%s] %s %s %s %s %s",
ip,
reqData.RemoteIP,
time.Now().Format("02/Jan/2006:15:04:05 -0700"),
msg,
host,
uri,
ua,
reqData.Host,
reqData.Uri,
reqData.UserAgent,
msg2,
)
lg.Info(line)
}
func (m *LogxManager) LogError(ip, host, uri, ua, msg, msg2 string) {
lg := m.getLogger(host)
func (m *LogxManager) LogError(reqData dataType.UserRequest, msg, msg2 string) {
lg := m.getLogger(reqData.Host)
line := fmt.Sprintf("%s - - [%s] %s %s %s %s %s",
ip,
reqData.RemoteIP,
time.Now().Format("02/Jan/2006:15:04:05 -0700"),
msg,
host,
uri,
ua,
reqData.Host,
reqData.Uri,
reqData.UserAgent,
msg2,
)
lg.Error(line)
}
func (m *LogxManager) LogDebug(ip, host, uri, ua, msg, msg2 string) {
lg := m.getLogger(host)
func (m *LogxManager) LogDebug(reqData dataType.UserRequest, msg, msg2 string) {
lg := m.getLogger(reqData.Host)
line := fmt.Sprintf("%s - - [%s] %s %s %s %s %s",
ip,
reqData.RemoteIP,
time.Now().Format("02/Jan/2006:15:04:05 -0700"),
msg,
host,
uri,
ua,
reqData.Host,
reqData.Uri,
reqData.UserAgent,
msg2,
)
lg.Debug(line)