12 std::string UserChars::format(Message*)
const {
16 void UserChars::addChar(
char c) {
20 std::string LevelFlag::format(Message* message)
const {
26 ss << std::left << std::setfill(
' ') << std::setw(7) << message->level;
27 std::string tmp(ss.str());
28 std::transform(tmp.begin(), tmp.end(), tmp.begin(), [](
char c) {
29 return static_cast<char>(toupper(c));
34 std::string MessageFlag::format(Message* message)
const {
39 return message->raw.str();
46 ss << std::put_time(now,
"%y");
52 ss << std::put_time(now,
"%Y");
58 ss << std::put_time(now,
"%m");
64 ss << std::put_time(now,
"%d");
70 ss << std::put_time(now,
"%H");
76 ss << std::put_time(now,
"%M");
82 ss << std::put_time(now,
"%S");
112 token.advanced = std::make_unique<priv::MessageFlag>();
115 token.advanced = std::make_unique<priv::LevelFlag>();
119 _formatChain.push_back(std::move(token));
123 std::unique_ptr<priv::UserChars> chars;
125 auto end = pattern.end();
127 for (
auto it = pattern.begin(); it != end; ++it) {
131 _formatChain.push_back(priv::Token(std::move(chars)));
143 chars = std::make_unique<priv::UserChars>();
152 _formatChain.push_back(priv::Token(std::move(chars)));
157 compilePattern(pattern);
163 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
164 std::time_t tt = std::chrono::system_clock::to_time_t(now);
167 #if defined(LUG_SYSTEM_WINDOWS) 169 localtime_s(&tf, &tt);
174 localtime_r(&tt, &tf);
181 msg.formatted.clear();
183 for (priv::Token& elem : _formatChain) {
185 msg.formatted << (this->*elem.basic)(now);
186 }
else if (elem.advanced) {
187 msg.formatted << elem.advanced->format(&msg);