增加日志输出
This commit is contained in:
parent
e2d8ab882b
commit
e1d0017257
|
@ -3,6 +3,7 @@ package async
|
|||
import (
|
||||
"blog/third_party/database"
|
||||
"context"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -15,6 +16,7 @@ type ViewRecord struct {
|
|||
ViewTime int64 `json:"viewTime"`
|
||||
IpAddr string `json:"ipAddr"`
|
||||
RelId string `json:"relId"`
|
||||
Title string `json:"title" gorm:"-"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -23,6 +25,7 @@ func init() {
|
|||
go func() {
|
||||
|
||||
for record := range viewRecordChannel {
|
||||
log.Println("IP:", record.IpAddr, "点击了:", record.Title)
|
||||
relId := record.RelId
|
||||
record.Id = uuid.NewString()
|
||||
database.GormTemplate.Table("blog_view_record").Create(&record)
|
||||
|
|
|
@ -53,7 +53,7 @@ func (ctrl *ArticleController) ViewArticle() {
|
|||
return
|
||||
}
|
||||
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
||||
async.PublishViewRecord(async.ViewRecord{RelId: articleId, IpAddr: xFrowardedFor, ViewTime: time.Now().UnixMilli()})
|
||||
async.PublishViewRecord(async.ViewRecord{RelId: articleId, IpAddr: xFrowardedFor, ViewTime: time.Now().UnixMilli(), Title: article.Title})
|
||||
|
||||
content := service.ContentService.GetContentByCache(articleId)
|
||||
ctrl.Ctx.ViewData("article", article)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"blog/internal/model/admin"
|
||||
"blog/third_party/database"
|
||||
"image/color"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
|
@ -92,5 +93,7 @@ func (ctrl *LoginController) Post() {
|
|||
newSession.Set("user", user)
|
||||
ctrl.Ctx.SetCookieKV("session_id_cookie", newSession.ID())
|
||||
|
||||
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
||||
log.Println("用户:", user.Username, "登录,IP为:", xFrowardedFor)
|
||||
ctrl.Ctx.JSON(AjaxResult.Ok("login"))
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -26,7 +26,6 @@ import (
|
|||
func main() {
|
||||
profile := os.Getenv("profile")
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC | log.Llongfile)
|
||||
log.Println("Go Iris 启动")
|
||||
app := iris.Default()
|
||||
app.FallbackView(iris.FallbackView("404.html"))
|
||||
app.HandleDir("/assets", iris.Dir("./assets"))
|
||||
|
@ -43,6 +42,7 @@ func main() {
|
|||
log.SetOutput(logFile)
|
||||
profile = "prod"
|
||||
}
|
||||
log.Println("Go Iris 启动")
|
||||
log.Println("当前环境是:", profile)
|
||||
|
||||
app.OnErrorCode(http.StatusNotFound, func(ctx iris.Context) {
|
||||
|
|
Loading…
Reference in New Issue