Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions source/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "MaaUtils/Logger.h"

#include <cerrno>
#include <iostream>
#include <thread>

#ifdef _WIN32
Expand Down Expand Up @@ -197,8 +199,16 @@ void Logger::open(bool append)
#ifdef _WIN32

// https://stackoverflow.com/questions/55513974/controlling-inheritability-of-file-handles-created-by-c-stdfstream-in-window
std::string str_log_path = log_path_.string();
FILE* file_ptr = fopen(str_log_path.c_str(), append ? "a" : "w");
FILE* file_ptr = _wfopen(log_path_.c_str(), append ? L"a" : L"w");
if (!file_ptr) {
const int error_no = errno;
const wchar_t* werr = _wcserror(error_no);
std::cerr << "[MaaUtils][Logger] Failed to open log file: " << path_to_utf8_string(log_path_)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好丑啊,你这还不如不加呢()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那肿么改

<< ", errno=" << error_no
<< ", message=" << (werr ? path_to_utf8_string(werr) : "unknown")
<< std::endl;
return;
}
Comment thread
Windsland52 marked this conversation as resolved.
SetHandleInformation((HANDLE)_get_osfhandle(_fileno(file_ptr)), HANDLE_FLAG_INHERIT, 0);
ofs_ = std::ofstream(file_ptr);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

Expand Down