fix: Corrected log format

This commit is contained in:
2024-12-17 17:03:16 +08:00
parent 9386306e7e
commit 7920e7c5a0
3 changed files with 19 additions and 7 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
# Work dir and files # Work dir and files
*.log
.idea .idea
tmp tmp

View File

@@ -1,13 +1,12 @@
package mApp package mApp
import ( import (
"MollyBlog/config"
"MollyBlog/internal/model"
"fmt" "fmt"
"html/template" "html/template"
"log" "log"
"MollyBlog/config"
"MollyBlog/internal/model"
"github.com/88250/lute" "github.com/88250/lute"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/huichen/wukong/engine" "github.com/huichen/wukong/engine"
@@ -40,11 +39,19 @@ const (
DST = "_post/dst" // destination html files DST = "_post/dst" // destination html files
) )
func init() {
log.SetPrefix("[MollyBlog] ")
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
gin.SetMode(gin.ReleaseMode)
}
func (ma *MApp) Run() { func (ma *MApp) Run() {
ma.loadRoutes() ma.loadRoutes()
ma.loadTemplates() ma.loadTemplates()
addr := fmt.Sprintf("%s:%d", ma.Host, ma.Port) addr := fmt.Sprintf("%s:%d", ma.Host, ma.Port)
log.Printf("mApp listening on %s\n", addr)
err := ma.engine.Run(addr) err := ma.engine.Run(addr)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -52,8 +59,8 @@ func (ma *MApp) Run() {
} }
func NewMApp(cfg *config.MConfig) *MApp { func NewMApp(cfg *config.MConfig) *MApp {
engine := gin.Default() _engine := gin.Default()
engine.SetFuncMap(template.FuncMap{ _engine.SetFuncMap(template.FuncMap{
"add": func(a, b int) int { "add": func(a, b int) int {
return a + b return a + b
}, },
@@ -76,7 +83,7 @@ func NewMApp(cfg *config.MConfig) *MApp {
CategorizedPosts: make(map[string][]*model.MPost), CategorizedPosts: make(map[string][]*model.MPost),
lute: lute.New(), lute: lute.New(),
engine: engine, engine: _engine,
} }
} }

View File

@@ -3,9 +3,9 @@ package mApp
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/huichen/wukong/types"
"html/template" "html/template"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@@ -15,6 +15,7 @@ import (
"MollyBlog/utils" "MollyBlog/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/huichen/wukong/types"
) )
func (ma *MApp) IndexHandler(ctx *gin.Context) { func (ma *MApp) IndexHandler(ctx *gin.Context) {
@@ -407,12 +408,14 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
err = ma.loadMarkdownFiles() err = ma.loadMarkdownFiles()
if err != nil { if err != nil {
log.Printf("load markdown files failed, err:%v\n", err)
_ = ctx.Error(err) _ = ctx.Error(err)
return return
} }
err = ma.parseMarkdowns() err = ma.parseMarkdowns()
if err != nil { if err != nil {
log.Printf("parse markdown files failed, err:%v\n", err)
_ = ctx.Error(err) _ = ctx.Error(err)
return return
} }
@@ -420,5 +423,6 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
// parse post index // parse post index
ma.loadPostIndex() ma.loadPostIndex()
log.Println("update blog success")
ctx.JSON(http.StatusOK, gin.H{"msg": "ok"}) ctx.JSON(http.StatusOK, gin.H{"msg": "ok"})
} }