169 std::error_code error;
170 fs::create_directories(directory, error);
172 return std::unexpected(
173 std::format(
"ログのフォルダを作れない: {}: {}",
ToUtf8(directory.wstring()), DescribeErrorCode(error)));
176 RemoveOldLogFiles(directory);
179 const std::tm now = LocalNow();
181 const std::wstring fileName = std::format(L
"{}{:04}{:02}{:02}-{:02}{:02}{:02}{}", LOG_FILE_PREFIX,
182 now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, now.tm_hour,
183 now.tm_min, now.tm_sec, LOG_FILE_EXTENSION);
185 fs::path path = directory / fileName;
186 std::ofstream stream(path, std::ios::binary | std::ios::app);
188 return std::unexpected(std::format(
"ログのファイルを開けない: {}",
ToUtf8(path.wstring())));
190 stream << std::format(
"# Bicameral Engine log {:04}-{:02}-{:02} {:02}:{:02}:{:02}\n", now.tm_year + 1900,
191 now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
192 stream <<
"# [経過秒] 重大度 チャンネル | 本文 (ファイル:行)\n";
193 logger.
AddSink(std::make_unique<FileSink>(std::move(stream)));