Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 支持导出系统日志文件 https://github.com/siyuan-note/siyuan/issues/5726

Liang Ding2a5212e15db6
diff --git a/kernel/api/router.go b/kernel/api/router.go
index e21c8d5d41..3c416a6f94 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -49,6 +49,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/setUILayout", model.CheckAuth, setUILayout)
ginServer.Handle("POST", "/api/system/getConf", model.CheckAuth, getConf)
ginServer.Handle("POST", "/api/system/checkUpdate", model.CheckAuth, checkUpdate)
+ ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, exportLog)
ginServer.Handle("POST", "/api/account/login", model.CheckAuth, login)
ginServer.Handle("POST", "/api/account/checkActivationcode", model.CheckAuth, checkActivationcode)
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 4f6b8fa10e..aaf7d136b3 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -131,6 +131,16 @@ func checkUpdate(c *gin.Context) {
model.CheckUpdate(showMsg)
}
+func exportLog(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ zipPath := model.ExportSystemLog()
+ ret.Data = map[string]interface{}{
+ "zip": zipPath,
+ }
+}
+
var start = true // 是否是启动
func getConf(c *gin.Context) {
ret := gulu.Ret.NewResult()
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 1a597aa2ab..c2d26b6813 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -47,6 +47,50 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
+func ExportSystemLog() (zipPath string) {
+ exportFolder := filepath.Join(util.TempDir, "export", "system-log")
+ os.RemoveAll(exportFolder)
+ if err := os.MkdirAll(exportFolder, 0755); nil != err {
+ logging.LogErrorf("create export temp folder failed: %s", err)
+ return
+ }
+
+ appLog := filepath.Join(util.HomeDir, ".config", "siyuan", "app.log")
+ if gulu.File.IsExist(appLog) {
+ to := filepath.Join(exportFolder, "app.log")
+ if err := gulu.File.CopyFile(appLog, to); nil != err {
+ logging.LogErrorf("copy app log from [%s] to [%s] failed: %s", err, appLog, to)
+ }
+ }
+ kernelLog := filepath.Join(util.TempDir, "siyuan.log")
+ if gulu.File.IsExist(kernelLog) {
+ to := filepath.Join(exportFolder, "siyuan.log")
+ if err := gulu.File.CopyFile(kernelLog, to); nil != err {
+ logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, kernelLog, to)
+ }
+ }
+
+ zipPath = exportFolder + ".zip"
+ zip, err := gulu.Zip.Create(zipPath)
+ if nil != err {
+ logging.LogErrorf("create export log zip [%s] failed: %s", exportFolder, err)
+ return ""
+ }
+
+ if err = zip.AddDirectory("log", exportFolder); nil != err {
+ logging.LogErrorf("create export log zip [%s] failed: %s", exportFolder, err)
+ return ""
+ }
+
+ if err = zip.Close(); nil != err {
+ logging.LogErrorf("close export log zip failed: %s", err)
+ }
+
+ os.RemoveAll(exportFolder)
+ zipPath = "/export/" + url.PathEscape(filepath.Base(zipPath))
+ return
+}
+
func ExportNotebookSY(id string) (zipPath string) {
zipPath = exportBoxSYZip(id)
return