mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-21 08:10:43 +08:00
coarse clock, short log level
This commit is contained in:
parent
a788fb3ed3
commit
2f34de820b
@ -71,10 +71,17 @@ typedef enum
|
||||
|
||||
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical", "alert", "emerg", "off"};
|
||||
|
||||
static const char* short_level_names[] { "T", "D", "I", "N", "W", "E", "C", "A", "M", "O"};
|
||||
|
||||
inline const char* to_str(spdlog::level::level_enum l)
|
||||
{
|
||||
return level_names[l];
|
||||
}
|
||||
|
||||
inline const char* to_short_str(spdlog::level::level_enum l)
|
||||
{
|
||||
return short_level_names[l];
|
||||
}
|
||||
} //level
|
||||
|
||||
|
||||
|
@ -26,6 +26,9 @@
|
||||
|
||||
#include "../common.h"
|
||||
#include "../logger.h"
|
||||
#ifdef SPDLOG_CLOCK_COARSE
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
|
||||
// Line logger class - aggregates operator<< calls to fast ostream
|
||||
@ -64,7 +67,15 @@ public:
|
||||
if (_enabled)
|
||||
{
|
||||
_log_msg.logger_name = _callback_logger->name();
|
||||
#ifndef SPDLOG_CLOCK_COARSE
|
||||
_log_msg.time = log_clock::now();
|
||||
#else
|
||||
timespec ts;
|
||||
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
||||
_log_msg.time = std::chrono::time_point<log_clock, typename log_clock::duration>(
|
||||
std::chrono::duration_cast<typename log_clock::duration>(
|
||||
std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
|
||||
#endif
|
||||
_callback_logger->_log_msg(_log_msg);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,15 @@ class level_formatter :public flag_formatter
|
||||
}
|
||||
};
|
||||
|
||||
// short log level appender
|
||||
class short_level_formatter :public flag_formatter
|
||||
{
|
||||
void format(details::log_msg& msg, const std::tm&) override
|
||||
{
|
||||
msg.formatted << level::to_short_str(msg.level);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Date time pattern appenders
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
@ -478,6 +487,10 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::level_formatter()));
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::short_level_formatter()));
|
||||
break;
|
||||
|
||||
case('t') :
|
||||
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::t_formatter()));
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user