An error occurs when the directory path is an absolute path during daily log creation
Mangomm opened this issue · comments
I have a problem, when I create a daily log "spdlog::daily_logger_mt("daily_logger","logs/daily.txt", 0, 0)", any path executor can automatically generate logs directory in the corresponding path, But will "logs/daily.txt" into an absolute path, such as "/ home/test/logs/daily.txt", when the "/home/test/logs/" directory does not exist, it throws an exception -- -- -- -- -- "what () : Failed opening file /home/test/logs/daily_2021-09-24.txt for writing: No such file or directory". The program can run only if the directory is manually created in this path("/home/test/logs/"). So I want to ask how to better solve this situation.
Since spdlog version 1.5.0, the log directory should be created automatically.
However, it may fail to be created due to permission errors.
The owner of the /home
directory is usually root
.
Does the user who runs the process have write access to /home
?
從 spdlog 版本 1.5.0 開始,應該自動創建日誌目錄。
但是可能會因為權限錯誤而無法創建。
/home
目錄的所有者通常是root
.
運行該進程的用戶是否具有寫入權限/home
?
Yes, I'm running the program as root, but I still get exceptions
My version of spdlog is 1.8.1
I can not reproduce your problem with this small project.
$ root@b439c1016f25:/workspace/build# ls -lha /home/
total 8.0K
drwxr-xr-x 1 root root 4.0K Sep 24 12:45 .
drwxr-xr-x 1 root root 4.0K Sep 24 12:23 ..
$ root@b439c1016f25:/workspace/build# ./spdlog_issue_2114
$ root@b439c1016f25:/workspace/build# cat /home/test/logs/daily_2021-09-24.txt
[2021-09-24 12:45:45.068] [daily_logger] [info] spdlog version 10801
I don't think it's a bug in the library.