Closed pn2200 closed 11 months ago
The issue is rather that the parent folder is not created when it doesn't exist. Make sure to create it yourself then:
// D: drive exists, but D:\logs\everything.log does not exist:
std::filesystem::path log_file_path = "D:\\logs\\everything.log";
std::filesystem::create_directories(log_file_path.parent_path());
const auto log_file_path_string = log_file_path.string();
loguru::add_file(log_file_path_string.c_str(), loguru::Append, loguru::Verbosity_MAX);
LOG_F(ERROR, "Log something");
I agree however that it would be great if loguru handled this correctly by itself internally. However, it's quite a C mess.
Ah, my mistake, thanks for the response. Closing issue.
On Windows, when logging to a file on a different drive, where the file and the directory do not exist, fails. Logs are not written to the file, the log file is not created, and the directory is not created. The following is the output from the reproducer program.
Reproducer: