14 const config& streamConfig,
18 const std::filesystem::path path = prepare_folder_and_get_log_file_path(streamConfig);
20 std::ios_base::sync_with_stdio(
false);
22 QX_DISABLE_MSVC_WARNINGS(4996);
24 path.generic_string().c_str(),
25 streamConfig.eLogFilePolicy == log_file_policy::clear_then_upend ?
"wb" :
"ab");
28 string sLastError =
to_string(std::strerror(errno));
32 QX_RESTORE_MSVC_WARNINGS(4996);
34 if (bufferSize.value > 0)
37 m_Buffer.resize(bytes.value);
38 std::setvbuf(m_pFile, m_Buffer.data(), _IOFBF, m_Buffer.size());
45 std::swap(m_Buffer, other.m_Buffer);
46 std::swap(m_pFile, other.m_pFile);
49 inline file_logger_stream_fopen::~file_logger_stream_fopen()
61 std::thread::id threadId,
62 std::chrono::system_clock::time_point messageTime,
64 string_view svFunction,
66 string_view svMessage)
70 #if QX_WIN || QX_CONF_USE_CHAR
71 std::fwrite(svMessage.data(),
sizeof(char_type), svMessage.size(), m_pFile);
73 std::array<char16_t, 2048> chunk;
75 const char_type* pData = svMessage.data();
76 size_t nCharsRemaining = svMessage.size();
78 while (nCharsRemaining > 0)
80 size_t nCharsToTake = std::min(nCharsRemaining, chunk.size());
81 for (
size_t i = 0; i < nCharsToTake; ++i)
83 chunk[i] =
static_cast<char16_t
>(
static_cast<char16_t
>(pData[i]) & 0xFFFFu);
86 std::fwrite(chunk.data(),
sizeof(char16_t), nCharsToTake, m_pFile);
88 pData += nCharsToTake;
89 nCharsRemaining -= nCharsToTake;
Base class for all file logger streams.
A category is a class that identifies a particular piece of code. This code can be located in differe...
FILE* based file logger stream.
virtual void do_flush() override
Flush the stream.
virtual void do_log(const category &category, verbosity eVerbosity, std::thread::id threadId, std::chrono::system_clock::time_point messageTime, string_view svFile, string_view svFunction, int nLine, string_view svMessage) override
Proceed stream logging.
file_logger_stream_fopen(const config &streamConfig=config(), unit< size_t, units::data > bufferSize={ 8192 *sizeof(char_type), units::data::bytes }) noexcept
file_logger_stream_fopen object constructor
void to_string(string &out, cstring_view stringView, const std::locale &locale=std::locale())
Convert a char string to common string type.