diff --git a/app/electron/main.js b/app/electron/main.js
index fc0196668..624d38241 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -473,9 +473,6 @@ const initKernel = (workspace, port, lang) => {
case 21:
errorWindowId = showErrorWindow("⚠️ 监听端口 " + currentKernelPort + " 失败 Failed to listen to port " + currentKernelPort, "
监听 " + currentKernelPort + " 端口失败,请确保程序拥有网络权限并不受防火墙和杀毒软件阻止。
Failed to listen to port " + currentKernelPort + ", please make sure the program has network permissions and is not blocked by firewalls and antivirus software.
");
break;
- case 22:
- errorWindowId = showErrorWindow("⚠️ 创建配置目录失败 Failed to create config directory", "思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。
SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.
");
- break;
case 24: // 工作空间已被锁定,尝试切换到第一个打开的工作空间
if (workspaces && 0 < workspaces.length) {
showWindow(workspaces[0].browserWindow);
@@ -484,7 +481,7 @@ const initKernel = (workspace, port, lang) => {
errorWindowId = showErrorWindow("⚠️ 工作空间已被锁定 The workspace is locked", "该工作空间正在被使用。
The workspace is in use.
");
break;
case 25:
- errorWindowId = showErrorWindow("⚠️ 创建工作空间目录失败 Failed to create workspace directory", "创建工作空间目录失败。
Failed to create workspace directory.
");
+ errorWindowId = showErrorWindow("⚠️ 初始化工作空间失败 Failed to create workspace directory", "初始化工作空间失败。
Failed to init workspace.
");
break;
case 26:
errorWindowId = showErrorWindow("⚠️ 文件系统读写错误 File system access error", "请检查文件系统权限,并确保没有其他程序正在读写文件;
请勿使用第三方同步盘进行数据同步,否则数据会被损坏(iCloud/OneDrive/Dropbox/Google Drive/坚果云/百度网盘/腾讯微云等)
Please check file system permissions and make sure no other programs are reading or writing to the file;
Do not use a third-party sync disk for data sync, otherwise the data will be damaged (OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)
");
diff --git a/kernel/go.mod b/kernel/go.mod
index b80529d9f..f0f31efd8 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -48,7 +48,7 @@ require (
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
github.com/siyuan-note/filelock v0.0.0-20230321113304-79a32917cc9f
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc
- github.com/siyuan-note/logging v0.0.0-20230319012246-6224f958f554
+ github.com/siyuan-note/logging v0.0.0-20230327034340-a7bed1fff2fe
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7
github.com/steambap/captcha v1.4.1
github.com/studio-b12/gowebdav v0.0.0-20230203202212-3282f94193f2
diff --git a/kernel/go.sum b/kernel/go.sum
index 6a8e9c0ba..d085a95bf 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -293,6 +293,10 @@ github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc h1:MX2cPWpn
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc/go.mod h1:WDO42mUVRnkk8M4AhZ4oakZ5jnghulP0c8NFCrrFWG4=
github.com/siyuan-note/logging v0.0.0-20230319012246-6224f958f554 h1:uaLbecIT6G7jFQUscXSzIxi/hDVSfzZccMCl8Lzqqn0=
github.com/siyuan-note/logging v0.0.0-20230319012246-6224f958f554/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
+github.com/siyuan-note/logging v0.0.0-20230327031937-fad01e626ac2 h1:RuByEVw3s+R4ch/n1Wd5uBn0Gd/PDqNae2QoYi/Q+vQ=
+github.com/siyuan-note/logging v0.0.0-20230327031937-fad01e626ac2/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
+github.com/siyuan-note/logging v0.0.0-20230327034340-a7bed1fff2fe h1:QmBB+8HVbjxXzVUdAiysYaClEAaREcxeZt6kvHcrFUc=
+github.com/siyuan-note/logging v0.0.0-20230327034340-a7bed1fff2fe/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7 h1:Kr8hhMhr6v+U24TMDCP5WdP4dWrXm5maar+TycTZs9I=
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7/go.mod h1:XJtLlKCr8cZE+lzykM4edHHih92M9M50UNw/nDLYRN8=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 4ef74b48d..51d2f5c81 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -174,14 +174,23 @@ func ExportSystemLog() (zipPath string) {
logging.LogErrorf("copy app log from [%s] to [%s] failed: %s", err, appLog, to)
}
}
- kernelLog := filepath.Join(util.TempDir, "siyuan.log")
+
+ kernelLog := filepath.Join(util.HomeDir, ".config", "siyuan", "kernel.log")
if gulu.File.IsExist(kernelLog) {
- to := filepath.Join(exportFolder, "siyuan.log")
+ to := filepath.Join(exportFolder, "kernel.log")
if err := gulu.File.CopyFile(kernelLog, to); nil != err {
logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, kernelLog, to)
}
}
+ siyuanLog := filepath.Join(util.TempDir, "siyuan.log")
+ if gulu.File.IsExist(siyuanLog) {
+ to := filepath.Join(exportFolder, "siyuan.log")
+ if err := gulu.File.CopyFile(siyuanLog, to); nil != err {
+ logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, siyuanLog, to)
+ }
+ }
+
zipPath = exportFolder + ".zip"
zip, err := gulu.Zip.Create(zipPath)
if nil != err {
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index 48a6f68eb..358c256d2 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -244,12 +244,11 @@ func checkFileSysStatus() {
}
func IsCloudDrivePath(workspaceAbsPath string) bool {
- absPathLower := strings.ToLower(workspaceAbsPath)
- if isICloudPath(absPathLower) {
+ if isICloudPath(workspaceAbsPath) {
return true
}
- if isKnownCloudDrivePath(absPathLower) {
+ if isKnownCloudDrivePath(workspaceAbsPath) {
return true
}
@@ -260,17 +259,20 @@ func IsCloudDrivePath(workspaceAbsPath string) bool {
return false
}
-func isKnownCloudDrivePath(workspaceAbsPathLower string) bool {
+func isKnownCloudDrivePath(workspaceAbsPath string) bool {
+ workspaceAbsPathLower := strings.ToLower(workspaceAbsPath)
return strings.Contains(workspaceAbsPathLower, "onedrive") || strings.Contains(workspaceAbsPathLower, "dropbox") ||
strings.Contains(workspaceAbsPathLower, "google drive") || strings.Contains(workspaceAbsPathLower, "pcloud") ||
strings.Contains(workspaceAbsPathLower, "坚果云")
}
-func isICloudPath(workspaceAbsPathLower string) (ret bool) {
+func isICloudPath(workspaceAbsPath string) (ret bool) {
if !gulu.OS.IsDarwin() {
return false
}
+ workspaceAbsPathLower := strings.ToLower(workspaceAbsPath)
+
// macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747
iCloudRoot := filepath.Join(HomeDir, "Library", "Mobile Documents")
WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error {
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 691b7a806..770ff5561 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -21,7 +21,6 @@ import (
"errors"
"flag"
"fmt"
- "log"
"math/rand"
"mime"
"os"
@@ -186,10 +185,12 @@ var (
func initWorkspaceDir(workspaceArg string) {
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
+ logging.SetLogPath(filepath.Join(userHomeConfDir, "kernel.log"))
+
if !gulu.File.IsExist(workspaceConf) {
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
- log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
- os.Exit(logging.ExitCodeCreateConfDirErr)
+ logging.LogErrorf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
}
@@ -201,8 +202,8 @@ func initWorkspaceDir(workspaceArg string) {
}
}
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
- log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
- os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
+ logging.LogErrorf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
var workspacePaths []string
@@ -226,13 +227,14 @@ func initWorkspaceDir(workspaceArg string) {
}
if !gulu.File.IsDir(WorkspaceDir) {
- log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
+ logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
WorkspaceDir = defaultWorkspaceDir
}
workspacePaths = append(workspacePaths, WorkspaceDir)
if err := WriteWorkspacePaths(workspacePaths); nil != err {
- log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err)
+ logging.LogErrorf("write workspace conf [%s] failed: %s", workspaceConf, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
ConfDir = filepath.Join(WorkspaceDir, "conf")
@@ -243,7 +245,8 @@ func initWorkspaceDir(workspaceArg string) {
osTmpDir := filepath.Join(TempDir, "os")
os.RemoveAll(osTmpDir)
if err := os.MkdirAll(osTmpDir, 0755); nil != err {
- log.Fatalf("create os tmp dir [%s] failed: %s", osTmpDir, err)
+ logging.LogErrorf("create os tmp dir [%s] failed: %s", osTmpDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
os.RemoveAll(filepath.Join(TempDir, "repo"))
os.Setenv("TMPDIR", osTmpDir)
@@ -327,33 +330,33 @@ const (
func initPathDir() {
if err := os.MkdirAll(ConfDir, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create conf folder [%s] failed: %s", ConfDir, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create conf folder [%s] failed: %s", ConfDir, err)
}
if err := os.MkdirAll(DataDir, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create data folder [%s] failed: %s", DataDir, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data folder [%s] failed: %s", DataDir, err)
}
if err := os.MkdirAll(TempDir, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create temp folder [%s] failed: %s", TempDir, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create temp folder [%s] failed: %s", TempDir, err)
}
assets := filepath.Join(DataDir, "assets")
if err := os.MkdirAll(assets, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create data assets folder [%s] failed: %s", assets, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data assets folder [%s] failed: %s", assets, err)
}
templates := filepath.Join(DataDir, "templates")
if err := os.MkdirAll(templates, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create data templates folder [%s] failed: %s", templates, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data templates folder [%s] failed: %s", templates, err)
}
widgets := filepath.Join(DataDir, "widgets")
if err := os.MkdirAll(widgets, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create data widgets folder [%s] failed: %s", widgets, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data widgets folder [%s] failed: %s", widgets, err)
}
emojis := filepath.Join(DataDir, "emojis")
if err := os.MkdirAll(emojis, 0755); nil != err && !os.IsExist(err) {
- log.Fatalf("create data emojis folder [%s] failed: %s", widgets, err)
+ logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data emojis folder [%s] failed: %s", widgets, err)
}
}
diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go
index cb94ba823..08182aa00 100644
--- a/kernel/util/working_mobile.go
+++ b/kernel/util/working_mobile.go
@@ -17,7 +17,6 @@
package util
import (
- "log"
"math/rand"
"os"
"path/filepath"
@@ -43,18 +42,20 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
WorkingDir = filepath.Join(appDir, "app")
HomeDir = filepath.Join(workspaceBaseDir, "home")
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
+ logging.SetLogPath(filepath.Join(userHomeConfDir, "kernel.log"))
+
if !gulu.File.IsExist(userHomeConfDir) {
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
- log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
- os.Exit(logging.ExitCodeCreateConfDirErr)
+ logging.LogErrorf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
}
defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
- log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
- os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
+ logging.LogErrorf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
initWorkspaceDirMobile(workspaceBaseDir)
@@ -69,7 +70,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
if gulu.File.IsDir(workspaceBaseDir) {
entries, err := os.ReadDir(workspaceBaseDir)
if nil != err {
- log.Printf("read workspace dir [%s] failed: %s", workspaceBaseDir, err)
+ logging.LogErrorf("read workspace dir [%s] failed: %s", workspaceBaseDir, err)
} else {
// 旧版 iOS 端会在 workspaceBaseDir 下直接创建工作空间,这里需要将数据迁移到 workspaceBaseDir/siyuan/ 文件夹下
var oldConf, oldData, oldTemp bool
@@ -96,9 +97,9 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
from := filepath.Join(workspaceBaseDir, entry.Name())
to := filepath.Join(workspaceBaseDir, "siyuan", entry.Name())
if err = os.Rename(from, to); nil != err {
- log.Printf("move workspace dir [%s] failed: %s", workspaceBaseDir, err)
+ logging.LogErrorf("move workspace dir [%s] failed: %s", workspaceBaseDir, err)
} else {
- log.Printf("moved workspace dir [fomr=%s, to=%s]", from, to)
+ logging.LogInfof("moved workspace dir [fomr=%s, to=%s]", from, to)
}
}
@@ -116,7 +117,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
if !gulu.File.IsExist(workspaceConf) {
WorkspaceDir = defaultWorkspaceDir
if !gulu.File.IsDir(WorkspaceDir) {
- log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
+ logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
WorkspaceDir = defaultWorkspaceDir
}
workspacePaths = append(workspacePaths, WorkspaceDir)
@@ -125,7 +126,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
if 0 < len(workspacePaths) {
WorkspaceDir = workspacePaths[len(workspacePaths)-1]
if !gulu.File.IsDir(WorkspaceDir) {
- log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir)
+ logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir)
WorkspaceDir = defaultWorkspaceDir
}
workspacePaths[len(workspacePaths)-1] = WorkspaceDir
@@ -136,7 +137,8 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
}
if err := WriteWorkspacePaths(workspacePaths); nil != err {
- log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err)
+ logging.LogErrorf("write workspace conf [%s] failed: %s", workspaceConf, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
ConfDir = filepath.Join(WorkspaceDir, "conf")
@@ -147,7 +149,8 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
osTmpDir := filepath.Join(TempDir, "os")
os.RemoveAll(osTmpDir)
if err := os.MkdirAll(osTmpDir, 0755); nil != err {
- log.Fatalf("create os tmp dir [%s] failed: %s", osTmpDir, err)
+ logging.LogErrorf("create os tmp dir [%s] failed: %s", osTmpDir, err)
+ os.Exit(logging.ExitCodeInitWorkspaceErr)
}
os.RemoveAll(filepath.Join(TempDir, "repo"))
os.Setenv("TMPDIR", osTmpDir)