option This commit refactors string_stream and string_streamx into a common basic_string_stream template class. When the EXT template == true, the string_streamx formatting options are enabled, they default to disabled. These options are enabled at compile time, and do not affect performance when they are disabled. By implementing the two streams in this manner, duplicated code is removed. This commit also adds the ENDL template paramter. When ENDL is set to zero, no endline character is printed when piping mtl::endl. Otherwise, the character is printed. Defaults to '\n'. This allows logging on the GBA to handle mtl::endl correctly and not print two newlines on the MGBA emulator.
30 lines
480 B
C++
30 lines
480 B
C++
#include "mtl/log.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
namespace mtl {
|
|
|
|
namespace log {
|
|
|
|
static string<512> buffer;
|
|
|
|
stream::stream(istring& buf, uint32_t log_level)
|
|
: basic_string_stream(buf), m_log_level(log_level) { }
|
|
stream::~stream() { }
|
|
|
|
void stream::flush() {
|
|
fwrite(buffer.c_str(), 1, buffer.length(), stdout);
|
|
clear();
|
|
}
|
|
|
|
stream debug(buffer, 4);
|
|
stream info(buffer, 3);
|
|
stream warn(buffer, 2);
|
|
stream error(buffer, 1);
|
|
|
|
} // namespace log
|
|
|
|
} // namespace mtl
|
|
|