Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/116#discussion_r125020880
--- Diff: libminifi/src/processors/TailFile.cpp ---
@@ -222,27 +233,52 @@ void TailFile::onTrigger(core::ProcessContext
*context, core::ProcessSession *se
checkRollOver(fileLocation, fileName);
std::string fullPath = fileLocation + "/" + _currentTailFileName;
struct stat statbuf;
+
if (stat(fullPath.c_str(), &statbuf) == 0) {
if (statbuf.st_size <= this->_currentTailFilePosition) {
- // there are no new input for the current tail fil
+ // there are no new input for the current tail file
context->yield();
return;
}
- std::shared_ptr<FlowFileRecord> flowFile =
std::static_pointer_cast<FlowFileRecord>(session->create());
- if (!flowFile)
- return;
- std::size_t found = _currentTailFileName.find_last_of(".");
- std::string baseName = _currentTailFileName.substr(0, found);
- std::string extension = _currentTailFileName.substr(found + 1);
- flowFile->updateKeyedAttribute(PATH, fileLocation);
- flowFile->addKeyedAttribute(ABSOLUTE_PATH, fullPath);
- session->import(fullPath, flowFile, true,
this->_currentTailFilePosition);
- session->transfer(flowFile, Success);
- logger_->log_info("TailFile %s for %d bytes",
_currentTailFileName.c_str(), flowFile->getSize());
- std::string logName = baseName + "." +
std::to_string(_currentTailFilePosition) + "-" +
std::to_string(_currentTailFilePosition + flowFile->getSize()) + "." +
extension;
- flowFile->updateKeyedAttribute(FILENAME, logName);
- this->_currentTailFilePosition += flowFile->getSize();
- storeState();
+
+ std::size_t found = _currentTailFileName.find_last_of(".");
+ std::string baseName = _currentTailFileName.substr(0, found);
+ std::string extension = _currentTailFileName.substr(found + 1);
+
+ if (!this->_delimiter.empty()) {
+ char delim = this->_delimiter.c_str()[0];
+ std::shared_ptr<std::vector<std::shared_ptr<FlowFileRecord>>>
flowFiles = std::make_shared<std::vector<std::shared_ptr<FlowFileRecord>>>();
+ session->import(fullPath, flowFiles, true,
this->_currentTailFilePosition, delim);
+ logger_->log_info("%d flowfiles were received from TailFile input",
flowFiles->size());
+
+ for(std::shared_ptr<FlowFileRecord> ffr : *flowFiles) {
+ logger_->log_info("TailFile %s for %d bytes",
_currentTailFileName.c_str(), ffr->getSize());
--- End diff --
One of the changes in the logger removes the need for c_str() calls. You
can simply make this
`logger_->log_info("TailFile %s for %d bytes", _currentTailFileName,
ffr->getSize());`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---