Commit d071e5fc authored by Gabi Melman's avatar Gabi Melman

Merge pull request #38 from divaykin/master

coarse clock, short log level
parents a788fb3e 2f34de82
...@@ -71,10 +71,17 @@ typedef enum ...@@ -71,10 +71,17 @@ typedef enum
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical", "alert", "emerg", "off"}; 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) inline const char* to_str(spdlog::level::level_enum l)
{ {
return level_names[l]; return level_names[l];
} }
inline const char* to_short_str(spdlog::level::level_enum l)
{
return short_level_names[l];
}
} //level } //level
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#include "../common.h" #include "../common.h"
#include "../logger.h" #include "../logger.h"
#ifdef SPDLOG_CLOCK_COARSE
#include <time.h>
#endif
// Line logger class - aggregates operator<< calls to fast ostream // Line logger class - aggregates operator<< calls to fast ostream
...@@ -64,7 +67,15 @@ public: ...@@ -64,7 +67,15 @@ public:
if (_enabled) if (_enabled)
{ {
_log_msg.logger_name = _callback_logger->name(); _log_msg.logger_name = _callback_logger->name();
#ifndef SPDLOG_CLOCK_COARSE
_log_msg.time = log_clock::now(); _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); _callback_logger->_log_msg(_log_msg);
} }
} }
......
...@@ -69,6 +69,15 @@ class level_formatter :public flag_formatter ...@@ -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 // Date time pattern appenders
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
...@@ -478,6 +487,10 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) ...@@ -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())); _formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::level_formatter()));
break; break;
case 'L':
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::short_level_formatter()));
break;
case('t') : case('t') :
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::t_formatter())); _formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::t_formatter()));
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment