29
class Logger: public std::ostringstream
50
// Strip the ending space char if it exists
51
auto result = _stream.str();
52
if (result.rfind(' ') == std::string::npos) {
60
static inline const char* log_level_string(Level level)
80
inline void log(const std::string& message)
84
g_debug("%s", message.c_str());
87
g_warning("%s", message.c_str());
90
g_critical("%s", message.c_str());
93
g_error("%s", message.c_str());
96
g_message("%s", message.c_str());
102
inline Logger& no_space() { return *this; }
103
inline Logger& maybe_space() {
110
inline Logger& operator<<(Level l) {
111
_stream << log_level_string(l);
113
return maybe_space();
116
inline Logger& operator<<(bool b) {
117
_stream << (b ? "true" : "false");
119
return maybe_space();
122
inline Logger& operator<<(char c) {
125
return maybe_space();
128
inline Logger& operator<<(const char *s) {
131
return maybe_space();
134
inline Logger& operator<<(const std::string& s) {
137
return maybe_space();
140
inline Logger& operator<<(const void *p) {
141
_stream << ((p == NULL) ? "(null)" : p);
143
return maybe_space();
146
inline Logger& operator<<(std::nullptr_t) {
147
_stream << "(nullptr)";
149
return maybe_space();
152
inline Logger& operator<<(int t) {
154
return maybe_space();
157
inline Logger& operator<<(long t) {
159
return maybe_space();
162
inline Logger& operator<<(long long t) {
164
return maybe_space();
167
inline Logger& operator<<(unsigned int t) {
169
return maybe_space();
172
inline Logger& operator<<(unsigned long t) {
174
return maybe_space();
177
inline Logger& operator<<(unsigned long long t) {
179
return maybe_space();
182
inline Logger& operator<<(float f) {
184
return maybe_space();
187
inline Logger& operator<<(double d) {
189
return maybe_space();
41
Logger(Logger::Level level, const std::string& domain);
42
Logger(Logger&& logger);
195
std::ostringstream _stream;
198
51
// These are the APIs to be used for logging.
199
#define debug() Logger(Logger::Level::DEBUG)
200
#define warn() Logger(Logger::Level::WARNING)
201
#define critical() Logger(Logger::Level::CRITICAL)
202
#define error() Logger(Logger::Level::ERROR)
52
#define debug() Logger(Logger::Level::DEBUG, G_LOG_DOMAIN)
53
#define info() Logger(Logger::Level::INFO, G_LOG_DOMAIN)
54
#define warn() Logger(Logger::Level::WARNING, G_LOG_DOMAIN)
55
#define critical() Logger(Logger::Level::CRITICAL, G_LOG_DOMAIN)
56
#define error() Logger(Logger::Level::ERROR, G_LOG_DOMAIN)
204
58
} // namespace util