]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4448: extractor: rewrite std writer to use text_log utility
authorAndrii Serbeniuk -X (aserbeni - SOFTSERVE INC at Cisco) <aserbeni@cisco.com>
Wed, 18 Sep 2024 14:44:28 +0000 (14:44 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Wed, 18 Sep 2024 14:44:28 +0000 (14:44 +0000)
Merge in SNORT/snort3 from ~ASERBENI/snort3:log_perf_ci to master

Squashed commit of the following:

commit 11c5aa69552e778d782dc74bce964d8e2e34378e
Author: Andrii Serbeniuk <aserbeni@cisco.com>
Date:   Fri Sep 6 10:13:34 2024 +0300

    extractor: rewrite std writer to use text_log utility

    This way its output will be written to the same descriptor as ips events. In most of the cases it's stdout, but it can also be descriptor 3 if snort was build with --enable-stdlog

src/network_inspectors/extractor/extractor_writer.cc
src/network_inspectors/extractor/extractor_writer.h

index 227b65f6cc7f4d234d342d20c7e320d8265dde93..7f402a31f39c47cdd79f53353d0835286e470435 100644 (file)
@@ -35,6 +35,19 @@ ExtractorWriter* ExtractorWriter::make_writer(OutputType o_type)
     }
 }
 
+StdExtractorWriter::StdExtractorWriter() : ExtractorWriter(), extr_std_log(snort::TextLog_Init("stdout"))
+{}
+
+StdExtractorWriter::~StdExtractorWriter()
+{
+    snort::TextLog_Term(extr_std_log);
+}
+
+void StdExtractorWriter::write(const char* ss)
+{
+    snort::TextLog_Print(extr_std_log, "%s", ss);
+}
+
 #ifdef UNIT_TEST
 
 #include "catch/snort_catch.h"
index d6551f5cf1f7f4aebb4ac12afc552c8e04f52b3e..a30c912b2a956fb17b9f23fcc9085ab30c5f0ee9 100644 (file)
@@ -23,6 +23,8 @@
 #include <mutex>
 #include <string>
 
+#include "log/text_log.h"
+
 class OutputType
 {
 public:
@@ -77,10 +79,10 @@ protected:
 class StdExtractorWriter : public ExtractorWriter
 {
 public:
-    StdExtractorWriter() = default;
+    StdExtractorWriter();
+    ~StdExtractorWriter() override;
 
-    void write(const char* ss) override
-    { fprintf(stdout, "%s", ss); }
+    void write(const char* ss) override;
 
     void lock() override
     { write_mutex.lock(); }
@@ -90,6 +92,7 @@ public:
 
 private:
     std::mutex write_mutex;
+    TextLog* extr_std_log;
 };
 
 #endif