| 594 | |
| 595 | protected: |
| 596 | bool dump_impl(const std::string& name, const butil::StringPiece& desc, const std::string& separator) { |
| 597 | if (_fp == NULL) { |
| 598 | butil::File::Error error; |
| 599 | butil::FilePath dir = butil::FilePath(_filename).DirName(); |
| 600 | if (!butil::CreateDirectoryAndGetError(dir, &error)) { |
| 601 | LOG(ERROR) << "Fail to create directory=`" << dir.value() |
| 602 | << "', " << error; |
| 603 | return false; |
| 604 | } |
| 605 | _fp = fopen(_filename.c_str(), "w"); |
| 606 | if (NULL == _fp) { |
| 607 | LOG(ERROR) << "Fail to open " << _filename; |
| 608 | return false; |
| 609 | } |
| 610 | } |
| 611 | if (fprintf(_fp, "%.*s%.*s %.*s %.*s\r\n", |
| 612 | (int)_prefix.size(), _prefix.data(), |
| 613 | (int)name.size(), name.data(), |
| 614 | (int)separator.size(), separator.data(), |
| 615 | (int)desc.size(), desc.data()) < 0) { |
| 616 | PLOG(ERROR) << "Fail to write into " << _filename; |
| 617 | return false; |
| 618 | } |
| 619 | return true; |
| 620 | } |
| 621 | private: |
| 622 | std::string _filename; |
| 623 | FILE* _fp; |