mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
log_msg refactoring and raw message support
This commit is contained in:
@@ -26,12 +26,7 @@ public:
|
||||
{
|
||||
if(enabled)
|
||||
{
|
||||
_log_msg.msg_time = log_clock::now();
|
||||
callback_logger->_formatter->format_header(callback_logger->_logger_name,
|
||||
_log_msg.msg_level,
|
||||
_log_msg.msg_time,
|
||||
_oss);
|
||||
_log_msg.msg_header_size = _oss.str().size();
|
||||
_log_msg.time = log_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +41,10 @@ public:
|
||||
_log_msg(std::move(other._log_msg)),
|
||||
_oss(std::move(other._oss.str())),
|
||||
_enabled(other._enabled),
|
||||
_empty(other._empty)
|
||||
{
|
||||
other.disable();
|
||||
}
|
||||
_empty(other._empty)
|
||||
{
|
||||
other.disable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,8 +53,7 @@ public:
|
||||
//only if enabled and not empty
|
||||
if (_enabled && !_empty)
|
||||
{
|
||||
_oss << os::eol();
|
||||
_log_msg.str = _oss.str();
|
||||
_log_msg.raw = _oss.str();
|
||||
_callback_logger->_log_it(_log_msg);
|
||||
}
|
||||
}
|
||||
@@ -81,10 +75,10 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
_enabled = false;
|
||||
}
|
||||
void disable()
|
||||
{
|
||||
_enabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +86,7 @@ private:
|
||||
logger* _callback_logger;
|
||||
log_msg _log_msg;
|
||||
//details::stack_oss _oss;
|
||||
std::ostringstream _oss;
|
||||
std::ostringstream _oss;
|
||||
bool _enabled;
|
||||
bool _empty;
|
||||
};
|
||||
|
@@ -8,51 +8,50 @@ struct log_msg
|
||||
{
|
||||
log_msg() = default;
|
||||
log_msg(level::level_enum l):
|
||||
msg_level(l),
|
||||
msg_time(),
|
||||
msg_header_size(0),
|
||||
str() {}
|
||||
level(l),
|
||||
time(),
|
||||
raw(),
|
||||
formatted() {}
|
||||
|
||||
|
||||
log_msg(const log_msg& other):
|
||||
msg_level(other.msg_level),
|
||||
msg_time(other.msg_time),
|
||||
msg_header_size(other.msg_header_size),
|
||||
str(other.str) {}
|
||||
log_msg(const log_msg& other):
|
||||
level(other.level),
|
||||
time(other.time),
|
||||
raw(other.raw),
|
||||
formatted(other.formatted) {}
|
||||
|
||||
log_msg(log_msg&& other):log_msg()
|
||||
{
|
||||
swap(*this, other);
|
||||
}
|
||||
log_msg(log_msg&& other)
|
||||
{
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
friend void swap(log_msg& l, log_msg& r)
|
||||
{
|
||||
using std::swap;
|
||||
swap(l.msg_level, r.msg_level);
|
||||
swap(l.msg_time, r.msg_time);
|
||||
swap(l.msg_header_size, r.msg_header_size);
|
||||
swap(l.str, r.str);
|
||||
}
|
||||
friend void swap(log_msg& l, log_msg& r)
|
||||
{
|
||||
using std::swap;
|
||||
swap(l.level, r.level);
|
||||
swap(l.time, r.time);
|
||||
swap(l.raw, r.raw);
|
||||
swap(l.formatted, r.formatted);
|
||||
}
|
||||
|
||||
|
||||
|
||||
log_msg& operator=(log_msg other)
|
||||
{
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
log_msg& operator=(log_msg other)
|
||||
{
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void clear()
|
||||
{
|
||||
msg_header_size = 0;
|
||||
str.clear();
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
raw.clear();
|
||||
formatted.clear();
|
||||
}
|
||||
|
||||
level::level_enum msg_level;
|
||||
log_clock::time_point msg_time;
|
||||
std::size_t msg_header_size;
|
||||
std::string str;
|
||||
level::level_enum level;
|
||||
log_clock::time_point time;
|
||||
std::string raw;
|
||||
std::string formatted;
|
||||
|
||||
};
|
||||
}
|
||||
|
@@ -44,23 +44,31 @@ inline bool operator!=(const std::tm& tm1, const std::tm& tm2)
|
||||
return !(tm1==tm2);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
inline const char* eol()
|
||||
{
|
||||
return "\r\n";
|
||||
}
|
||||
#else
|
||||
constexpr inline const char* eol()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return "\r\n";
|
||||
#else
|
||||
return "\n";
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
inline unsigned short eol_size()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
#else
|
||||
constexpr inline unsigned short eol_size()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return 2;
|
||||
#else
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
} //os
|
||||
} //details
|
||||
} //c11log
|
||||
|
Reference in New Issue
Block a user