mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-02 06:48:49 +01:00
♻️ 日志组件单独抽取项目 https://github.com/siyuan-note/siyuan/issues/5439
This commit is contained in:
parent
c8ea858976
commit
505b973c2d
70 changed files with 671 additions and 942 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/88250/lute/html"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -285,7 +286,7 @@ func getBlockInfo(c *gin.Context) {
|
|||
break
|
||||
}
|
||||
if b, _ = model.GetBlock(parentID); nil == b {
|
||||
util.LogErrorf("not found parent")
|
||||
logging.LogErrorf("not found parent")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -48,7 +49,7 @@ func extensionCopy(c *gin.Context) {
|
|||
}
|
||||
|
||||
if err := os.MkdirAll(assets, 0755); nil != err {
|
||||
util.LogErrorf("create assets folder [%s] failed: %s", assets, err)
|
||||
logging.LogErrorf("create assets folder [%s] failed: %s", assets, err)
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -49,12 +50,12 @@ func getFile(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
if info.IsDir() {
|
||||
util.LogErrorf("file [%s] is a directory", filePath)
|
||||
logging.LogErrorf("file [%s] is a directory", filePath)
|
||||
c.Status(405)
|
||||
return
|
||||
}
|
||||
|
|
@ -78,28 +79,28 @@ func putFile(c *gin.Context) {
|
|||
if isDir {
|
||||
err = os.MkdirAll(filePath, 0755)
|
||||
if nil != err {
|
||||
util.LogErrorf("make a dir [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf("make a dir [%s] failed: %s", filePath, err)
|
||||
}
|
||||
} else {
|
||||
file, _ := c.FormFile("file")
|
||||
if nil == file {
|
||||
util.LogErrorf("form file is nil [path=%s]", filePath)
|
||||
logging.LogErrorf("form file is nil [path=%s]", filePath)
|
||||
c.Status(400)
|
||||
return
|
||||
}
|
||||
|
||||
dir := filepath.Dir(filePath)
|
||||
if err = os.MkdirAll(dir, 0755); nil != err {
|
||||
util.LogErrorf("put a file [%s] make dir [%s] failed: %s", filePath, dir, err)
|
||||
logging.LogErrorf("put a file [%s] make dir [%s] failed: %s", filePath, dir, err)
|
||||
} else {
|
||||
if filelock.IsLocked(filePath) {
|
||||
msg := fmt.Sprintf("file [%s] is locked", filePath)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
err = errors.New(msg)
|
||||
} else {
|
||||
err = writeFile(file, filePath)
|
||||
if nil != err {
|
||||
util.LogErrorf("put a file [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf("put a file [%s] failed: %s", filePath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,13 +114,13 @@ func putFile(c *gin.Context) {
|
|||
modTimeStr := c.PostForm("modTime")
|
||||
modTimeInt, err := strconv.ParseInt(modTimeStr, 10, 64)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse mod time [%s] failed: %s", modTimeStr, err)
|
||||
logging.LogErrorf("parse mod time [%s] failed: %s", modTimeStr, err)
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
modTime := millisecond2Time(modTimeInt)
|
||||
if err = os.Chtimes(filePath, modTime, modTime); nil != err {
|
||||
util.LogErrorf("change time failed: %s", err)
|
||||
logging.LogErrorf("change time failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -34,7 +35,7 @@ func importSY(c *gin.Context) {
|
|||
|
||||
form, err := c.MultipartForm()
|
||||
if nil != err {
|
||||
util.LogErrorf("parse import .sy.zip failed: %s", err)
|
||||
logging.LogErrorf("parse import .sy.zip failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -42,7 +43,7 @@ func importSY(c *gin.Context) {
|
|||
|
||||
files := form.File["file"]
|
||||
if 1 > len(files) {
|
||||
util.LogErrorf("parse import .sy.zip failed: %s", err)
|
||||
logging.LogErrorf("parse import .sy.zip failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -50,7 +51,7 @@ func importSY(c *gin.Context) {
|
|||
file := files[0]
|
||||
reader, err := file.Open()
|
||||
if nil != err {
|
||||
util.LogErrorf("read import .sy.zip failed: %s", err)
|
||||
logging.LogErrorf("read import .sy.zip failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -58,7 +59,7 @@ func importSY(c *gin.Context) {
|
|||
|
||||
importDir := filepath.Join(util.TempDir, "import")
|
||||
if err = os.MkdirAll(importDir, 0755); nil != err {
|
||||
util.LogErrorf("make import dir [%s] failed: %s", importDir, err)
|
||||
logging.LogErrorf("make import dir [%s] failed: %s", importDir, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -67,13 +68,13 @@ func importSY(c *gin.Context) {
|
|||
defer os.RemoveAll(writePath)
|
||||
writer, err := os.OpenFile(writePath, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if nil != err {
|
||||
util.LogErrorf("open import .sy.zip [%s] failed: %s", writePath, err)
|
||||
logging.LogErrorf("open import .sy.zip [%s] failed: %s", writePath, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
if _, err = io.Copy(writer, reader); nil != err {
|
||||
util.LogErrorf("write import .sy.zip failed: %s", err)
|
||||
logging.LogErrorf("write import .sy.zip failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -98,14 +99,14 @@ func importData(c *gin.Context) {
|
|||
|
||||
form, err := c.MultipartForm()
|
||||
if nil != err {
|
||||
util.LogErrorf("import data failed: %s", err)
|
||||
logging.LogErrorf("import data failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
if 1 > len(form.File["file"]) {
|
||||
util.LogErrorf("import data failed: %s", err)
|
||||
logging.LogErrorf("import data failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = "file not found"
|
||||
return
|
||||
|
|
@ -122,7 +123,7 @@ func importData(c *gin.Context) {
|
|||
defer os.RemoveAll(dataZipPath)
|
||||
dataZipFile, err := os.Create(dataZipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("create temp file failed: %s", err)
|
||||
logging.LogErrorf("create temp file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = "create temp file failed"
|
||||
return
|
||||
|
|
@ -130,20 +131,20 @@ func importData(c *gin.Context) {
|
|||
file := form.File["file"][0]
|
||||
fileReader, err := file.Open()
|
||||
if nil != err {
|
||||
util.LogErrorf("open upload file failed: %s", err)
|
||||
logging.LogErrorf("open upload file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = "open file failed"
|
||||
return
|
||||
}
|
||||
_, err = io.Copy(dataZipFile, fileReader)
|
||||
if nil != err {
|
||||
util.LogErrorf("read upload file failed: %s", err)
|
||||
logging.LogErrorf("read upload file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = "read file failed"
|
||||
return
|
||||
}
|
||||
if err = dataZipFile.Close(); nil != err {
|
||||
util.LogErrorf("close file failed: %s", err)
|
||||
logging.LogErrorf("close file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = "close file failed"
|
||||
return
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/88250/lute/render"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -112,7 +113,7 @@ func html2BlockDOM(c *gin.Context) {
|
|||
name = name + "-" + ast.NewNodeID() + ext
|
||||
targetPath := filepath.Join(util.DataDir, "assets", name)
|
||||
if err = gulu.File.CopyFile(localPath, targetPath); nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", localPath, targetPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", localPath, targetPath, err)
|
||||
return ast.WalkStop
|
||||
}
|
||||
n.Tokens = gulu.Str.ToBytes("assets/" + name)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -38,7 +39,7 @@ func getEmojiConf(c *gin.Context) {
|
|||
builtConfPath := filepath.Join(util.AppearancePath, "emojis", "conf.json")
|
||||
data, err := os.ReadFile(builtConfPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read emojis conf.json failed: %s", err)
|
||||
logging.LogErrorf("read emojis conf.json failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -46,7 +47,7 @@ func getEmojiConf(c *gin.Context) {
|
|||
|
||||
var conf []map[string]interface{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &conf); nil != err {
|
||||
util.LogErrorf("unmarshal emojis conf.json failed: %s", err)
|
||||
logging.LogErrorf("unmarshal emojis conf.json failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -64,7 +65,7 @@ func getEmojiConf(c *gin.Context) {
|
|||
model.CustomEmojis = sync.Map{}
|
||||
customEmojis, err := os.ReadDir(customConfDir)
|
||||
if nil != err {
|
||||
util.LogErrorf("read custom emojis failed: %s", err)
|
||||
logging.LogErrorf("read custom emojis failed: %s", err)
|
||||
} else {
|
||||
for _, customEmoji := range customEmojis {
|
||||
name := customEmoji.Name()
|
||||
|
|
@ -76,7 +77,7 @@ func getEmojiConf(c *gin.Context) {
|
|||
// 子级
|
||||
subCustomEmojis, err := os.ReadDir(filepath.Join(customConfDir, name))
|
||||
if nil != err {
|
||||
util.LogErrorf("read custom emojis failed: %s", err)
|
||||
logging.LogErrorf("read custom emojis failed: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -78,12 +79,12 @@ func performTransactions(c *gin.Context) {
|
|||
if nil != err {
|
||||
tx, txErr := sql.BeginTx()
|
||||
if nil != txErr {
|
||||
util.LogFatalf("transaction failed: %s", txErr)
|
||||
logging.LogFatalf("transaction failed: %s", txErr)
|
||||
return
|
||||
}
|
||||
sql.ClearBoxHash(tx)
|
||||
sql.CommitTx(tx)
|
||||
util.LogFatalf("transaction failed: %s", err)
|
||||
logging.LogFatalf("transaction failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -39,7 +40,7 @@ func listWorkspaceDirs(c *gin.Context) {
|
|||
data, err := os.ReadFile(workspaceConf)
|
||||
var workspacePaths []string
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &workspacePaths); nil != err {
|
||||
util.LogErrorf("unmarshal workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
logging.LogErrorf("unmarshal workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
return
|
||||
}
|
||||
ret.Data = workspacePaths
|
||||
|
|
@ -76,10 +77,10 @@ func setWorkspaceDir(c *gin.Context) {
|
|||
workspaceConf := filepath.Join(util.HomeDir, ".config", "siyuan", "workspace.json")
|
||||
data, err := os.ReadFile(workspaceConf)
|
||||
if nil != err {
|
||||
util.LogErrorf("read workspace conf failed: %s", err)
|
||||
logging.LogErrorf("read workspace conf failed: %s", err)
|
||||
} else {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &workspacePaths); nil != err {
|
||||
util.LogErrorf("unmarshal workspace conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal workspace conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue