Skip to content

Commit

Permalink
Fixed crash in async logger in gcc 4.8.5 regarding static members in …
Browse files Browse the repository at this point in the history
…pattern_formatter impl
  • Loading branch information
gabime committed Aug 19, 2017
1 parent 6340c16 commit 268222e
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions include/spdlog/details/pattern_formatter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,67 +79,42 @@ static int to12h(const tm& t)
}

//Abbreviated weekday name
using days_array = std::array<std::string, 7>;
static const days_array& days()
{
static const days_array arr{ { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" } };
return arr;
}
static const std::string days[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
class a_formatter:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << days()[tm_time.tm_wday];
}
};
// message counter formatter
class i_formatter SPDLOG_FINAL:public flag_formatter
{
void format(details::log_msg& msg, const std::tm&) override
{
msg.formatted << '#' << msg.msg_id;
msg.formatted << days[tm_time.tm_wday];
}
};

//Full weekday name
static const days_array& full_days()
{
static const days_array arr{ { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } };
return arr;
}
class A_formatter SPDLOG_FINAL :public flag_formatter
static const std::string full_days[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
class A_formatter:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << full_days()[tm_time.tm_wday];
msg.formatted << full_days[tm_time.tm_wday];
}
};

//Abbreviated month
using months_array = std::array<std::string, 12>;
static const months_array& months()
{
static const months_array arr{ { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" } };
return arr;
}
static const std::string months[] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };
class b_formatter:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << months()[tm_time.tm_mon];
msg.formatted << months[tm_time.tm_mon];
}
};

//Full month name
static const months_array& full_months()
{
static const months_array arr{ { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } };
return arr;
}
class B_formatter SPDLOG_FINAL :public flag_formatter
static const std::string full_months[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
class B_formatter:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << full_months()[tm_time.tm_mon];
msg.formatted << full_months[tm_time.tm_mon];
}
};

Expand All @@ -164,7 +139,7 @@ class c_formatter SPDLOG_FINAL:public flag_formatter
{
void format(details::log_msg& msg, const std::tm& tm_time) override
{
msg.formatted << days()[tm_time.tm_wday] << ' ' << months()[tm_time.tm_mon] << ' ' << tm_time.tm_mday << ' ';
msg.formatted << days[tm_time.tm_wday] << ' ' << months[tm_time.tm_mon] << ' ' << tm_time.tm_mday << ' ';
pad_n_join(msg.formatted, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, ':') << ' ' << tm_time.tm_year + 1900;
}
};
Expand Down

0 comments on commit 268222e

Please sign in to comment.