Commit 72c449ec authored by Dominik Charousset's avatar Dominik Charousset

Fix logger on GCC 4.8

parent a4aa1c36
......@@ -19,6 +19,7 @@
#include "caf/logger.hpp"
#include <ctime>
#include <thread>
#include <cstring>
#include <iomanip>
......@@ -292,7 +293,11 @@ void logger::render_time_diff(std::ostream& out, timestamp t0, timestamp tn) {
void logger::render_date(std::ostream& out, timestamp x) {
auto y = std::chrono::time_point_cast<timestamp::clock::duration>(x);
auto z = timestamp::clock::to_time_t(y);
out << std::put_time(std::localtime(&z), "%F %T");
// strftime workaround: std::put_time not available on GCC 4.8
// out << std::put_time(std::localtime(&z), "%F %T");
char buf[50];
if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&z)))
out << buf;
}
void logger::render(std::ostream& out, const line_format& lf,
......
......@@ -22,6 +22,7 @@
#define CAF_SUITE logger
#include "caf/test/unit_test.hpp"
#include <ctime>
#include <string>
#include "caf/all.hpp"
......@@ -99,10 +100,11 @@ CAF_TEST(rendering) {
timestamp t0;
timestamp t1{timestamp::duration{5000000}}; // epoch + 5000000ns (5ms)
CAF_CHECK_EQUAL(render(logger::render_time_diff, t0, t1), "5");
ostringstream t0_iso8601;
auto t0_t = system_clock::to_time_t(system_clock::time_point{});
t0_iso8601 << put_time(localtime(&t0_t), "%F %T");
CAF_CHECK_EQUAL(render(logger::render_date, t0), t0_iso8601.str());
time_t t0_t = 0;
char t0_buf[50];
CAF_REQUIRE(strftime(t0_buf, sizeof(t0_buf),
"%Y-%m-%d %H:%M:%S", localtime(&t0_t)));
CAF_CHECK_EQUAL(render(logger::render_date, t0), t0_buf);
// Rendering of events.
logger::event e{
nullptr,
......
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