|
@@ -12,7 +12,8 @@
|
|
|
|
|
|
|
|
using namespace logging;
|
|
using namespace logging;
|
|
|
|
|
|
|
|
-c_logger::c_logger(std::string const & name, std::shared_ptr<logger_impl> impl)
|
|
|
|
|
|
|
+c_logger::c_logger(std::string const & name,
|
|
|
|
|
+ std::shared_ptr<logger_impl> impl)
|
|
|
: min_level_(LDEBUG), logger_name_(name), impl_(impl)
|
|
: min_level_(LDEBUG), logger_name_(name), impl_(impl)
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
@@ -21,28 +22,20 @@ c_logger::~c_logger() {
|
|
|
if (impl_) impl_->flush();
|
|
if (impl_) impl_->flush();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-std::string c_logger::get_header(log_level level) {
|
|
|
|
|
- std::string ts = timestamp();
|
|
|
|
|
- char data[64];
|
|
|
|
|
- snprintf(data, sizeof(data), "[%-5s] %s %s - ",
|
|
|
|
|
- level_header(level), logger_name_.c_str(), ts.c_str());
|
|
|
|
|
- return data;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void c_logger::vlognf(log_level level, size_t num_bytes, char const* fmt,
|
|
void c_logger::vlognf(log_level level, size_t num_bytes, char const* fmt,
|
|
|
- va_list args) {
|
|
|
|
|
|
|
+ va_list args) {
|
|
|
if (level < min_level_ || !impl_->should_log(level)) return;
|
|
if (level < min_level_ || !impl_->should_log(level)) return;
|
|
|
const std::unique_ptr<char[]> data(new char[num_bytes]);
|
|
const std::unique_ptr<char[]> data(new char[num_bytes]);
|
|
|
int n = vsnprintf(data.get(), num_bytes, fmt, args);
|
|
int n = vsnprintf(data.get(), num_bytes, fmt, args);
|
|
|
if (n >= 0) {
|
|
if (n >= 0) {
|
|
|
data[num_bytes-1] = '\0';
|
|
data[num_bytes-1] = '\0';
|
|
|
- log(level, get_header(level) + data.get() + "\n");
|
|
|
|
|
|
|
+ impl_->write({ now(), level, {}, logger_name_.c_str(), data.get() });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void c_logger::log(log_level level, std::string const& msg) {
|
|
void c_logger::log(log_level level, std::string const& msg) {
|
|
|
if (level < min_level_ || !impl_->should_log(level)) return;
|
|
if (level < min_level_ || !impl_->should_log(level)) return;
|
|
|
- impl_->write(level, msg);
|
|
|
|
|
|
|
+ impl_->write({ now(), level, {}, logger_name_.c_str(), msg });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void c_logger::flush() {
|
|
void c_logger::flush() {
|