mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 18:11:33 +08:00
Use fmt::pad for faster formatting of the default format pattern
This commit is contained in:
parent
45628c8ec3
commit
c5afdbddcf
@ -371,7 +371,10 @@ class full_formatter :public flag_formatter
|
||||
{
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
||||
msg.formatted.write("[{:d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:03d}] [{}] [{}] ",
|
||||
|
||||
|
||||
/* Slower version(while still very fast - about 3.2 million lines/sec),
|
||||
msg.formatted.write("[{:d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:03d}] [{}] [{}] {} ",
|
||||
msg.tm_time.tm_year + 1900,
|
||||
msg.tm_time.tm_mon + 1,
|
||||
msg.tm_time.tm_mday,
|
||||
@ -380,9 +383,20 @@ class full_formatter :public flag_formatter
|
||||
msg.tm_time.tm_sec,
|
||||
static_cast<int>(millis),
|
||||
msg.logger_name,
|
||||
level::to_str(msg.level));
|
||||
level::to_str(msg.level),
|
||||
msg.raw.str());*/
|
||||
|
||||
msg.formatted.write(msg.raw.str());
|
||||
// Faster (albeit uglier) way to format the line (5.6 million lines/sec)
|
||||
msg.formatted << '[' << msg.tm_time.tm_year + 1900 << '-'
|
||||
<< fmt::pad(msg.tm_time.tm_mon + 1, 2, '0') << '-'
|
||||
<< fmt::pad(msg.tm_time.tm_mday, 2, '0') << ' '
|
||||
<< fmt::pad(msg.tm_time.tm_hour, 2, '0') << ':'
|
||||
<< fmt::pad(msg.tm_time.tm_min, 2, '0') << ':'
|
||||
<< fmt::pad(msg.tm_time.tm_sec, 2, '0') << '.'
|
||||
<< fmt::pad(static_cast<int>(millis), 3, '0') << "] ";
|
||||
|
||||
msg.formatted << '[' << msg.logger_name << "] [" << level::to_str(msg.level) << "] ";
|
||||
msg.formatted.write(msg.raw.data(), msg.raw.size());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user