docs: 更新图标并优化日志记录功能
- 更新侧边栏和文档页面的图标 - 评论静态文件请求的日志记录功能 - 增加东八区时区支持并优化日志时间格式
This commit is contained in:
parent
f09d7e8304
commit
4870d2aa42
@ -5,7 +5,7 @@ export default sidebar({
|
|||||||
"",
|
"",
|
||||||
{
|
{
|
||||||
text: "拓展",
|
text: "拓展",
|
||||||
icon: "laptop-code",
|
icon: "rainbow",
|
||||||
prefix: "expansion/",
|
prefix: "expansion/",
|
||||||
link: "expansion/",
|
link: "expansion/",
|
||||||
children: "structure",
|
children: "structure",
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
title: 译文
|
title: 译文
|
||||||
index: false
|
index: false
|
||||||
icon: laptop-code
|
icon: laptop-code
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
::: warning AI生成
|
::: warning AI生成
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
title: 拓展
|
title: 拓展
|
||||||
order: 1
|
order: 1
|
||||||
index: false
|
index: false
|
||||||
|
icon: rainbow
|
||||||
---
|
---
|
||||||
|
|
||||||
<Catalog />
|
<Catalog />
|
||||||
@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: 原文
|
title: 原文
|
||||||
index: false
|
index: false
|
||||||
|
icon: book
|
||||||
---
|
---
|
||||||
|
|
||||||
<Catalog />
|
<Catalog />
|
||||||
@ -44,8 +44,8 @@ func ServeIndex(db *gorm.DB) gin.HandlerFunc {
|
|||||||
// 处理静态文件请求
|
// 处理静态文件请求
|
||||||
func ServeStatic(db *gorm.DB) gin.HandlerFunc {
|
func ServeStatic(db *gorm.DB) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
userInfo := getUserInfo(c, db)
|
//userInfo := getUserInfo(c, db)
|
||||||
utils.LogAccess(c.ClientIP(), c.Request.URL.Path, c.Request.Method, userInfo)
|
//utils.LogAccess(c.ClientIP(), c.Request.URL.Path, c.Request.Method, userInfo)
|
||||||
filePath := "./static" + c.Request.URL.Path
|
filePath := "./static" + c.Request.URL.Path
|
||||||
if _, err := os.Stat(filePath); err == nil {
|
if _, err := os.Stat(filePath); err == nil {
|
||||||
http.ServeFile(c.Writer, c.Request, filePath)
|
http.ServeFile(c.Writer, c.Request, filePath)
|
||||||
|
|||||||
@ -28,11 +28,23 @@ func InitLogger() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LogAccess(ip, path, method string, userInfo map[string]interface{}) {
|
func LogAccess(ip, path, method string, userInfo map[string]interface{}) {
|
||||||
|
// 设置东八区时区
|
||||||
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||||
|
if err != nil {
|
||||||
|
Logger.WithError(err).Error("Failed to load timezone")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前时间并格式化为东八区时间,使用中国人的习惯格式
|
||||||
|
now := time.Now().In(loc)
|
||||||
|
timestamp := now.Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
// 构建日志字段
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"ip": ip,
|
"ip": ip,
|
||||||
"path": path,
|
"path": path,
|
||||||
"method": method,
|
"method": method,
|
||||||
"timestamp": time.Now().Format(time.RFC3339),
|
"timestamp": timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并用户信息到日志字段中
|
// 合并用户信息到日志字段中
|
||||||
@ -42,5 +54,6 @@ func LogAccess(ip, path, method string, userInfo map[string]interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
Logger.WithFields(fields).Info("Page accessed")
|
Logger.WithFields(fields).Info("Page accessed")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user