Merge pull request #38 from divaykin/master

coarse clock, short log level
This commit is contained in:
Gabi Melman 2015-01-27 18:13:36 +02:00
commit d071e5fcfa
3 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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;