| 421 | : LogMessage(file, line, id, severity, nullptr, error) {} |
| 422 | |
| 423 | LogMessage::~LogMessage() { |
| 424 | // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM. |
| 425 | if (!WOULD_LOG(data_->GetSeverity())) { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | // Finish constructing the message. |
| 430 | if (data_->GetError() != -1) { |
| 431 | data_->GetBuffer() << ": " << strerror(data_->GetError()); |
| 432 | } |
| 433 | std::string msg(data_->ToString()); |
| 434 | |
| 435 | { |
| 436 | // Do the actual logging with the lock held. |
| 437 | std::lock_guard<std::mutex> lock(LoggingLock()); |
| 438 | if (msg.find('\n') == std::string::npos) { |
| 439 | LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(), |
| 440 | data_->GetTag(), msg.c_str()); |
| 441 | } else { |
| 442 | msg += '\n'; |
| 443 | size_t i = 0; |
| 444 | while (i < msg.size()) { |
| 445 | size_t nl = msg.find('\n', i); |
| 446 | msg[nl] = '\0'; |
| 447 | LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(), |
| 448 | data_->GetTag(), &msg[i]); |
| 449 | // Undo the zero-termination so we can give the complete message to the aborter. |
| 450 | msg[nl] = '\n'; |
| 451 | i = nl + 1; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | // Abort if necessary. |
| 457 | if (data_->GetSeverity() == FATAL) { |
| 458 | Aborter()(msg.c_str()); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | std::ostream& LogMessage::stream() { |
| 463 | return data_->GetBuffer(); |
nothing calls this directly
no test coverage detected