bakaid commented on a change in pull request #596: MINIFICPP-925 - Fix TailFile 
hang on long lines
URL: https://github.com/apache/nifi-minifi-cpp/pull/596#discussion_r296895963
 
 

 ##########
 File path: extensions/standard-processors/processors/LogAttribute.cpp
 ##########
 @@ -137,33 +137,32 @@ void LogAttribute::onTrigger(const 
std::shared_ptr<core::ProcessContext> &contex
       message << "\n" << "Payload:" << "\n";
       ReadCallback callback(flow->getSize());
       session->read(flow, &callback);
-      for (unsigned int i = 0, j = 0; i < callback.read_size_; i++) {
-        message << std::hex << callback.buffer_[i];
-        j++;
-        if (j == 80) {
-          message << '\n';
-          j = 0;
-        }
+
+      auto payload_hex = utils::StringUtils::to_hex(callback.buffer_.data(), 
callback.buffer_.size());
+      for (size_t i = 0; i < payload_hex.size(); i += 80) {
+        message << payload_hex.substr(i, 80) << '\n';
       }
+    } else {
+      message << "\n";
     }
-    message << "\n" << dashLine;
+    message << dashLine;
     std::string output = message.str();
 
     switch (level) {
       case LogAttrLevelInfo:
-        logger_->log_info("%s", output);
 
 Review comment:
   As I wrote in the global comment, this is a fix for the truncation issue. An 
another way to solve that would be to either enlarge the log format buffer 
size, or use a dynamic reallocation approach in it, but this seemed a less 
disruptive way to fix the bug.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to