83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include "mtl/string_stream.hpp"
|
|
|
|
namespace mtl {
|
|
|
|
namespace log {
|
|
|
|
enum class level : uint32_t {
|
|
error = 1,
|
|
warn = 2,
|
|
info = 3,
|
|
debug = 4,
|
|
};
|
|
|
|
#ifdef __GBA__
|
|
constexpr char endl_char = 0;
|
|
#else
|
|
constexpr char endl_char = '\n';
|
|
#endif
|
|
|
|
/**
|
|
* \brief Log stream
|
|
*
|
|
* String stream that overrides sync() to flush the stream to the correct
|
|
* output depending on the platform. Each flush is treated as a separate message.
|
|
* The capacity of the stream depends on the platform.
|
|
*
|
|
* See mtl::basic_string_stream for information on when the stream is flushed.
|
|
*
|
|
* Platform specific info:
|
|
*
|
|
* GBA: Flushing cannot be done without printing to a new line. Trying to
|
|
* insert a newline will instead just flush the stream onto a new line. On MGBA
|
|
* this also starts the line with "GBA Debug: ", so the line is not completely
|
|
* blank.
|
|
*/
|
|
class stream : public basic_string_stream<false, endl_char> {
|
|
private:
|
|
level m_log_level;
|
|
|
|
public:
|
|
stream(istring& str, level log_level);
|
|
~stream();
|
|
|
|
using basic_string_stream::operator=;
|
|
using basic_string_stream::operator<<;
|
|
|
|
void flush() override;
|
|
};
|
|
|
|
/**
|
|
* \brief Stub log stream
|
|
*
|
|
* Implements all of the log stream functions as a NOP. Replaces all of
|
|
* the log streams when logging is disabled.
|
|
*
|
|
* TODO: Enable logging disabling.
|
|
*/
|
|
class stream_stub {
|
|
public:
|
|
stream_stub(istring&, uint32_t) { }
|
|
|
|
void flush() { }
|
|
void clear() { }
|
|
|
|
template <typename T>
|
|
stream_stub& operator<<(T) {
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
extern stream debug;
|
|
extern stream info;
|
|
extern stream warn;
|
|
extern stream error;
|
|
|
|
} // namespace log
|
|
|
|
} // namespace mtl
|