29 if (level < LogLevel::INFO) {
31 }
else if (level < LogLevel::WARN) {
33 }
else if (level < LogLevel::ERR) {
35 }
else if (level < LogLevel::CRITICAL) {
37 }
else if (level < LogLevel::DFATAL) {
44 if (level < LogLevel::INFO || level >= LogLevel::WARN) {
52 if (level < LogLevel::INFO) {
54 }
else if (level < LogLevel::WARN) {
56 }
else if (level < LogLevel::ERR) {
58 }
else if (level < LogLevel::CRITICAL) {
66 const std::size_t argIndex;
67 const std::size_t width;
71 std::size_t argIndex_,
72 std::size_t width_ = 0)
73 : key(key_), argIndex(argIndex_), width(width_) {}
85 constexpr std::array<FormatKeys, 11> formatKeys{{
86 FormatKeys(
"D", 2, 2),
87 FormatKeys(
"FILE", 8),
88 FormatKeys(
"FUN", 9),
89 FormatKeys(
"H", 3, 2),
90 FormatKeys(
"L", 0, 1),
91 FormatKeys(
"LINE", 10, 4),
92 FormatKeys(
"M", 4, 2),
93 FormatKeys(
"S", 5, 2),
94 FormatKeys(
"THREAD", 7, 5),
95 FormatKeys(
"USECS", 6, 6),
96 FormatKeys(
"m", 1, 2),
98 constexpr
int messageIndex = formatKeys.size();
110 std::size_t estimatedWidth = 0;
116 output.reserve(input.
size());
117 const char* varNameStart =
nullptr;
125 for (
const char* p = input.
begin(); p < input.
end(); ++p) {
132 if ((p + 1) != input.
end() &&
133 (0 == memcmp(p,
"}}", 2) || 0 == memcmp(p,
"{{", 2))) {
134 output.append(p + 1, 1);
141 else if (*p ==
'{') {
142 varNameStart = p + 1;
156 if (*p ==
':' || *p ==
'}') {
158 auto item = std::lower_bound(
162 [](
const auto&
a,
const auto&
b) {
return a.key <
b; });
164 if (
UNLIKELY(item == formatKeys.end() || item->key != varName)) {
165 throw std::runtime_error(folly::to<std::string>(
166 "unknown format argument \"", varName,
"\""));
168 output.append(folly::to<std::string>(item->argIndex));
175 estimatedWidth += item->width;
176 if (item->key ==
"FILE") {
178 }
else if (item->key ==
"FUN") {
185 state = FMT_MODIFIERS;
203 throw std::runtime_error(
"unterminated format string");
206 if (!output.empty()) {
227 folly::to<std::string>(
logFormat_,
"{", messageIndex,
"}\n");
236 auto timeSinceEpoch = message.
getTimestamp().time_since_epoch();
238 std::chrono::duration_cast<std::chrono::seconds>(timeSinceEpoch);
239 std::chrono::microseconds usecs =
240 std::chrono::duration_cast<std::chrono::microseconds>(timeSinceEpoch) -
242 time_t unixTimestamp = epochSeconds.count();
243 if (!localtime_r(&unixTimestamp, <ime)) {
244 memset(<ime, 0,
sizeof(ltime));
254 getGlogLevelName(message.
getLevel())[0],
270 getColorSequence(message.
getLevel()),
271 getResetSequence(message.
getLevel()));
278 getGlogLevelName(message.
getLevel())[0],
311 size_t numLinesGuess = 4;
312 buffer.reserve((headerLengthGuess * numLinesGuess) + msgData.size());
316 auto end = msgData.find(
'\n', idx);
318 end = msgData.size();
321 auto line = msgData.subpiece(idx,
end - idx);
322 headerFormatter.appendTo(buffer);
323 buffer.append(line.data(), line.size());
324 buffer.push_back(
'\n');
326 if (
end == msgData.size()) {
std::vector< uint8_t > buffer(kBufferSize+16)
folly::StringPiece toString(StateEnum state)
folly::StringPiece getFunctionName() const
std::string sformat(StringPiece fmt, Args &&...args)
constexpr size_type size() const
—— Concurrent Priority Queue Implementation ——
const std::string & getMessage() const
uint64_t getThreadID() const
LogLevel getLevel() const
auto end(TestAdlIterable &instance)
constexpr Iter end() const
constexpr Iter begin() const
unsigned int getLineNumber() const
static const size_type npos
folly::StringPiece getFileBaseName() const
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
const Instruction LITERAL
std::chrono::system_clock::time_point getTimestamp() const
Range< const char * > StringPiece
bool containsNewlines() const