feat(logging): include milliseconds timestamps (#2963)
This commit is contained in:
+10
-5
@@ -4,10 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
// standard includes
|
// standard includes
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// lib includes
|
// lib includes
|
||||||
#include <boost/core/null_deleter.hpp>
|
#include <boost/core/null_deleter.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
#include <boost/log/attributes/clock.hpp>
|
#include <boost/log/attributes/clock.hpp>
|
||||||
#include <boost/log/common.hpp>
|
#include <boost/log/common.hpp>
|
||||||
#include <boost/log/expressions.hpp>
|
#include <boost/log/expressions.hpp>
|
||||||
@@ -67,7 +69,6 @@ namespace logging {
|
|||||||
sink->set_formatter([](const bl::record_view &view, bl::formatting_ostream &os) {
|
sink->set_formatter([](const bl::record_view &view, bl::formatting_ostream &os) {
|
||||||
constexpr const char *message = "Message";
|
constexpr const char *message = "Message";
|
||||||
constexpr const char *severity = "Severity";
|
constexpr const char *severity = "Severity";
|
||||||
constexpr int DATE_BUFFER_SIZE = 21 + 2 + 1; // Full string plus ": \0"
|
|
||||||
|
|
||||||
auto log_level = view.attribute_values()[severity].extract<int>().get();
|
auto log_level = view.attribute_values()[severity].extract<int>().get();
|
||||||
|
|
||||||
@@ -93,11 +94,15 @@ namespace logging {
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
char _date[DATE_BUFFER_SIZE];
|
auto now = std::chrono::system_clock::now();
|
||||||
std::time_t t = std::time(nullptr);
|
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
strftime(_date, DATE_BUFFER_SIZE, "[%Y:%m:%d:%H:%M:%S]: ", std::localtime(&t));
|
now - std::chrono::time_point_cast<std::chrono::seconds>(now));
|
||||||
|
|
||||||
os << _date << log_type << view.attribute_values()[message].extract<std::string>();
|
auto t = std::chrono::system_clock::to_time_t(now);
|
||||||
|
auto lt = *std::localtime(&t);
|
||||||
|
|
||||||
|
os << "["sv << std::put_time(<, "%Y-%m-%d %H:%M:%S.") << boost::format("%03u") % ms.count() << "]: "sv
|
||||||
|
<< log_type << view.attribute_values()[message].extract<std::string>();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Flush after each log record to ensure log file contents on disk isn't stale.
|
// Flush after each log record to ensure log file contents on disk isn't stale.
|
||||||
|
|||||||
@@ -142,7 +142,7 @@
|
|||||||
/** Parse the text errors, calculating the text, the timestamp and the level */
|
/** Parse the text errors, calculating the text, the timestamp and the level */
|
||||||
fancyLogs() {
|
fancyLogs() {
|
||||||
if (!this.logs) return [];
|
if (!this.logs) return [];
|
||||||
let regex = /(\[\d{4}:\d{2}:\d{2}:\d{2}:\d{2}:\d{2}\]):\s/g;
|
let regex = /(\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}]):\s/g;
|
||||||
let rawLogLines = (this.logs.split(regex)).splice(1);
|
let rawLogLines = (this.logs.split(regex)).splice(1);
|
||||||
let logLines = []
|
let logLines = []
|
||||||
for (let i = 0; i < rawLogLines.length; i += 2) {
|
for (let i = 0; i < rawLogLines.length; i += 2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user