martinzink commented on code in PR #1482:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1482#discussion_r1098371050


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -699,42 +699,38 @@ void ConsumeWindowsEventLog::refreshTimeZoneData() {
 }
 
 void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const 
EventRender& eventRender, core::ProcessSession& session) const {
-  auto commitFlowFile = [&] (const std::shared_ptr<core::FlowFile>& flowFile, 
const std::string& content, const std::string& mimeType) {
-    session.writeBuffer(flowFile, content);
-    session.putAttribute(flowFile, core::SpecialFlowAttribute::MIME_TYPE, 
mimeType);
-    session.putAttribute(flowFile, "timezone.name", timezone_name_);
-    session.putAttribute(flowFile, "timezone.offset", timezone_offset_);
-    session.getProvenanceReporter()->receive(flowFile, provenanceUri_, 
getUUIDStr(), "Consume windows event logs", 0ms);
-    session.transfer(flowFile, Success);
+  auto commitFlowFile = [&] (const std::string& content, const std::string& 
mimeType) {
+    auto flow_file = session.create();
+    addMatchedFieldsAsAttributes(eventRender, session, flow_file);
+    session.writeBuffer(flow_file, content);
+    session.putAttribute(flow_file, core::SpecialFlowAttribute::MIME_TYPE, 
mimeType);
+    session.putAttribute(flow_file, "timezone.name", timezone_name_);
+    session.putAttribute(flow_file, "timezone.offset", timezone_offset_);
+    session.getProvenanceReporter()->receive(flow_file, provenanceUri_, 
getUUIDStr(), "Consume windows event logs", 0ms);
+    session.transfer(flow_file, Success);
   };
 
   if (output_.xml) {
-    auto flowFile = session.create();
     logger_->log_trace("Writing rendered XML to a flow file");
-
-    for (const auto &fieldMapping : eventRender.matched_fields) {
-      if (!fieldMapping.second.empty()) {
-        session.putAttribute(flowFile, fieldMapping.first, 
fieldMapping.second);
-      }
-    }
-
-    commitFlowFile(flowFile, eventRender.xml, "application/xml");
+    commitFlowFile(eventRender.xml, "application/xml");
   }
 
   if (output_.plaintext) {
     logger_->log_trace("Writing rendered plain text to a flow file");
-    commitFlowFile(session.create(), eventRender.plaintext, "text/plain");
+    commitFlowFile(eventRender.plaintext, "text/plain");
   }
 
-  if (output_.json.type == JSONType::Raw) {
-    logger_->log_trace("Writing rendered raw JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Simple) {
-    logger_->log_trace("Writing rendered simple JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
-  } else if (output_.json.type == JSONType::Flattened) {
-    logger_->log_trace("Writing rendered flattened JSON to a flow file");
-    commitFlowFile(session.create(), eventRender.json, "application/json");
+  if (output_.json.type != JSONType::None) {

Review Comment:
   :+1: good idea, changed it in 
https://github.com/apache/nifi-minifi-cpp/pull/1482/commits/efb169ad2b661a82f1608e80031dfcb7672eab06#diff-0769252d38a0bd8b7b412439a306a061cd5da7b84419220a1aec6e100a853cecR723



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to