This is an automated email from the ASF dual-hosted git repository. lordgamez pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 30fdfb7ee74c98a6975afb6d26602c26ee381864 Author: Ferenc Gerlits <[email protected]> AuthorDate: Wed Dec 7 16:33:06 2022 +0100 MINIFICPP-1948 Add the UUID to the end of Processor and Controller Service log lines Signed-off-by: Gabor Gyimesi <[email protected]> This closes #1481 --- conf/minifi-log.properties | 3 ++ docker/conf/minifi-log.properties | 3 ++ extensions/aws/processors/DeleteS3Object.h | 4 +- extensions/aws/processors/FetchS3Object.h | 4 +- extensions/aws/processors/ListS3.h | 4 +- extensions/aws/processors/PutS3Object.h | 4 +- extensions/aws/processors/S3Processor.cpp | 5 +- extensions/aws/processors/S3Processor.h | 2 +- .../AzureStorageCredentialsService.h | 2 +- .../processors/AzureBlobStorageProcessorBase.h | 4 -- .../AzureBlobStorageSingleBlobProcessorBase.h | 4 -- .../azure/processors/DeleteAzureDataLakeStorage.h | 2 +- .../azure/processors/FetchAzureDataLakeStorage.h | 2 +- extensions/azure/processors/ListAzureBlobStorage.h | 2 +- .../azure/processors/ListAzureDataLakeStorage.h | 4 +- extensions/bustache/ApplyTemplate.h | 2 +- extensions/civetweb/processors/ListenHTTP.h | 7 ++- .../ElasticsearchCredentialsControllerService.h | 2 +- extensions/elasticsearch/PostElasticsearch.h | 2 +- .../GCPCredentialsControllerService.h | 2 +- extensions/gcp/processors/DeleteGCSObject.h | 2 +- extensions/gcp/processors/FetchGCSObject.h | 2 +- extensions/gcp/processors/ListGCSBucket.h | 2 +- extensions/gcp/processors/PutGCSObject.h | 2 +- extensions/gps/GetGPS.h | 2 +- extensions/http-curl/processors/InvokeHTTP.h | 2 +- extensions/jni/ExecuteJavaControllerService.h | 4 +- extensions/jni/jvm/JavaControllerService.h | 2 +- .../KubernetesControllerService.cpp | 2 +- .../processors/CollectKubernetesPodMetrics.h | 2 +- extensions/libarchive/BinFiles.h | 15 +++--- extensions/libarchive/CompressContent.h | 14 ++---- extensions/libarchive/FocusArchiveEntry.h | 2 +- extensions/libarchive/ManipulateArchive.h | 2 +- extensions/libarchive/MergeContent.cpp | 4 +- extensions/libarchive/MergeContent.h | 16 +++--- extensions/libarchive/UnfocusArchiveEntry.h | 2 +- extensions/librdkafka/ConsumeKafka.h | 11 ++--- extensions/librdkafka/PublishKafka.h | 2 +- extensions/mqtt/processors/AbstractMQTTProcessor.h | 2 +- extensions/mqtt/processors/ConsumeMQTT.h | 2 +- extensions/mqtt/processors/PublishMQTT.h | 2 +- extensions/opc/include/fetchopc.h | 16 +++--- extensions/opc/include/putopc.h | 4 +- extensions/opencv/CaptureRTSPFrame.h | 2 +- extensions/opencv/MotionDetector.h | 2 +- extensions/pcap/CapturePacket.h | 2 +- extensions/procfs/processors/ProcFsMonitor.h | 3 +- extensions/script/ExecuteScript.h | 2 +- extensions/script/python/ExecutePythonProcessor.h | 2 +- extensions/sftp/processors/FetchSFTP.cpp | 6 +-- extensions/sftp/processors/FetchSFTP.h | 4 +- extensions/sftp/processors/ListSFTP.cpp | 21 ++------ extensions/sftp/processors/ListSFTP.h | 28 +++++------ extensions/sftp/processors/PutSFTP.cpp | 15 ++---- extensions/splunk/PutSplunkHTTP.h | 2 +- extensions/sql/processors/ExecuteSQL.cpp | 10 +--- extensions/sql/processors/PutSQL.cpp | 4 +- extensions/sql/processors/QueryDatabaseTable.cpp | 8 +-- extensions/sql/processors/QueryDatabaseTable.h | 3 +- extensions/sql/services/DatabaseService.h | 6 +-- extensions/sql/services/ODBCConnector.h | 6 ++- .../processors/AppendHostInfo.h | 12 ++--- .../processors/AttributesToJSON.h | 2 +- .../processors/DefragmentText.h | 2 +- .../processors/ExecuteProcess.h | 10 ++-- .../standard-processors/processors/ExtractText.h | 2 +- .../standard-processors/processors/FetchFile.h | 2 +- .../processors/GenerateFlowFile.h | 3 +- .../standard-processors/processors/GetFile.h | 2 +- extensions/standard-processors/processors/GetTCP.h | 27 ++++------ .../standard-processors/processors/HashContent.h | 8 +-- .../standard-processors/processors/ListFile.h | 2 +- .../standard-processors/processors/ListenSyslog.h | 2 +- .../standard-processors/processors/ListenTCP.h | 2 +- .../standard-processors/processors/ListenUDP.h | 2 +- .../standard-processors/processors/LogAttribute.h | 19 +++----- .../standard-processors/processors/PutFile.h | 6 +-- extensions/standard-processors/processors/PutTCP.h | 2 +- .../standard-processors/processors/PutUDP.cpp | 2 +- .../standard-processors/processors/ReplaceText.cpp | 2 +- .../standard-processors/processors/RetryFlowFile.h | 2 +- .../processors/RouteOnAttribute.h | 7 +-- .../standard-processors/processors/RouteText.cpp | 6 +-- .../standard-processors/processors/TailFile.h | 2 +- .../processors/UpdateAttribute.h | 7 +-- extensions/systemd/ConsumeJournald.h | 2 +- extensions/tensorflow/TFApplyGraph.h | 2 +- extensions/tensorflow/TFConvertImageToTensor.h | 2 +- extensions/tensorflow/TFExtractTopLabels.h | 2 +- extensions/test-processors/KamikazeProcessor.h | 2 +- .../test-processors/LogOnDestructionProcessor.h | 2 +- extensions/usb-camera/GetUSBCamera.h | 8 +-- .../CollectorInitiatedSubscription.cpp | 2 +- .../windows-event-log/ConsumeWindowsEventLog.cpp | 2 +- libminifi/include/Funnel.h | 2 +- libminifi/include/Port.h | 2 +- libminifi/include/RemoteProcessorGroupPort.h | 2 +- .../controllers/LinuxPowerManagementService.h | 2 +- .../controllers/NetworkPrioritizerService.h | 2 +- libminifi/include/controllers/SSLContextService.h | 5 +- libminifi/include/core/Processor.h | 1 - libminifi/include/core/logging/Logger.h | 57 ++++++++++------------ .../include/core/logging/LoggerConfiguration.h | 27 +++++----- libminifi/include/core/logging/LoggerFactory.h | 9 ++-- libminifi/src/core/Connectable.cpp | 4 +- libminifi/src/core/Processor.cpp | 4 +- libminifi/src/core/logging/LoggerConfiguration.cpp | 30 +++++++----- libminifi/src/core/logging/LoggerFactory.cpp | 4 +- libminifi/test/ReadFromFlowFileTestProcessor.h | 3 +- libminifi/test/TestBase.cpp | 4 +- libminifi/test/TestBase.h | 4 +- libminifi/test/WriteToFlowFileTestProcessor.h | 3 +- libminifi/test/sql-tests/mocks/MockODBCService.h | 2 +- libminifi/test/unit/LoggerTests.cpp | 35 +++++++++++++ nanofi/include/cxx/CallbackProcessor.h | 7 +-- 116 files changed, 319 insertions(+), 353 deletions(-) diff --git a/conf/minifi-log.properties b/conf/minifi-log.properties index db296157b..f27ef967b 100644 --- a/conf/minifi-log.properties +++ b/conf/minifi-log.properties @@ -49,6 +49,9 @@ appender.rolling.max_file_size=5242880 #appender.alert1.level=TRACE #appender.alert1.ssl.context.service=<Name of the SSLContextService> +# Uncomment if you do not want to include the UUID of the component at the end of log lines +#logger.include.uuid=false + logger.root=INFO,rolling #Logging configurable by namespace diff --git a/docker/conf/minifi-log.properties b/docker/conf/minifi-log.properties index 459db5085..6b01d285e 100644 --- a/docker/conf/minifi-log.properties +++ b/docker/conf/minifi-log.properties @@ -38,6 +38,9 @@ appender.stderr=stderr ## The syslog appender will log using syslog(3) on *nix, and to the Windows Event Log on Windows #appender.syslog=syslog +# Uncomment if you do not want to include the UUID of the component at the end of log lines +#logger.include.uuid=false + logger.root=INFO,stderr #Logging configurable by namespace diff --git a/extensions/aws/processors/DeleteS3Object.h b/extensions/aws/processors/DeleteS3Object.h index 1e5c1ca9c..e3769570c 100644 --- a/extensions/aws/processors/DeleteS3Object.h +++ b/extensions/aws/processors/DeleteS3Object.h @@ -57,7 +57,7 @@ class DeleteS3Object : public S3Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit DeleteS3Object(const std::string& name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : S3Processor(name, uuid, core::logging::LoggerFactory<DeleteS3Object>::getLogger()) { + : S3Processor(name, uuid, core::logging::LoggerFactory<DeleteS3Object>::getLogger(uuid)) { } ~DeleteS3Object() override = default; @@ -69,7 +69,7 @@ class DeleteS3Object : public S3Processor { friend class ::S3TestsFixture<DeleteS3Object>; explicit DeleteS3Object(std::string name, const minifi::utils::Identifier& uuid, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) - : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<DeleteS3Object>::getLogger(), std::move(s3_request_sender)) { + : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<DeleteS3Object>::getLogger(uuid), std::move(s3_request_sender)) { } std::optional<aws::s3::DeleteObjectRequestParameters> buildDeleteS3RequestParams( diff --git a/extensions/aws/processors/FetchS3Object.h b/extensions/aws/processors/FetchS3Object.h index afb8e7902..e9e837e77 100644 --- a/extensions/aws/processors/FetchS3Object.h +++ b/extensions/aws/processors/FetchS3Object.h @@ -61,7 +61,7 @@ class FetchS3Object : public S3Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit FetchS3Object(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<FetchS3Object>::getLogger()) { + : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<FetchS3Object>::getLogger(uuid)) { } ~FetchS3Object() override = default; @@ -74,7 +74,7 @@ class FetchS3Object : public S3Processor { friend class ::S3TestsFixture<FetchS3Object>; explicit FetchS3Object(const std::string& name, const minifi::utils::Identifier& uuid, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) - : S3Processor(name, uuid, core::logging::LoggerFactory<FetchS3Object>::getLogger(), std::move(s3_request_sender)) { + : S3Processor(name, uuid, core::logging::LoggerFactory<FetchS3Object>::getLogger(uuid), std::move(s3_request_sender)) { } std::optional<aws::s3::GetObjectRequestParameters> buildFetchS3RequestParams( diff --git a/extensions/aws/processors/ListS3.h b/extensions/aws/processors/ListS3.h index db1ddb49d..2381af106 100644 --- a/extensions/aws/processors/ListS3.h +++ b/extensions/aws/processors/ListS3.h @@ -63,10 +63,10 @@ class ListS3 : public S3Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit ListS3(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<ListS3>::getLogger()) { + : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<ListS3>::getLogger(uuid)) { } explicit ListS3(const std::string& name, minifi::utils::Identifier uuid, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) - : S3Processor(name, uuid, core::logging::LoggerFactory<ListS3>::getLogger(), std::move(s3_request_sender)) { + : S3Processor(name, uuid, core::logging::LoggerFactory<ListS3>::getLogger(uuid), std::move(s3_request_sender)) { } ~ListS3() override = default; diff --git a/extensions/aws/processors/PutS3Object.h b/extensions/aws/processors/PutS3Object.h index 6a743e9b4..b131d5d6e 100644 --- a/extensions/aws/processors/PutS3Object.h +++ b/extensions/aws/processors/PutS3Object.h @@ -81,7 +81,7 @@ class PutS3Object : public S3Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit PutS3Object(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<PutS3Object>::getLogger()) { + : S3Processor(std::move(name), uuid, core::logging::LoggerFactory<PutS3Object>::getLogger(uuid)) { } ~PutS3Object() override = default; @@ -137,7 +137,7 @@ class PutS3Object : public S3Processor { friend class ::S3TestsFixture<PutS3Object>; explicit PutS3Object(const std::string& name, const minifi::utils::Identifier& uuid, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) - : S3Processor(name, uuid, core::logging::LoggerFactory<PutS3Object>::getLogger(), std::move(s3_request_sender)) { + : S3Processor(name, uuid, core::logging::LoggerFactory<PutS3Object>::getLogger(uuid), std::move(s3_request_sender)) { } void fillUserMetadata(const std::shared_ptr<core::ProcessContext> &context); diff --git a/extensions/aws/processors/S3Processor.cpp b/extensions/aws/processors/S3Processor.cpp index 5503f9405..695bc9a10 100644 --- a/extensions/aws/processors/S3Processor.cpp +++ b/extensions/aws/processors/S3Processor.cpp @@ -18,7 +18,6 @@ #include "S3Processor.h" #include <string> -#include <set> #include <memory> #include <utility> @@ -35,8 +34,8 @@ S3Processor::S3Processor(std::string name, const minifi::utils::Identifier& uuid logger_(std::move(logger)) { } -S3Processor::S3Processor(const std::string& name, const minifi::utils::Identifier& uuid, std::shared_ptr<core::logging::Logger> logger, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) - : core::Processor(name, uuid), +S3Processor::S3Processor(std::string name, const minifi::utils::Identifier& uuid, std::shared_ptr<core::logging::Logger> logger, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender) + : core::Processor(std::move(name), uuid), logger_(std::move(logger)), s3_wrapper_(std::move(s3_request_sender)) { } diff --git a/extensions/aws/processors/S3Processor.h b/extensions/aws/processors/S3Processor.h index d1c522456..0e7b1c780 100644 --- a/extensions/aws/processors/S3Processor.h +++ b/extensions/aws/processors/S3Processor.h @@ -116,7 +116,7 @@ class S3Processor : public core::Processor { void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override; protected: - explicit S3Processor(const std::string& name, const minifi::utils::Identifier& uuid, std::shared_ptr<core::logging::Logger> logger, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender); + explicit S3Processor(std::string name, const minifi::utils::Identifier& uuid, std::shared_ptr<core::logging::Logger> logger, std::unique_ptr<aws::s3::S3RequestSender> s3_request_sender); std::optional<Aws::Auth::AWSCredentials> getAWSCredentialsFromControllerService(const std::shared_ptr<core::ProcessContext> &context) const; std::optional<Aws::Auth::AWSCredentials> getAWSCredentials(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::FlowFile> &flow_file); diff --git a/extensions/azure/controllerservices/AzureStorageCredentialsService.h b/extensions/azure/controllerservices/AzureStorageCredentialsService.h index b6d6f1593..2bc95526b 100644 --- a/extensions/azure/controllerservices/AzureStorageCredentialsService.h +++ b/extensions/azure/controllerservices/AzureStorageCredentialsService.h @@ -82,7 +82,7 @@ class AzureStorageCredentialsService : public core::controller::ControllerServic private: storage::AzureStorageCredentials credentials_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AzureStorageCredentialsService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AzureStorageCredentialsService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::azure::controllers diff --git a/extensions/azure/processors/AzureBlobStorageProcessorBase.h b/extensions/azure/processors/AzureBlobStorageProcessorBase.h index a053445ec..de771c620 100644 --- a/extensions/azure/processors/AzureBlobStorageProcessorBase.h +++ b/extensions/azure/processors/AzureBlobStorageProcessorBase.h @@ -55,10 +55,6 @@ class AzureBlobStorageProcessorBase : public AzureStorageProcessorBase { }); } - explicit AzureBlobStorageProcessorBase(std::string name, const minifi::utils::Identifier& uuid, const std::shared_ptr<core::logging::Logger>& logger) - : AzureBlobStorageProcessorBase(std::move(name), uuid, logger, nullptr) { - } - void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override; protected: diff --git a/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h b/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h index 67be0f5d8..1250391dc 100644 --- a/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h +++ b/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h @@ -37,10 +37,6 @@ class AzureBlobStorageSingleBlobProcessorBase : public AzureBlobStorageProcessor return utils::array_cat(AzureBlobStorageProcessorBase::properties(), std::array{Blob}); } - explicit AzureBlobStorageSingleBlobProcessorBase(std::string name, const minifi::utils::Identifier& uuid, const std::shared_ptr<core::logging::Logger>& logger) - : AzureBlobStorageSingleBlobProcessorBase(std::move(name), uuid, logger, nullptr) { - } - protected: explicit AzureBlobStorageSingleBlobProcessorBase( std::string name, diff --git a/extensions/azure/processors/DeleteAzureDataLakeStorage.h b/extensions/azure/processors/DeleteAzureDataLakeStorage.h index b4135d7b7..312761e43 100644 --- a/extensions/azure/processors/DeleteAzureDataLakeStorage.h +++ b/extensions/azure/processors/DeleteAzureDataLakeStorage.h @@ -49,7 +49,7 @@ class DeleteAzureDataLakeStorage final : public AzureDataLakeStorageFileProcesso ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit DeleteAzureDataLakeStorage(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : AzureDataLakeStorageFileProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<DeleteAzureDataLakeStorage>::getLogger()) { + : AzureDataLakeStorageFileProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<DeleteAzureDataLakeStorage>::getLogger(uuid)) { } ~DeleteAzureDataLakeStorage() override = default; diff --git a/extensions/azure/processors/FetchAzureDataLakeStorage.h b/extensions/azure/processors/FetchAzureDataLakeStorage.h index a1e7785d8..01007f5f1 100644 --- a/extensions/azure/processors/FetchAzureDataLakeStorage.h +++ b/extensions/azure/processors/FetchAzureDataLakeStorage.h @@ -57,7 +57,7 @@ class FetchAzureDataLakeStorage final : public AzureDataLakeStorageFileProcessor ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit FetchAzureDataLakeStorage(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : AzureDataLakeStorageFileProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<FetchAzureDataLakeStorage>::getLogger()) { + : AzureDataLakeStorageFileProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<FetchAzureDataLakeStorage>::getLogger(uuid)) { } ~FetchAzureDataLakeStorage() override = default; diff --git a/extensions/azure/processors/ListAzureBlobStorage.h b/extensions/azure/processors/ListAzureBlobStorage.h index e552fd18d..ca4603e96 100644 --- a/extensions/azure/processors/ListAzureBlobStorage.h +++ b/extensions/azure/processors/ListAzureBlobStorage.h @@ -65,7 +65,7 @@ class ListAzureBlobStorage final : public AzureBlobStorageProcessorBase { } explicit ListAzureBlobStorage(std::string name, std::unique_ptr<storage::BlobStorageClient> blob_storage_client, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : AzureBlobStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureBlobStorage>::getLogger(), std::move(blob_storage_client)) { + : AzureBlobStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureBlobStorage>::getLogger(uuid), std::move(blob_storage_client)) { } void initialize() override; diff --git a/extensions/azure/processors/ListAzureDataLakeStorage.h b/extensions/azure/processors/ListAzureDataLakeStorage.h index 93a0335a8..bc8a64b9b 100644 --- a/extensions/azure/processors/ListAzureDataLakeStorage.h +++ b/extensions/azure/processors/ListAzureDataLakeStorage.h @@ -64,7 +64,7 @@ class ListAzureDataLakeStorage final : public AzureDataLakeStorageProcessorBase ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit ListAzureDataLakeStorage(std::string name, const minifi::utils::Identifier& uuid = minifi::utils::Identifier()) - : AzureDataLakeStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureDataLakeStorage>::getLogger()) { + : AzureDataLakeStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureDataLakeStorage>::getLogger(uuid)) { } ~ListAzureDataLakeStorage() override = default; @@ -77,7 +77,7 @@ class ListAzureDataLakeStorage final : public AzureDataLakeStorageProcessorBase friend class ::ListAzureDataLakeStorageTestsFixture; explicit ListAzureDataLakeStorage(std::string name, const minifi::utils::Identifier& uuid, std::unique_ptr<storage::DataLakeStorageClient> data_lake_storage_client) - : AzureDataLakeStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureDataLakeStorage>::getLogger(), std::move(data_lake_storage_client)) { + : AzureDataLakeStorageProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ListAzureDataLakeStorage>::getLogger(uuid), std::move(data_lake_storage_client)) { } std::optional<storage::ListAzureDataLakeStorageParameters> buildListParameters(core::ProcessContext& context); diff --git a/extensions/bustache/ApplyTemplate.h b/extensions/bustache/ApplyTemplate.h index 5f7d22445..a6b03eae7 100644 --- a/extensions/bustache/ApplyTemplate.h +++ b/extensions/bustache/ApplyTemplate.h @@ -57,7 +57,7 @@ class ApplyTemplate : public core::Processor { void initialize() override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ApplyTemplate>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ApplyTemplate>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/civetweb/processors/ListenHTTP.h b/extensions/civetweb/processors/ListenHTTP.h index a43a17508..314a92390 100644 --- a/extensions/civetweb/processors/ListenHTTP.h +++ b/extensions/civetweb/processors/ListenHTTP.h @@ -43,8 +43,7 @@ class ListenHTTP : public core::Processor { using FlowFileBufferPair = std::pair<std::shared_ptr<FlowFileRecord>, std::unique_ptr<io::BufferStream>>; explicit ListenHTTP(std::string name, const utils::Identifier& uuid = {}) - : Processor(std::move(name), uuid), - batch_size_(0) { + : Processor(std::move(name), uuid) { callbacks_.log_message = &logMessage; callbacks_.log_access = &logAccess; } @@ -190,12 +189,12 @@ class ListenHTTP : public core::Processor { bool processIncomingFlowFile(core::ProcessSession &session); bool processRequestBuffer(core::ProcessSession &session); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ListenHTTP>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ListenHTTP>::getLogger(uuid_); CivetCallbacks callbacks_; std::unique_ptr<CivetServer> server_; std::unique_ptr<Handler> handler_; std::string listeningPort; - uint64_t batch_size_; + uint64_t batch_size_{0}; }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h index 0d0992f1f..ebd80e6d9 100644 --- a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h +++ b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h @@ -68,6 +68,6 @@ class ElasticsearchCredentialsControllerService : public core::controller::Contr private: std::optional<std::pair<std::string, std::string>> username_password_; std::optional<std::string> api_key_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ElasticsearchCredentialsControllerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ElasticsearchCredentialsControllerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::extensions::elasticsearch diff --git a/extensions/elasticsearch/PostElasticsearch.h b/extensions/elasticsearch/PostElasticsearch.h index a8fe7becc..bbe080351 100644 --- a/extensions/elasticsearch/PostElasticsearch.h +++ b/extensions/elasticsearch/PostElasticsearch.h @@ -85,7 +85,7 @@ class PostElasticsearch : public core::Processor { std::string host_url_; std::shared_ptr<ElasticsearchCredentialsControllerService> credentials_service_; curl::HTTPClient client_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PostElasticsearch>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PostElasticsearch>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::extensions::elasticsearch diff --git a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h index a3d1b30ca..ae51fa472 100644 --- a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h +++ b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h @@ -80,6 +80,6 @@ class GCPCredentialsControllerService : public core::controller::ControllerServi std::shared_ptr<google::cloud::storage::oauth2::Credentials> credentials_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GCPCredentialsControllerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GCPCredentialsControllerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::extensions::gcp diff --git a/extensions/gcp/processors/DeleteGCSObject.h b/extensions/gcp/processors/DeleteGCSObject.h index e3dd886e7..024d17c10 100644 --- a/extensions/gcp/processors/DeleteGCSObject.h +++ b/extensions/gcp/processors/DeleteGCSObject.h @@ -30,7 +30,7 @@ namespace org::apache::nifi::minifi::extensions::gcp { class DeleteGCSObject : public GCSProcessor { public: explicit DeleteGCSObject(std::string name, const utils::Identifier& uuid = {}) - : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<DeleteGCSObject>::getLogger()) { + : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<DeleteGCSObject>::getLogger(uuid)) { } ~DeleteGCSObject() override = default; diff --git a/extensions/gcp/processors/FetchGCSObject.h b/extensions/gcp/processors/FetchGCSObject.h index 3036ff976..13845012c 100644 --- a/extensions/gcp/processors/FetchGCSObject.h +++ b/extensions/gcp/processors/FetchGCSObject.h @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::extensions::gcp { class FetchGCSObject : public GCSProcessor { public: explicit FetchGCSObject(std::string name, const utils::Identifier& uuid = {}) - : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<FetchGCSObject>::getLogger()) { + : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<FetchGCSObject>::getLogger(uuid)) { } ~FetchGCSObject() override = default; diff --git a/extensions/gcp/processors/ListGCSBucket.h b/extensions/gcp/processors/ListGCSBucket.h index 88e25ee99..df85c4b0f 100644 --- a/extensions/gcp/processors/ListGCSBucket.h +++ b/extensions/gcp/processors/ListGCSBucket.h @@ -30,7 +30,7 @@ namespace org::apache::nifi::minifi::extensions::gcp { class ListGCSBucket : public GCSProcessor { public: explicit ListGCSBucket(std::string name, const utils::Identifier& uuid = {}) - : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListGCSBucket>::getLogger()) { + : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListGCSBucket>::getLogger(uuid)) { } ~ListGCSBucket() override = default; diff --git a/extensions/gcp/processors/PutGCSObject.h b/extensions/gcp/processors/PutGCSObject.h index 94d5ad53e..b96e849a1 100644 --- a/extensions/gcp/processors/PutGCSObject.h +++ b/extensions/gcp/processors/PutGCSObject.h @@ -41,7 +41,7 @@ class PutGCSObject : public GCSProcessor { (PUBLIC_READ_WRITE, "publicReadWrite")); explicit PutGCSObject(std::string name, const utils::Identifier& uuid = {}) - : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<PutGCSObject>::getLogger()) { + : GCSProcessor(std::move(name), uuid, core::logging::LoggerFactory<PutGCSObject>::getLogger(uuid)) { } ~PutGCSObject() override = default; diff --git a/extensions/gps/GetGPS.h b/extensions/gps/GetGPS.h index 50e294525..133c4e740 100644 --- a/extensions/gps/GetGPS.h +++ b/extensions/gps/GetGPS.h @@ -69,7 +69,7 @@ class GetGPS : public core::Processor { std::string gpsdHost_; std::string gpsdPort_; int64_t gpsdWaitTime_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetGPS>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetGPS>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/http-curl/processors/InvokeHTTP.h b/extensions/http-curl/processors/InvokeHTTP.h index cfc617464..39cb55a6e 100644 --- a/extensions/http-curl/processors/InvokeHTTP.h +++ b/extensions/http-curl/processors/InvokeHTTP.h @@ -160,7 +160,7 @@ class InvokeHTTP : public core::Processor { InvalidHTTPHeaderFieldHandlingOption invalid_http_header_field_handling_strategy_; - std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<InvokeHTTP>::getLogger()}; + std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<InvokeHTTP>::getLogger(uuid_)}; std::shared_ptr<utils::ResourceQueue<extensions::curl::HTTPClient>> client_queue_; }; diff --git a/extensions/jni/ExecuteJavaControllerService.h b/extensions/jni/ExecuteJavaControllerService.h index 3d0622147..43e5102b2 100644 --- a/extensions/jni/ExecuteJavaControllerService.h +++ b/extensions/jni/ExecuteJavaControllerService.h @@ -82,7 +82,7 @@ class ExecuteJavaControllerService : public ConfigurationContext, public std::en try { if (!onEnabledName.first.empty()) - current_cs_class.callVoidMethod(env, clazzInstance, onEnabledName.first.c_str(), onEnabledName.second); + current_cs_class.callVoidMethod(env, clazzInstance, onEnabledName.first, onEnabledName.second); } catch (std::runtime_error &re) { // this is avoidable. } @@ -133,7 +133,7 @@ class ExecuteJavaControllerService : public ConfigurationContext, public std::en std::string class_name_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteJavaControllerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteJavaControllerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::jni::controllers diff --git a/extensions/jni/jvm/JavaControllerService.h b/extensions/jni/jvm/JavaControllerService.h index 7b7ebf547..854240094 100644 --- a/extensions/jni/jvm/JavaControllerService.h +++ b/extensions/jni/jvm/JavaControllerService.h @@ -155,7 +155,7 @@ class JavaControllerService : public core::controller::ControllerService, public JVMLoader *loader = nullptr; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<JavaControllerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<JavaControllerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::jni::controllers diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp index 24f3b9a4a..cc1ab5059 100644 --- a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp +++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp @@ -48,7 +48,7 @@ const core::Property KubernetesControllerService::ContainerNameFilter{ KubernetesControllerService::KubernetesControllerService(const std::string& name, const utils::Identifier& uuid) : AttributeProviderService(name, uuid), - logger_{core::logging::LoggerFactory<KubernetesControllerService>::getLogger()} { + logger_{core::logging::LoggerFactory<KubernetesControllerService>::getLogger(uuid)} { } KubernetesControllerService::KubernetesControllerService(const std::string& name, const std::shared_ptr<Configure>& configuration) diff --git a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h index b1e922033..9fd1cb9af 100644 --- a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h +++ b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h @@ -54,7 +54,7 @@ class CollectKubernetesPodMetrics : public core::Processor { void onTrigger(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSession>& session) override; private: - gsl::not_null<std::shared_ptr<core::logging::Logger>> logger_ = gsl::make_not_null(core::logging::LoggerFactory<CollectKubernetesPodMetrics>::getLogger()); + gsl::not_null<std::shared_ptr<core::logging::Logger>> logger_ = gsl::make_not_null(core::logging::LoggerFactory<CollectKubernetesPodMetrics>::getLogger(uuid_)); std::shared_ptr<controllers::KubernetesControllerService> kubernetes_controller_service_; }; diff --git a/extensions/libarchive/BinFiles.h b/extensions/libarchive/BinFiles.h index dcc55974f..381827361 100644 --- a/extensions/libarchive/BinFiles.h +++ b/extensions/libarchive/BinFiles.h @@ -24,6 +24,8 @@ #include <string> #include <set> #include <map> +#include <utility> + #include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" @@ -42,13 +44,13 @@ class Bin { /*! * Create a new Bin. Note: this object is not thread safe */ - explicit Bin(const uint64_t &minSize, const uint64_t &maxSize, const size_t &minEntries, const size_t & maxEntries, const std::string &fileCount, const std::string &groupId) + explicit Bin(const uint64_t &minSize, const uint64_t &maxSize, const size_t &minEntries, const size_t & maxEntries, std::string fileCount, std::string groupId) : minSize_(minSize), maxSize_(maxSize), maxEntries_(maxEntries), minEntries_(minEntries), - fileCount_(fileCount), - groupId_(groupId) { + fileCount_(std::move(fileCount)), + groupId_(std::move(groupId)) { queued_data_size_ = 0; creation_dated_ = std::chrono::system_clock::now(); uuid_ = utils::IdGenerator::getIdGenerator()->generate(); @@ -73,7 +75,7 @@ class Bin { return queue_; } // offer the flowfile to the bin - bool offer(std::shared_ptr<core::FlowFile> flow) { + bool offer(const std::shared_ptr<core::FlowFile>& flow) { if (!fileCount_.empty()) { std::string value; if (flow->getAttribute(fileCount_, value)) { @@ -243,7 +245,6 @@ class BinFiles : public core::Processor { EXTENSIONAPI static const char *SEGMENT_ORIGINAL_FILENAME; EXTENSIONAPI static const char *TAR_PERMISSIONS_ATTRIBUTE; - public: void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory *sessionFactory) override; void onTrigger(core::ProcessContext* /*context*/, core::ProcessSession* /*session*/) override { } @@ -258,7 +259,7 @@ class BinFiles : public core::Processor { // Allows general pre-processing of a flow file before it is offered to a bin. This is called before getGroupId(). virtual void preprocessFlowFile(core::ProcessContext *context, core::ProcessSession *session, const std::shared_ptr<core::FlowFile>& flow); // Returns a group ID representing a bin. This allows flow files to be binned into like groups - virtual std::string getGroupId(core::ProcessContext* /*context*/, std::shared_ptr<core::FlowFile> /*flow*/) { + virtual std::string getGroupId(core::ProcessContext* /*context*/, const std::shared_ptr<core::FlowFile>& /*flow*/) { return ""; } // Processes a single bin. @@ -273,7 +274,7 @@ class BinFiles : public core::Processor { BinManager binManager_; private: - std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<BinFiles>::getLogger()}; + std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<BinFiles>::getLogger(uuid_)}; uint32_t batchSize_{1}; uint32_t maxBinCount_{100}; core::FlowFileStore file_store_; diff --git a/extensions/libarchive/CompressContent.h b/extensions/libarchive/CompressContent.h index 1e71af22b..d221bbc38 100644 --- a/extensions/libarchive/CompressContent.h +++ b/extensions/libarchive/CompressContent.h @@ -47,9 +47,7 @@ namespace org::apache::nifi::minifi::processors { class CompressContent : public core::Processor { public: explicit CompressContent(std::string name, const utils::Identifier& uuid = {}) - : core::Processor(std::move(name), uuid) - , updateFileName_(false) - , encapsulateInTar_(false) { + : core::Processor(std::move(name), uuid) { } ~CompressContent() override = default; @@ -95,11 +93,10 @@ class CompressContent : public core::Processor { (USE_MIME_TYPE, "use mime.type attribute") ) - public: class GzipWriteCallback { public: GzipWriteCallback(CompressionMode compress_mode, int compress_level, std::shared_ptr<core::FlowFile> flow, std::shared_ptr<core::ProcessSession> session) - : compress_mode_(std::move(compress_mode)) + : compress_mode_(compress_mode) , compress_level_(compress_level) , flow_(std::move(flow)) , session_(std::move(session)) { @@ -146,7 +143,6 @@ class CompressContent : public core::Processor { } }; - public: /** * Function that's executed when the processor is scheduled. * @param context process context. @@ -167,12 +163,12 @@ class CompressContent : public core::Processor { void processFlowFile(const std::shared_ptr<core::FlowFile>& flowFile, const std::shared_ptr<core::ProcessSession>& session); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CompressContent>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CompressContent>::getLogger(uuid_); int compressLevel_{}; CompressionMode compressMode_; ExtendedCompressionFormat compressFormat_; - bool updateFileName_; - bool encapsulateInTar_; + bool updateFileName_ = false; + bool encapsulateInTar_ = false; uint32_t batchSize_{1}; static const std::map<std::string, io::CompressionFormat> compressionFormatMimeTypeMap_; static const std::map<io::CompressionFormat, std::string> fileExtension_; diff --git a/extensions/libarchive/FocusArchiveEntry.h b/extensions/libarchive/FocusArchiveEntry.h index 25a349711..874b3bdc0 100644 --- a/extensions/libarchive/FocusArchiveEntry.h +++ b/extensions/libarchive/FocusArchiveEntry.h @@ -76,7 +76,7 @@ class FocusArchiveEntry : public core::Processor { }; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<FocusArchiveEntry>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<FocusArchiveEntry>::getLogger(uuid_); static std::shared_ptr<utils::IdGenerator> id_generator_; }; diff --git a/extensions/libarchive/ManipulateArchive.h b/extensions/libarchive/ManipulateArchive.h index a47309894..f4e53a423 100644 --- a/extensions/libarchive/ManipulateArchive.h +++ b/extensions/libarchive/ManipulateArchive.h @@ -80,7 +80,7 @@ class ManipulateArchive : public core::Processor { void initialize() override; private: - std::shared_ptr<Logger> logger_ = core::logging::LoggerFactory<ManipulateArchive>::getLogger(); + std::shared_ptr<Logger> logger_ = core::logging::LoggerFactory<ManipulateArchive>::getLogger(uuid_); std::string before_, after_, operation_, destination_, targetEntry_; }; diff --git a/extensions/libarchive/MergeContent.cpp b/extensions/libarchive/MergeContent.cpp index 9af2194b7..22cce6177 100644 --- a/extensions/libarchive/MergeContent.cpp +++ b/extensions/libarchive/MergeContent.cpp @@ -43,7 +43,7 @@ std::string MergeContent::readContent(const std::string& path) { in.seekg(0, std::ios::end); contents.resize(gsl::narrow<size_t>(in.tellg())); in.seekg(0, std::ios::beg); - in.read(contents.data(), contents.size()); + in.read(contents.data(), gsl::narrow<std::streamsize>(contents.size())); in.close(); } return (contents); @@ -128,7 +128,7 @@ void MergeContent::validatePropertyOptions() { } } -std::string MergeContent::getGroupId(core::ProcessContext*, std::shared_ptr<core::FlowFile> flow) { +std::string MergeContent::getGroupId(core::ProcessContext*, const std::shared_ptr<core::FlowFile>& flow) { std::string groupId; std::string value; if (!correlationAttributeName_.empty()) { diff --git a/extensions/libarchive/MergeContent.h b/extensions/libarchive/MergeContent.h index 7880c13da..3d32b4847 100644 --- a/extensions/libarchive/MergeContent.h +++ b/extensions/libarchive/MergeContent.h @@ -170,8 +170,8 @@ class ArchiveMerge { FlowFileSerializer& serializer_; static la_ssize_t archive_write(struct archive* /*arch*/, void *context, const void *buff, size_t size) { - WriteCallback *callback = reinterpret_cast<WriteCallback *>(context); - uint8_t* data = reinterpret_cast<uint8_t*>(const_cast<void*>(buff)); + auto* callback = reinterpret_cast<WriteCallback *>(context); + auto* data = reinterpret_cast<uint8_t*>(const_cast<void*>(buff)); la_ssize_t totalWrote = 0; size_t remaining = size; while (remaining > 0) { @@ -203,14 +203,14 @@ class ArchiveMerge { archive_write_set_bytes_per_block(arch, 0); archive_write_add_filter_none(arch); stream_ = stream; - archive_write_open(arch, this, NULL, archive_write, NULL); + archive_write_open(arch, this, nullptr, archive_write, nullptr); - for (auto flow : flows_) { + for (const auto& flow : flows_) { struct archive_entry *entry = archive_entry_new(); std::string fileName; flow->getAttribute(core::SpecialFlowAttribute::FILENAME, fileName); archive_entry_set_pathname(entry, fileName.c_str()); - archive_entry_set_size(entry, flow->getSize()); + archive_entry_set_size(entry, gsl::narrow<la_int64_t>(flow->getSize())); archive_entry_set_mode(entry, S_IFREG | 0755); if (merge_type_ == merge_content_options::MERGE_FORMAT_TAR_VALUE) { std::string perm; @@ -233,7 +233,7 @@ class ArchiveMerge { archive_write_close(arch); archive_write_free(arch); - return size_; + return gsl::narrow<int64_t>(size_); } }; }; @@ -343,14 +343,14 @@ class MergeContent : public processors::BinFiles { protected: // Returns a group ID representing a bin. This allows flow files to be binned into like groups - std::string getGroupId(core::ProcessContext *context, std::shared_ptr<core::FlowFile> flow) override; + std::string getGroupId(core::ProcessContext *context, const std::shared_ptr<core::FlowFile>& flow) override; // check whether the defragment bin is validate static bool checkDefragment(std::unique_ptr<Bin> &bin); private: void validatePropertyOptions(); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<MergeContent>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<MergeContent>::getLogger(uuid_); std::string mergeStrategy_; std::string mergeFormat_; std::string correlationAttributeName_; diff --git a/extensions/libarchive/UnfocusArchiveEntry.h b/extensions/libarchive/UnfocusArchiveEntry.h index f0643bcbe..f36b1cf54 100644 --- a/extensions/libarchive/UnfocusArchiveEntry.h +++ b/extensions/libarchive/UnfocusArchiveEntry.h @@ -75,7 +75,7 @@ class UnfocusArchiveEntry : public core::Processor { }; private: - std::shared_ptr<Logger> logger_ = core::logging::LoggerFactory<UnfocusArchiveEntry>::getLogger(); + std::shared_ptr<Logger> logger_ = core::logging::LoggerFactory<UnfocusArchiveEntry>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/librdkafka/ConsumeKafka.h b/extensions/librdkafka/ConsumeKafka.h index c6107a5a7..634b5b83f 100644 --- a/extensions/librdkafka/ConsumeKafka.h +++ b/extensions/librdkafka/ConsumeKafka.h @@ -134,7 +134,7 @@ class ConsumeKafka : public KafkaProcessorBase { static constexpr const std::size_t METADATA_COMMUNICATIONS_TIMEOUT_MS{ 60000 }; explicit ConsumeKafka(std::string name, const utils::Identifier& uuid = utils::Identifier()) : - KafkaProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ConsumeKafka>::getLogger()) {} + KafkaProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<ConsumeKafka>::getLogger(uuid)) {} ~ConsumeKafka() override = default; @@ -157,11 +157,10 @@ class ConsumeKafka : public KafkaProcessorBase { std::optional<std::vector<std::shared_ptr<FlowFileRecord>>> transform_pending_messages_into_flowfiles(core::ProcessSession& session) const; void process_pending_messages(core::ProcessSession& session); - private: std::string kafka_brokers_; std::vector<std::string> topic_names_; std::string topic_name_format_; - bool honor_transactions_; + bool honor_transactions_{}; std::string group_id_; std::string offset_reset_; std::string key_attribute_encoding_; @@ -169,9 +168,9 @@ class ConsumeKafka : public KafkaProcessorBase { std::string message_header_encoding_; std::string duplicate_header_handling_; std::vector<std::string> headers_to_add_as_attributes_; - std::size_t max_poll_records_; - std::chrono::milliseconds max_poll_time_milliseconds_; - std::chrono::milliseconds session_timeout_milliseconds_; + std::size_t max_poll_records_{}; + std::chrono::milliseconds max_poll_time_milliseconds_{}; + std::chrono::milliseconds session_timeout_milliseconds_{}; std::unique_ptr<rd_kafka_t, utils::rd_kafka_consumer_deleter> consumer_; std::unique_ptr<rd_kafka_conf_t, utils::rd_kafka_conf_deleter> conf_; diff --git a/extensions/librdkafka/PublishKafka.h b/extensions/librdkafka/PublishKafka.h index 095d3d13d..329f82947 100644 --- a/extensions/librdkafka/PublishKafka.h +++ b/extensions/librdkafka/PublishKafka.h @@ -123,7 +123,7 @@ class PublishKafka : public KafkaProcessorBase { static constexpr const char* KAFKA_KEY_ATTRIBUTE = "kafka.key"; explicit PublishKafka(std::string name, const utils::Identifier& uuid = {}) - : KafkaProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<PublishKafka>::getLogger()) { + : KafkaProcessorBase(std::move(name), uuid, core::logging::LoggerFactory<PublishKafka>::getLogger(uuid)) { } ~PublishKafka() override = default; diff --git a/extensions/mqtt/processors/AbstractMQTTProcessor.h b/extensions/mqtt/processors/AbstractMQTTProcessor.h index 281bcc75f..d9c1458df 100644 --- a/extensions/mqtt/processors/AbstractMQTTProcessor.h +++ b/extensions/mqtt/processors/AbstractMQTTProcessor.h @@ -206,7 +206,7 @@ class AbstractMQTTProcessor : public core::Processor { uint32_t last_will_qos_ = MQTT_QOS_1; bool last_will_retain_ = false; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AbstractMQTTProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AbstractMQTTProcessor>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/mqtt/processors/ConsumeMQTT.h b/extensions/mqtt/processors/ConsumeMQTT.h index 1e104584b..3486c526c 100644 --- a/extensions/mqtt/processors/ConsumeMQTT.h +++ b/extensions/mqtt/processors/ConsumeMQTT.h @@ -121,7 +121,7 @@ class ConsumeMQTT : public processors::AbstractMQTTProcessor { void checkProperties() override; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ConsumeMQTT>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ConsumeMQTT>::getLogger(uuid_); bool cleanSession_ = true; uint64_t maxQueueSize_; moodycamel::ConcurrentQueue<std::unique_ptr<MQTTAsync_message, MQTTMessageDeleter>> queue_; diff --git a/extensions/mqtt/processors/PublishMQTT.h b/extensions/mqtt/processors/PublishMQTT.h index 30e3369bc..12acbd524 100644 --- a/extensions/mqtt/processors/PublishMQTT.h +++ b/extensions/mqtt/processors/PublishMQTT.h @@ -128,7 +128,7 @@ class PublishMQTT : public processors::AbstractMQTTProcessor { } bool retain_ = false; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PublishMQTT>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PublishMQTT>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/opc/include/fetchopc.h b/extensions/opc/include/fetchopc.h index 760661689..5f076bb1a 100644 --- a/extensions/opc/include/fetchopc.h +++ b/extensions/opc/include/fetchopc.h @@ -39,8 +39,8 @@ namespace org::apache::nifi::minifi::processors { class FetchOPCProcessor : public BaseOPCProcessor { public: explicit FetchOPCProcessor(std::string name, const utils::Identifier& uuid = {}) - : BaseOPCProcessor(std::move(name), uuid), nameSpaceIdx_(0), nodesFound_(0), variablesFound_(0), maxDepth_(0) { - logger_ = core::logging::LoggerFactory<FetchOPCProcessor>::getLogger(); + : BaseOPCProcessor(std::move(name), uuid) { + logger_ = core::logging::LoggerFactory<FetchOPCProcessor>::getLogger(uuid_); } EXTENSIONAPI static constexpr const char* Description = "Fetches OPC-UA node"; @@ -82,12 +82,12 @@ class FetchOPCProcessor : public BaseOPCProcessor { void OPCData2FlowFile(const opc::NodeData& opcnode, const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session); std::string nodeID_; - int32_t nameSpaceIdx_; - opc::OPCNodeIDType idType_; - uint32_t nodesFound_; - uint32_t variablesFound_; - uint64_t maxDepth_; - bool lazy_mode_; + int32_t nameSpaceIdx_ = 0; + opc::OPCNodeIDType idType_{}; + uint32_t nodesFound_ = 0; + uint32_t variablesFound_ = 0; + uint64_t maxDepth_ = 0; + bool lazy_mode_ = false; private: std::vector<UA_NodeId> translatedNodeIDs_; // Only used when user provides path, path->nodeid translation is only done once diff --git a/extensions/opc/include/putopc.h b/extensions/opc/include/putopc.h index 4f8bd6658..3aa9281db 100644 --- a/extensions/opc/include/putopc.h +++ b/extensions/opc/include/putopc.h @@ -72,8 +72,8 @@ class PutOPCProcessor : public BaseOPCProcessor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit PutOPCProcessor(std::string name, const utils::Identifier& uuid = {}) - : BaseOPCProcessor(std::move(name), uuid), nameSpaceIdx_(0), parentExists_(false) { - logger_ = core::logging::LoggerFactory<PutOPCProcessor>::getLogger(); + : BaseOPCProcessor(std::move(name), uuid) { + logger_ = core::logging::LoggerFactory<PutOPCProcessor>::getLogger(uuid_); } void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &factory) override; diff --git a/extensions/opencv/CaptureRTSPFrame.h b/extensions/opencv/CaptureRTSPFrame.h index a8beeb85e..ff16e53e5 100644 --- a/extensions/opencv/CaptureRTSPFrame.h +++ b/extensions/opencv/CaptureRTSPFrame.h @@ -81,7 +81,7 @@ class CaptureRTSPFrame : public core::Processor { void notifyStop() override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CaptureRTSPFrame>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CaptureRTSPFrame>::getLogger(uuid_); std::mutex mutex_; std::string rtsp_username_; std::string rtsp_password_; diff --git a/extensions/opencv/MotionDetector.h b/extensions/opencv/MotionDetector.h index 80b57019f..e3bd6d6fd 100644 --- a/extensions/opencv/MotionDetector.h +++ b/extensions/opencv/MotionDetector.h @@ -72,7 +72,7 @@ class MotionDetector : public core::Processor { private: bool detectAndDraw(cv::Mat &frame); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<MotionDetector>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<MotionDetector>::getLogger(uuid_); std::mutex mutex_; cv::Mat background_; cv::Mat bg_img_; diff --git a/extensions/pcap/CapturePacket.h b/extensions/pcap/CapturePacket.h index 5f692b155..fe63b0674 100644 --- a/extensions/pcap/CapturePacket.h +++ b/extensions/pcap/CapturePacket.h @@ -166,7 +166,7 @@ class CapturePacket : public core::Processor { std::unique_ptr<PacketMovers> mover; static std::atomic<int> num_; std::vector<pcpp::PcapLiveDevice*> device_list_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CapturePacket>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CapturePacket>::getLogger(uuid_); static std::shared_ptr<utils::IdGenerator> id_generator_; }; diff --git a/extensions/procfs/processors/ProcFsMonitor.h b/extensions/procfs/processors/ProcFsMonitor.h index b85b8d224..64cfce268 100644 --- a/extensions/procfs/processors/ProcFsMonitor.h +++ b/extensions/procfs/processors/ProcFsMonitor.h @@ -67,7 +67,6 @@ class ProcFsMonitor : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS - public: void onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& sessionFactory) override; void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; @@ -124,7 +123,7 @@ class ProcFsMonitor : public core::Processor { ResultRelativeness result_relativeness_ = ResultRelativeness::ABSOLUTE; std::optional<uint8_t> decimal_places_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ProcFsMonitor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ProcFsMonitor>::getLogger(uuid_); ProcFs proc_fs_; diff --git a/extensions/script/ExecuteScript.h b/extensions/script/ExecuteScript.h index 256ceee0a..1f47987fc 100644 --- a/extensions/script/ExecuteScript.h +++ b/extensions/script/ExecuteScript.h @@ -115,7 +115,7 @@ class ExecuteScript : public core::Processor { const std::shared_ptr<core::ProcessSession> &session) override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteScript>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteScript>::getLogger(uuid_); ScriptEngineOption script_engine_; std::string script_file_; diff --git a/extensions/script/python/ExecutePythonProcessor.h b/extensions/script/python/ExecutePythonProcessor.h index 52eb5aa24..c84337b65 100644 --- a/extensions/script/python/ExecutePythonProcessor.h +++ b/extensions/script/python/ExecutePythonProcessor.h @@ -115,7 +115,7 @@ class ExecutePythonProcessor : public core::Processor { bool processor_initialized_; bool python_dynamic_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecutePythonProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecutePythonProcessor>::getLogger(uuid_); std::string script_to_exec_; bool reload_on_script_change_; diff --git a/extensions/sftp/processors/FetchSFTP.cpp b/extensions/sftp/processors/FetchSFTP.cpp index 8872b8cc0..0753b7615 100644 --- a/extensions/sftp/processors/FetchSFTP.cpp +++ b/extensions/sftp/processors/FetchSFTP.cpp @@ -42,10 +42,8 @@ void FetchSFTP::initialize() { } FetchSFTP::FetchSFTP(std::string name, const utils::Identifier& uuid /*= utils::Identifier()*/) - : SFTPProcessorBase(std::move(name), uuid), - create_directory_(false), - disable_directory_listing_(false) { - logger_ = core::logging::LoggerFactory<FetchSFTP>::getLogger(); + : SFTPProcessorBase(std::move(name), uuid) { + logger_ = core::logging::LoggerFactory<FetchSFTP>::getLogger(uuid_); } FetchSFTP::~FetchSFTP() = default; diff --git a/extensions/sftp/processors/FetchSFTP.h b/extensions/sftp/processors/FetchSFTP.h index 53f37641e..e2156c4d9 100644 --- a/extensions/sftp/processors/FetchSFTP.h +++ b/extensions/sftp/processors/FetchSFTP.h @@ -93,8 +93,8 @@ class FetchSFTP : public SFTPProcessorBase { private: std::string completion_strategy_; - bool create_directory_; - bool disable_directory_listing_; + bool create_directory_ = false; + bool disable_directory_listing_ = false; }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/sftp/processors/ListSFTP.cpp b/extensions/sftp/processors/ListSFTP.cpp index 2f671b56d..5a7891cb1 100644 --- a/extensions/sftp/processors/ListSFTP.cpp +++ b/extensions/sftp/processors/ListSFTP.cpp @@ -37,7 +37,6 @@ #include "utils/file/FileUtils.h" #include "core/FlowFile.h" #include "core/ProcessContext.h" -#include "core/Relationship.h" #include "core/Resource.h" #include "io/BufferStream.h" #include "io/StreamFactory.h" @@ -75,17 +74,8 @@ void ListSFTP::initialize() { } ListSFTP::ListSFTP(std::string name, const utils::Identifier& uuid /*= utils::Identifier()*/) - : SFTPProcessorBase(std::move(name), uuid) - , search_recursively_(false) - , follow_symlink_(false) - , ignore_dotted_files_(false) - , minimum_file_age_(0U) - , maximum_file_age_(0U) - , minimum_file_size_(0U) - , maximum_file_size_(0U) - , already_loaded_from_cache_(false) - , initial_listing_complete_(false) { - logger_ = core::logging::LoggerFactory<ListSFTP>::getLogger(); + : SFTPProcessorBase(std::move(name), uuid) { + logger_ = core::logging::LoggerFactory<ListSFTP>::getLogger(uuid_); } ListSFTP::~ListSFTP() = default; @@ -174,11 +164,6 @@ void ListSFTP::invalidateCache() { already_listed_entities_.clear(); } -ListSFTP::Child::Child() - :directory(false) { - memset(&attrs, 0x00, sizeof(attrs)); -} - ListSFTP::Child::Child(const std::string& parent_path_, std::tuple<std::string /* filename */, std::string /* longentry */, LIBSSH2_SFTP_ATTRIBUTES /* attrs */>&& sftp_child) { parent_path = parent_path_; std::tie(filename, std::ignore, attrs) = std::move(sftp_child); @@ -231,7 +216,7 @@ bool ListSFTP::filterFile(const std::string& parent_path, const std::string& fil } /* Age */ - auto file_age = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(attrs.mtime)); + auto file_age = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(gsl::narrow<time_t>(attrs.mtime))); if (file_age < minimum_file_age_) { logger_->log_debug("Ignoring \"%s/%s\" because it is younger than the Minimum File Age: %ld ms < %lu ms", parent_path.c_str(), diff --git a/extensions/sftp/processors/ListSFTP.h b/extensions/sftp/processors/ListSFTP.h index 0867aff3a..85e8cea39 100644 --- a/extensions/sftp/processors/ListSFTP.h +++ b/extensions/sftp/processors/ListSFTP.h @@ -119,21 +119,21 @@ class ListSFTP : public SFTPProcessorBase { void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override; private: - core::CoreComponentStateManager* state_manager_; + core::CoreComponentStateManager* state_manager_{}; std::string listing_strategy_; - bool search_recursively_; - bool follow_symlink_; + bool search_recursively_{}; + bool follow_symlink_{}; std::string file_filter_regex_; std::string path_filter_regex_; std::optional<utils::Regex> compiled_file_filter_regex_; std::optional<utils::Regex> compiled_path_filter_regex_; - bool ignore_dotted_files_; + bool ignore_dotted_files_{}; std::string target_system_timestamp_precision_; std::string entity_tracking_initial_listing_target_; - std::chrono::milliseconds minimum_file_age_; - std::chrono::milliseconds maximum_file_age_; - uint64_t minimum_file_size_; - uint64_t maximum_file_size_; + std::chrono::milliseconds minimum_file_age_{}; + std::chrono::milliseconds maximum_file_age_{}; + uint64_t minimum_file_size_{}; + uint64_t maximum_file_size_{}; std::string last_listing_strategy_; std::string last_hostname_; @@ -141,24 +141,24 @@ class ListSFTP : public SFTPProcessorBase { std::filesystem::path last_remote_path_; struct Child { - Child(); + Child() = default; Child(const std::string& parent_path_, std::tuple<std::string /* filename */, std::string /* longentry */, LIBSSH2_SFTP_ATTRIBUTES /* attrs */>&& sftp_child); [[nodiscard]] std::string getPath() const; - bool directory; + bool directory{false}; std::filesystem::path parent_path; std::filesystem::path filename; - LIBSSH2_SFTP_ATTRIBUTES attrs; + LIBSSH2_SFTP_ATTRIBUTES attrs{}; }; - bool already_loaded_from_cache_; + bool already_loaded_from_cache_{}; - std::chrono::steady_clock::time_point last_run_time_; + std::chrono::steady_clock::time_point last_run_time_{}; std::optional<std::chrono::system_clock::time_point> last_listed_latest_entry_timestamp_; std::optional<std::chrono::system_clock::time_point> last_processed_latest_entry_timestamp_; std::set<std::string> latest_identifiers_processed_; - bool initial_listing_complete_; + bool initial_listing_complete_{}; struct ListedEntity { uint64_t timestamp; uint64_t size; diff --git a/extensions/sftp/processors/PutSFTP.cpp b/extensions/sftp/processors/PutSFTP.cpp index 7b7c99595..581846528 100644 --- a/extensions/sftp/processors/PutSFTP.cpp +++ b/extensions/sftp/processors/PutSFTP.cpp @@ -18,27 +18,18 @@ #include "PutSFTP.h" #include <memory> -#include <algorithm> -#include <cctype> #include <cstdint> -#include <cstring> #include <iostream> -#include <iterator> #include <limits> -#include <map> #include <string> #include <utility> -#include <vector> -#include "utils/ByteArrayCallback.h" #include "core/FlowFile.h" #include "core/logging/Logger.h" #include "core/ProcessContext.h" -#include "core/Relationship.h" #include "core/Resource.h" #include "io/BufferStream.h" #include "io/StreamFactory.h" -#include "ResourceClaim.h" #include "utils/StringUtils.h" #include "utils/file/FileUtils.h" @@ -57,7 +48,7 @@ PutSFTP::PutSFTP(std::string name, const utils::Identifier& uuid /*= utils::Iden batch_size_(0), reject_zero_byte_(false), dot_rename_(false) { - logger_ = core::logging::LoggerFactory<PutSFTP>::getLogger(); + logger_ = core::logging::LoggerFactory<PutSFTP>::getLogger(uuid_); } PutSFTP::~PutSFTP() = default; @@ -291,7 +282,7 @@ bool PutSFTP::processOne(const std::shared_ptr<core::ProcessContext> &context, c if (!client->putFile(target_path.generic_string(), *stream, conflict_resolution_ == CONFLICT_RESOLUTION_REPLACE /*overwrite*/, - stream->size() /*expected_size*/)) { + gsl::narrow<int64_t>(stream->size()) /*expected_size*/)) { throw utils::SFTPException{client->getLastError()}; } return gsl::narrow<int64_t>(stream->size()); @@ -319,7 +310,7 @@ bool PutSFTP::processOne(const std::shared_ptr<core::ProcessContext> &context, c permissions_set || remote_owner_set || remote_group_set) { - utils::SFTPClient::SFTPAttributes attrs; + utils::SFTPClient::SFTPAttributes attrs{}; attrs.flags = 0U; if (last_modified_) { /* diff --git a/extensions/splunk/PutSplunkHTTP.h b/extensions/splunk/PutSplunkHTTP.h index 1570c34a2..052619345 100644 --- a/extensions/splunk/PutSplunkHTTP.h +++ b/extensions/splunk/PutSplunkHTTP.h @@ -73,7 +73,7 @@ class PutSplunkHTTP final : public SplunkHECProcessor { void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override; private: - std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<PutSplunkHTTP>::getLogger()}; + std::shared_ptr<core::logging::Logger> logger_{core::logging::LoggerFactory<PutSplunkHTTP>::getLogger(uuid_)}; std::shared_ptr<utils::ResourceQueue<extensions::curl::HTTPClient>> client_queue_; }; diff --git a/extensions/sql/processors/ExecuteSQL.cpp b/extensions/sql/processors/ExecuteSQL.cpp index f92d04f42..e4946c353 100644 --- a/extensions/sql/processors/ExecuteSQL.cpp +++ b/extensions/sql/processors/ExecuteSQL.cpp @@ -18,18 +18,12 @@ #include "ExecuteSQL.h" #include <string> -#include <memory> +#include <utility> -#include <soci/soci.h> - -#include "io/BufferStream.h" #include "io/StreamPipe.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/Resource.h" #include "Exception.h" -#include "data/JSONSQLWriter.h" -#include "data/SQLRowsetProcessor.h" namespace org::apache::nifi::minifi::processors { @@ -37,7 +31,7 @@ const std::string ExecuteSQL::RESULT_ROW_COUNT = "executesql.row.count"; const std::string ExecuteSQL::INPUT_FLOW_FILE_UUID = "input.flowfile.uuid"; ExecuteSQL::ExecuteSQL(std::string name, const utils::Identifier& uuid) - : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<ExecuteSQL>::getLogger()) { + : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<ExecuteSQL>::getLogger(uuid)) { } void ExecuteSQL::initialize() { diff --git a/extensions/sql/processors/PutSQL.cpp b/extensions/sql/processors/PutSQL.cpp index f579308b3..8c2914b6d 100644 --- a/extensions/sql/processors/PutSQL.cpp +++ b/extensions/sql/processors/PutSQL.cpp @@ -18,17 +18,17 @@ #include "PutSQL.h" #include <string> +#include <utility> #include "io/BufferStream.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/Resource.h" #include "Exception.h" namespace org::apache::nifi::minifi::processors { PutSQL::PutSQL(std::string name, const utils::Identifier& uuid) - : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<PutSQL>::getLogger()) { + : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<PutSQL>::getLogger(uuid)) { } void PutSQL::initialize() { diff --git a/extensions/sql/processors/QueryDatabaseTable.cpp b/extensions/sql/processors/QueryDatabaseTable.cpp index 6c1ef55d9..ecbf5b2d5 100644 --- a/extensions/sql/processors/QueryDatabaseTable.cpp +++ b/extensions/sql/processors/QueryDatabaseTable.cpp @@ -19,18 +19,12 @@ #include <vector> #include <string> -#include <memory> #include <algorithm> -#include <soci/soci.h> - #include "io/BufferStream.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/Resource.h" #include "Exception.h" -#include "data/JSONSQLWriter.h" -#include "data/SQLRowsetProcessor.h" #include "data/MaxCollector.h" #include "utils/StringUtils.h" @@ -45,7 +39,7 @@ const std::string QueryDatabaseTable::TABLENAME_KEY = "tablename"; const std::string QueryDatabaseTable::MAXVALUE_KEY_PREFIX = "maxvalue."; QueryDatabaseTable::QueryDatabaseTable(std::string name, const utils::Identifier& uuid) - : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<QueryDatabaseTable>::getLogger()) { + : SQLProcessor(std::move(name), uuid, core::logging::LoggerFactory<QueryDatabaseTable>::getLogger(uuid)) { } void QueryDatabaseTable::initialize() { diff --git a/extensions/sql/processors/QueryDatabaseTable.h b/extensions/sql/processors/QueryDatabaseTable.h index 82faf054b..f510e0953 100644 --- a/extensions/sql/processors/QueryDatabaseTable.h +++ b/extensions/sql/processors/QueryDatabaseTable.h @@ -23,6 +23,7 @@ #include <string> #include <vector> #include <unordered_map> +#include <unordered_set> #include <memory> #include "core/ProcessSession.h" @@ -82,7 +83,7 @@ class QueryDatabaseTable: public SQLProcessor, public FlowFileSource { bool saveState(); - core::CoreComponentStateManager* state_manager_; + core::CoreComponentStateManager* state_manager_{}; std::string table_name_; std::unordered_set<sql::SQLColumnIdentifier> return_columns_; std::string queried_columns_; diff --git a/extensions/sql/services/DatabaseService.h b/extensions/sql/services/DatabaseService.h index f21e9f410..f82acb092 100644 --- a/extensions/sql/services/DatabaseService.h +++ b/extensions/sql/services/DatabaseService.h @@ -17,7 +17,9 @@ #pragma once #include <memory> +#include <string> #include <unordered_map> +#include <utility> #include "core/logging/LoggerConfiguration.h" #include "core/controller/ControllerService.h" @@ -69,7 +71,6 @@ class DatabaseService : public core::controller::ControllerService { virtual std::unique_ptr<sql::Connection> getConnection() const = 0; protected: - void initializeProperties(); // initialization mutex. @@ -80,8 +81,7 @@ class DatabaseService : public core::controller::ControllerService { std::string connection_string_; private: - - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DatabaseService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DatabaseService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::sql::controllers diff --git a/extensions/sql/services/ODBCConnector.h b/extensions/sql/services/ODBCConnector.h index 48b008cf0..9bc45bd83 100644 --- a/extensions/sql/services/ODBCConnector.h +++ b/extensions/sql/services/ODBCConnector.h @@ -17,6 +17,10 @@ #pragma once +#include <memory> +#include <string> +#include <utility> + #include "core/logging/LoggerConfiguration.h" #include "core/controller/ControllerService.h" @@ -51,7 +55,7 @@ class ODBCService : public DatabaseService { std::unique_ptr<sql::Connection> getConnection() const override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ODBCService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ODBCService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::sql::controllers diff --git a/extensions/standard-processors/processors/AppendHostInfo.h b/extensions/standard-processors/processors/AppendHostInfo.h index 13ec9ca4c..1eb5d58ed 100644 --- a/extensions/standard-processors/processors/AppendHostInfo.h +++ b/extensions/standard-processors/processors/AppendHostInfo.h @@ -17,8 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_APPENDHOSTINFO_H_ -#define EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_APPENDHOSTINFO_H_ +#pragma once #include <memory> #include <optional> @@ -43,8 +42,7 @@ class AppendHostInfo : public core::Processor { static constexpr const char* REFRESH_POLICY_ON_SCHEDULE = "On schedule"; explicit AppendHostInfo(std::string name, const utils::Identifier& uuid = {}) - : core::Processor(std::move(name), uuid), - refresh_on_trigger_(false) { + : core::Processor(std::move(name), uuid) { } ~AppendHostInfo() override = default; @@ -82,16 +80,14 @@ class AppendHostInfo : public core::Processor { private: std::shared_mutex shared_mutex_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AppendHostInfo>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AppendHostInfo>::getLogger(uuid_); std::string hostname_attribute_name_; std::string ipaddress_attribute_name_; std::optional<std::regex> interface_name_filter_; - bool refresh_on_trigger_; + bool refresh_on_trigger_ = false; std::string hostname_; std::optional<std::string> ipaddresses_; }; } // namespace org::apache::nifi::minifi::processors - -#endif // EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_APPENDHOSTINFO_H_ diff --git a/extensions/standard-processors/processors/AttributesToJSON.h b/extensions/standard-processors/processors/AttributesToJSON.h index 0d90174cf..f7d745e50 100644 --- a/extensions/standard-processors/processors/AttributesToJSON.h +++ b/extensions/standard-processors/processors/AttributesToJSON.h @@ -88,7 +88,7 @@ class AttributesToJSON : public core::Processor { void addAttributeToJson(rapidjson::Document& document, const std::string& key, const std::optional<std::string>& value) const; std::string buildAttributeJsonData(const core::FlowFile::AttributeMap& flowfile_attributes); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AttributesToJSON>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AttributesToJSON>::getLogger(uuid_); std::vector<std::string> attribute_list_; std::optional<utils::Regex> attributes_regular_expression_; WriteDestination write_destination_; diff --git a/extensions/standard-processors/processors/DefragmentText.h b/extensions/standard-processors/processors/DefragmentText.h index ac97b0dd4..72c39cf3d 100644 --- a/extensions/standard-processors/processors/DefragmentText.h +++ b/extensions/standard-processors/processors/DefragmentText.h @@ -123,7 +123,7 @@ class DefragmentText : public core::Processor { std::optional<std::chrono::milliseconds> max_age_; std::optional<size_t> max_size_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DefragmentText>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DefragmentText>::getLogger(uuid_); core::FlowFileStore flow_file_store_; std::unordered_map<FragmentSource::Id, FragmentSource, FragmentSource::Id::hash> fragment_sources_; diff --git a/extensions/standard-processors/processors/ExecuteProcess.h b/extensions/standard-processors/processors/ExecuteProcess.h index 9cbea5b43..38c0b06d6 100644 --- a/extensions/standard-processors/processors/ExecuteProcess.h +++ b/extensions/standard-processors/processors/ExecuteProcess.h @@ -47,9 +47,7 @@ class ExecuteProcess : public core::Processor { public: explicit ExecuteProcess(std::string name, const utils::Identifier& uuid = {}) : Processor(std::move(name), uuid), - working_dir_("."), - redirect_error_stream_(false), - pid_(0) { + working_dir_(".") { } ~ExecuteProcess() override { if (pid_ > 0) { @@ -99,15 +97,15 @@ class ExecuteProcess : public core::Processor { void readOutput(core::ProcessSession& session); bool writeToFlowFile(core::ProcessSession& session, std::shared_ptr<core::FlowFile>& flow_file, gsl::span<const char> buffer) const; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteProcess>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExecuteProcess>::getLogger(uuid_); std::string command_; std::string command_argument_; std::filesystem::path working_dir_; std::chrono::milliseconds batch_duration_ = std::chrono::milliseconds(0); - bool redirect_error_stream_; + bool redirect_error_stream_ = false; std::string full_command_; int pipefd_[2]{}; - pid_t pid_; + pid_t pid_{}; }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/ExtractText.h b/extensions/standard-processors/processors/ExtractText.h index e51136209..80801a09c 100644 --- a/extensions/standard-processors/processors/ExtractText.h +++ b/extensions/standard-processors/processors/ExtractText.h @@ -85,7 +85,7 @@ class ExtractText : public core::Processor { }; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExtractText>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ExtractText>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/FetchFile.h b/extensions/standard-processors/processors/FetchFile.h index 747bf0aeb..90e0c411d 100644 --- a/extensions/standard-processors/processors/FetchFile.h +++ b/extensions/standard-processors/processors/FetchFile.h @@ -117,7 +117,7 @@ class FetchFile : public core::Processor { MoveConflictStrategyOption move_confict_strategy_; LogLevelOption log_level_when_file_not_found_; LogLevelOption log_level_when_permission_denied_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<FetchFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<FetchFile>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/GenerateFlowFile.h b/extensions/standard-processors/processors/GenerateFlowFile.h index e033ee816..050fc74a6 100644 --- a/extensions/standard-processors/processors/GenerateFlowFile.h +++ b/extensions/standard-processors/processors/GenerateFlowFile.h @@ -74,7 +74,6 @@ class GenerateFlowFile : public core::Processor { EXTENSIONAPI static const char *DATA_FORMAT_TEXT; - public: void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) override; void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; void initialize() override; @@ -88,7 +87,7 @@ class GenerateFlowFile : public core::Processor { bool textData_; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GenerateFlowFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GenerateFlowFile>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/GetFile.h b/extensions/standard-processors/processors/GetFile.h index 1a287d38a..5a46b5909 100644 --- a/extensions/standard-processors/processors/GetFile.h +++ b/extensions/standard-processors/processors/GetFile.h @@ -145,7 +145,7 @@ class GetFile : public core::Processor { std::queue<std::filesystem::path> directory_listing_; mutable std::mutex directory_listing_mutex_; std::atomic<std::chrono::time_point<std::chrono::system_clock>> last_listing_time_{}; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetFile>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/GetTCP.h b/extensions/standard-processors/processors/GetTCP.h index 0685f20cf..e8070afd2 100644 --- a/extensions/standard-processors/processors/GetTCP.h +++ b/extensions/standard-processors/processors/GetTCP.h @@ -66,10 +66,7 @@ class SocketAfterExecute : public utils::AfterExecute<int> { } } bool isCancelled(const int& /*result*/) override { - if (!running_) - return true; - else - return false; + return !running_; } std::chrono::milliseconds wait_time() override { @@ -100,13 +97,7 @@ class DataHandler { class GetTCP : public core::Processor { public: explicit GetTCP(std::string name, const utils::Identifier& uuid = {}) - : Processor(std::move(name), uuid), - running_(false), - stay_connected_(true), - concurrent_handlers_(2), - endOfMessageByte(static_cast<std::byte>(13)), - receive_buffer_size_(16 * 1024 * 1024), - connection_attempt_limit_(3) { + : Processor(std::move(name), uuid) { } ~GetTCP() override { @@ -163,21 +154,21 @@ class GetTCP : public core::Processor { private: std::function<int()> f_ex; - std::atomic<bool> running_; + std::atomic<bool> running_{false}; std::unique_ptr<DataHandler> handler_; std::vector<std::string> endpoints; std::map<std::string, std::future<int>*> live_clients_; moodycamel::ConcurrentQueue<std::unique_ptr<io::Socket>> socket_ring_buffer_; - bool stay_connected_; - uint16_t concurrent_handlers_; - std::byte endOfMessageByte; + bool stay_connected_{true}; + uint16_t concurrent_handlers_{2}; + std::byte endOfMessageByte{13}; std::chrono::milliseconds reconnect_interval_{5000}; - uint64_t receive_buffer_size_; - uint16_t connection_attempt_limit_; + uint64_t receive_buffer_size_{16 * 1024 * 1024}; + uint16_t connection_attempt_limit_{3}; // Mutex for ensuring clients are running std::mutex mutex_; std::shared_ptr<minifi::controllers::SSLContextService> ssl_service_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetTCP>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetTCP>::getLogger(uuid_); utils::ThreadPool<int> client_thread_pool_; }; diff --git a/extensions/standard-processors/processors/HashContent.h b/extensions/standard-processors/processors/HashContent.h index 7dbdd56c5..33224d505 100644 --- a/extensions/standard-processors/processors/HashContent.h +++ b/extensions/standard-processors/processors/HashContent.h @@ -57,7 +57,7 @@ namespace { // NOLINT ret = stream->read(buffer); if (ret > 0) { MD5_Update(&context, buffer.data(), ret); - ret_val.second += ret; + ret_val.second += gsl::narrow<int64_t>(ret); } } while (ret > 0); @@ -81,7 +81,7 @@ namespace { // NOLINT ret = stream->read(buffer); if (ret > 0) { SHA1_Update(&context, buffer.data(), ret); - ret_val.second += ret; + ret_val.second += gsl::narrow<int64_t>(ret); } } while (ret > 0); @@ -105,7 +105,7 @@ namespace { // NOLINT ret = stream->read(buffer); if (ret > 0) { SHA256_Update(&context, buffer.data(), ret); - ret_val.second += ret; + ret_val.second += gsl::narrow<int64_t>(ret); } } while (ret > 0); @@ -160,7 +160,7 @@ class HashContent : public core::Processor { void initialize() override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<HashContent>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<HashContent>::getLogger(uuid_); std::function<HashReturnType(const std::shared_ptr<io::InputStream>&)> algorithm_ = SHA256Hash; std::string attrKey_; bool failOnEmpty_{}; diff --git a/extensions/standard-processors/processors/ListFile.h b/extensions/standard-processors/processors/ListFile.h index 8199d5654..5ca29fa78 100644 --- a/extensions/standard-processors/processors/ListFile.h +++ b/extensions/standard-processors/processors/ListFile.h @@ -99,7 +99,7 @@ class ListFile : public core::Processor { bool fileMatchesFilters(const ListedFile& listed_file); std::shared_ptr<core::FlowFile> createFlowFile(core::ProcessSession& session, const ListedFile& listed_file); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ListFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ListFile>::getLogger(uuid_); std::filesystem::path input_directory_; std::unique_ptr<minifi::utils::ListingStateManager> state_manager_; bool recurse_subdirectories_ = true; diff --git a/extensions/standard-processors/processors/ListenSyslog.h b/extensions/standard-processors/processors/ListenSyslog.h index 9844c0c1b..d26031332 100644 --- a/extensions/standard-processors/processors/ListenSyslog.h +++ b/extensions/standard-processors/processors/ListenSyslog.h @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::processors { class ListenSyslog : public NetworkListenerProcessor { public: explicit ListenSyslog(std::string name, const utils::Identifier& uuid = {}) - : NetworkListenerProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListenSyslog>::getLogger()) { + : NetworkListenerProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListenSyslog>::getLogger(uuid)) { } EXTENSIONAPI static constexpr const char* Description = "Listens for Syslog messages being sent to a given port over TCP or UDP. " diff --git a/extensions/standard-processors/processors/ListenTCP.h b/extensions/standard-processors/processors/ListenTCP.h index 567865346..5cdcfdf22 100644 --- a/extensions/standard-processors/processors/ListenTCP.h +++ b/extensions/standard-processors/processors/ListenTCP.h @@ -29,7 +29,7 @@ namespace org::apache::nifi::minifi::processors { class ListenTCP : public NetworkListenerProcessor { public: explicit ListenTCP(std::string name, const utils::Identifier& uuid = {}) - : NetworkListenerProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListenTCP>::getLogger()) { + : NetworkListenerProcessor(std::move(name), uuid, core::logging::LoggerFactory<ListenTCP>::getLogger(uuid)) { } EXTENSIONAPI static constexpr const char* Description = "Listens for incoming TCP connections and reads data from each connection using a line separator as the message demarcator. " diff --git a/extensions/standard-processors/processors/ListenUDP.h b/extensions/standard-processors/processors/ListenUDP.h index 1eb4cfd96..647386ac8 100644 --- a/extensions/standard-processors/processors/ListenUDP.h +++ b/extensions/standard-processors/processors/ListenUDP.h @@ -27,7 +27,7 @@ namespace org::apache::nifi::minifi::processors { class ListenUDP : public NetworkListenerProcessor { public: explicit ListenUDP(const std::string& name, const utils::Identifier& uuid = {}) - : NetworkListenerProcessor(name, uuid, core::logging::LoggerFactory<ListenUDP>::getLogger()) { + : NetworkListenerProcessor(name, uuid, core::logging::LoggerFactory<ListenUDP>::getLogger(uuid)) { } EXTENSIONAPI static constexpr const char* Description = "Listens for incoming UDP datagrams. For each datagram the processor produces a single FlowFile."; diff --git a/extensions/standard-processors/processors/LogAttribute.h b/extensions/standard-processors/processors/LogAttribute.h index e539a8979..c344122d0 100644 --- a/extensions/standard-processors/processors/LogAttribute.h +++ b/extensions/standard-processors/processors/LogAttribute.h @@ -37,10 +37,7 @@ namespace org::apache::nifi::minifi::processors { class LogAttribute : public core::Processor { public: explicit LogAttribute(std::string name, const utils::Identifier& uuid = {}) - : Processor(std::move(name), uuid), - flowfiles_to_log_(1), - hexencode_(false), - max_line_length_(80U) { + : Processor(std::move(name), uuid) { } ~LogAttribute() override = default; @@ -84,8 +81,8 @@ class LogAttribute : public core::Processor { LogAttrLevelWarn, LogAttrLevelError }; - // Convert log level from string to enum - bool logLevelStringToEnum(const std::string &logStr, LogAttrLevel &level) { + + static bool logLevelStringToEnum(const std::string &logStr, LogAttrLevel &level) { if (logStr == "trace") { level = LogAttrLevelTrace; return true; @@ -106,17 +103,15 @@ class LogAttribute : public core::Processor { } } - public: void onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &factory) override; void onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) override; void initialize() override; private: - uint64_t flowfiles_to_log_; - bool hexencode_; - uint32_t max_line_length_; - // Logger - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LogAttribute>::getLogger(); + uint64_t flowfiles_to_log_{1}; + bool hexencode_{false}; + uint32_t max_line_length_{80}; + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LogAttribute>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/PutFile.h b/extensions/standard-processors/processors/PutFile.h index f19e74699..334f889ba 100644 --- a/extensions/standard-processors/processors/PutFile.h +++ b/extensions/standard-processors/processors/PutFile.h @@ -115,15 +115,15 @@ class PutFile : public core::Processor { const std::filesystem::path& tmpFile, const std::filesystem::path& destFile, const std::filesystem::path& destDir); - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PutFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PutFile>::getLogger(uuid_); static std::shared_ptr<utils::IdGenerator> id_generator_; #ifndef WIN32 class FilePermissions { static const uint32_t MINIMUM_INVALID_PERMISSIONS_VALUE = 1 << 9; public: - bool valid() { return permissions_ < MINIMUM_INVALID_PERMISSIONS_VALUE; } - uint32_t getValue() const { return permissions_; } + [[nodiscard]] bool valid() const { return permissions_ < MINIMUM_INVALID_PERMISSIONS_VALUE; } + [[nodiscard]] uint32_t getValue() const { return permissions_; } void setValue(uint32_t perms) { permissions_ = perms; } private: uint32_t permissions_ = MINIMUM_INVALID_PERMISSIONS_VALUE; diff --git a/extensions/standard-processors/processors/PutTCP.h b/extensions/standard-processors/processors/PutTCP.h index 4b8999e0f..1f6f7fb58 100644 --- a/extensions/standard-processors/processors/PutTCP.h +++ b/extensions/standard-processors/processors/PutTCP.h @@ -123,7 +123,7 @@ class PutTCP final : public core::Processor { std::optional<size_t> max_size_of_socket_send_buffer_; std::chrono::milliseconds timeout_ = std::chrono::seconds(15); std::shared_ptr<controllers::SSLContextService> ssl_context_service_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PutTCP>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PutTCP>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/PutUDP.cpp b/extensions/standard-processors/processors/PutUDP.cpp index 037336769..c59a86e80 100644 --- a/extensions/standard-processors/processors/PutUDP.cpp +++ b/extensions/standard-processors/processors/PutUDP.cpp @@ -49,7 +49,7 @@ const core::Relationship PutUDP::Success{"success", "FlowFiles that are sent to const core::Relationship PutUDP::Failure{"failure", "FlowFiles that encountered IO errors are send out this relationship."}; PutUDP::PutUDP(std::string name, const utils::Identifier& uuid) - : Processor(std::move(name), uuid), logger_{core::logging::LoggerFactory<PutUDP>::getLogger()} + : Processor(std::move(name), uuid), logger_{core::logging::LoggerFactory<PutUDP>::getLogger(uuid)} { } PutUDP::~PutUDP() = default; diff --git a/extensions/standard-processors/processors/ReplaceText.cpp b/extensions/standard-processors/processors/ReplaceText.cpp index ac16e230b..174a47f51 100644 --- a/extensions/standard-processors/processors/ReplaceText.cpp +++ b/extensions/standard-processors/processors/ReplaceText.cpp @@ -77,7 +77,7 @@ const core::Relationship ReplaceText::Failure("failure", "FlowFiles that could n ReplaceText::ReplaceText(std::string name, const utils::Identifier& uuid) : core::Processor(std::move(name), uuid), - logger_(core::logging::LoggerFactory<ReplaceText>::getLogger()) { + logger_(core::logging::LoggerFactory<ReplaceText>::getLogger(uuid)) { } void ReplaceText::initialize() { diff --git a/extensions/standard-processors/processors/RetryFlowFile.h b/extensions/standard-processors/processors/RetryFlowFile.h index c1b24be8d..66fa50e10 100644 --- a/extensions/standard-processors/processors/RetryFlowFile.h +++ b/extensions/standard-processors/processors/RetryFlowFile.h @@ -103,7 +103,7 @@ class RetryFlowFile : public core::Processor { std::string reuse_mode_; std::vector<core::Property> exceeded_flowfile_attribute_keys_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<RetryFlowFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<RetryFlowFile>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/RouteOnAttribute.h b/extensions/standard-processors/processors/RouteOnAttribute.h index 28a4c222b..047872301 100644 --- a/extensions/standard-processors/processors/RouteOnAttribute.h +++ b/extensions/standard-processors/processors/RouteOnAttribute.h @@ -17,8 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_ROUTEONATTRIBUTE_H_ -#define EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_ROUTEONATTRIBUTE_H_ +#pragma once #include <map> #include <memory> @@ -59,11 +58,9 @@ class RouteOnAttribute : public core::Processor { void initialize() override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<RouteOnAttribute>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<RouteOnAttribute>::getLogger(uuid_); std::map<std::string, core::Property> route_properties_; std::map<std::string, core::Relationship> route_rels_; }; } // namespace org::apache::nifi::minifi::processors - -#endif // EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_ROUTEONATTRIBUTE_H_ diff --git a/extensions/standard-processors/processors/RouteText.cpp b/extensions/standard-processors/processors/RouteText.cpp index ecb045b90..a68fd42b7 100644 --- a/extensions/standard-processors/processors/RouteText.cpp +++ b/extensions/standard-processors/processors/RouteText.cpp @@ -105,7 +105,7 @@ const core::Relationship RouteText::Unmatched("unmatched", "Segments that do not const core::Relationship RouteText::Matched("matched", "Segments that satisfy the required user-defined rules will be routed to this Relationship"); RouteText::RouteText(std::string name, const utils::Identifier& uuid) - : core::Processor(std::move(name), uuid), logger_(core::logging::LoggerFactory<RouteText>::getLogger()) {} + : core::Processor(std::move(name), uuid), logger_(core::logging::LoggerFactory<RouteText>::getLogger(uuid)) {} void RouteText::initialize() { setSupportedProperties(properties()); @@ -144,7 +144,7 @@ class RouteText::ReadCallback { switch (segmentation_.value()) { case Segmentation::FULL_TEXT: { fn_({content, 0}); - return content.length(); + return gsl::narrow<int64_t>(content.length()); } case Segmentation::PER_LINE: { // 1-based index as in nifi @@ -164,7 +164,7 @@ class RouteText::ReadCallback { curr = next_line; ++segment_idx; } - return content.length(); + return gsl::narrow<int64_t>(content.length()); } } throw Exception(PROCESSOR_EXCEPTION, "Unknown segmentation strategy"); diff --git a/extensions/standard-processors/processors/TailFile.h b/extensions/standard-processors/processors/TailFile.h index 4cbab4759..49297c979 100644 --- a/extensions/standard-processors/processors/TailFile.h +++ b/extensions/standard-processors/processors/TailFile.h @@ -215,7 +215,7 @@ class TailFile : public core::Processor { controllers::AttributeProviderService* attribute_provider_service_ = nullptr; std::unordered_map<std::string, controllers::AttributeProviderService::AttributeMap> extra_attributes_; std::optional<uint32_t> batch_size_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<TailFile>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<TailFile>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/standard-processors/processors/UpdateAttribute.h b/extensions/standard-processors/processors/UpdateAttribute.h index a408e2352..804453868 100644 --- a/extensions/standard-processors/processors/UpdateAttribute.h +++ b/extensions/standard-processors/processors/UpdateAttribute.h @@ -17,8 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_UPDATEATTRIBUTE_H_ -#define EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_UPDATEATTRIBUTE_H_ +#pragma once #include <memory> #include <string> @@ -60,10 +59,8 @@ class UpdateAttribute : public core::Processor { void initialize() override; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<UpdateAttribute>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<UpdateAttribute>::getLogger(uuid_); std::vector<core::Property> attributes_; }; } // namespace org::apache::nifi::minifi::processors - -#endif // EXTENSIONS_STANDARD_PROCESSORS_PROCESSORS_UPDATEATTRIBUTE_H_ diff --git a/extensions/systemd/ConsumeJournald.h b/extensions/systemd/ConsumeJournald.h index f6add017c..25a70150c 100644 --- a/extensions/systemd/ConsumeJournald.h +++ b/extensions/systemd/ConsumeJournald.h @@ -111,7 +111,7 @@ class ConsumeJournald final : public core::Processor { std::string getCursor() const; std::atomic<bool> running_{false}; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ConsumeJournald>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ConsumeJournald>::getLogger(uuid_); core::CoreComponentStateManager* state_manager_; std::unique_ptr<libwrapper::LibWrapper> libwrapper_; std::unique_ptr<utils::FifoExecutor> worker_; diff --git a/extensions/tensorflow/TFApplyGraph.h b/extensions/tensorflow/TFApplyGraph.h index edfd5516f..2973ab08b 100644 --- a/extensions/tensorflow/TFApplyGraph.h +++ b/extensions/tensorflow/TFApplyGraph.h @@ -32,7 +32,7 @@ class TFApplyGraph : public core::Processor { public: explicit TFApplyGraph(const std::string &name, const utils::Identifier &uuid = {}) : Processor(name, uuid), - logger_(logging::LoggerFactory<TFApplyGraph>::getLogger()) { + logger_(logging::LoggerFactory<TFApplyGraph>::getLogger(uuid_)) { } EXTENSIONAPI static constexpr const char* Description = "Applies a TensorFlow graph to the tensor protobuf supplied as input. The tensor is fed into the node specified by the Input Node property. " diff --git a/extensions/tensorflow/TFConvertImageToTensor.h b/extensions/tensorflow/TFConvertImageToTensor.h index 6c71bf180..38472f79b 100644 --- a/extensions/tensorflow/TFConvertImageToTensor.h +++ b/extensions/tensorflow/TFConvertImageToTensor.h @@ -32,7 +32,7 @@ class TFConvertImageToTensor : public core::Processor { public: explicit TFConvertImageToTensor(const std::string &name, const utils::Identifier &uuid = {}) : Processor(name, uuid), - logger_(logging::LoggerFactory<TFConvertImageToTensor>::getLogger()) { + logger_(logging::LoggerFactory<TFConvertImageToTensor>::getLogger(uuid_)) { } EXTENSIONAPI static constexpr const char* Description = "Converts the input image file into a tensor protobuf. The image will be resized to the given output tensor dimensions."; diff --git a/extensions/tensorflow/TFExtractTopLabels.h b/extensions/tensorflow/TFExtractTopLabels.h index bd707752d..9df642da3 100644 --- a/extensions/tensorflow/TFExtractTopLabels.h +++ b/extensions/tensorflow/TFExtractTopLabels.h @@ -32,7 +32,7 @@ class TFExtractTopLabels : public core::Processor { public: explicit TFExtractTopLabels(const std::string &name, const utils::Identifier &uuid = {}) : Processor(name, uuid), - logger_(logging::LoggerFactory<TFExtractTopLabels>::getLogger()) { + logger_(logging::LoggerFactory<TFExtractTopLabels>::getLogger(uuid_)) { } EXTENSIONAPI static constexpr const char* Description = "Extracts the top 5 labels for categorical inference models"; diff --git a/extensions/test-processors/KamikazeProcessor.h b/extensions/test-processors/KamikazeProcessor.h index aea568f8a..f50cffb5b 100644 --- a/extensions/test-processors/KamikazeProcessor.h +++ b/extensions/test-processors/KamikazeProcessor.h @@ -66,7 +66,7 @@ class KamikazeProcessor : public core::Processor { private: bool _throwInOnTrigger = false; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<KamikazeProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<KamikazeProcessor>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/test-processors/LogOnDestructionProcessor.h b/extensions/test-processors/LogOnDestructionProcessor.h index aa8670a4e..9c5bf0795 100644 --- a/extensions/test-processors/LogOnDestructionProcessor.h +++ b/extensions/test-processors/LogOnDestructionProcessor.h @@ -47,7 +47,7 @@ class LogOnDestructionProcessor : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LogOnDestructionProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LogOnDestructionProcessor>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::processors diff --git a/extensions/usb-camera/GetUSBCamera.h b/extensions/usb-camera/GetUSBCamera.h index 410f5cd96..23298b3b0 100644 --- a/extensions/usb-camera/GetUSBCamera.h +++ b/extensions/usb-camera/GetUSBCamera.h @@ -94,7 +94,7 @@ class GetUSBCamera : public core::Processor { core::ProcessSession *session) override; void initialize() override; - typedef struct { + struct CallbackData { core::ProcessContext *context; core::ProcessSessionFactory *session_factory; std::shared_ptr<core::logging::Logger> logger; @@ -107,7 +107,7 @@ class GetUSBCamera : public core::Processor { uint32_t device_fps; double target_fps; std::chrono::steady_clock::time_point last_frame_time; - } CallbackData; + }; static void onFrame(uvc_frame_t *frame, void *ptr); @@ -127,11 +127,11 @@ class GetUSBCamera : public core::Processor { }; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetUSBCamera>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GetUSBCamera>::getLogger(uuid_); static std::shared_ptr<utils::IdGenerator> id_generator_; std::shared_ptr<std::thread> camera_thread_; - CallbackData cb_data_; + CallbackData cb_data_{}; std::shared_ptr<std::mutex> png_write_mtx_; std::shared_ptr<std::recursive_mutex> dev_access_mtx_; diff --git a/extensions/windows-event-log/CollectorInitiatedSubscription.cpp b/extensions/windows-event-log/CollectorInitiatedSubscription.cpp index 8e66878fc..5c00f218a 100644 --- a/extensions/windows-event-log/CollectorInitiatedSubscription.cpp +++ b/extensions/windows-event-log/CollectorInitiatedSubscription.cpp @@ -160,7 +160,7 @@ const core::Property CollectorInitiatedSubscription::InactiveDurationToReconnect const core::Relationship CollectorInitiatedSubscription::Success("success", "Relationship for successfully consumed events."); CollectorInitiatedSubscription::CollectorInitiatedSubscription(const std::string& name, const utils::Identifier& uuid) - : core::Processor(name, uuid), logger_(core::logging::LoggerFactory<CollectorInitiatedSubscription>::getLogger()) { + : core::Processor(name, uuid), logger_(core::logging::LoggerFactory<CollectorInitiatedSubscription>::getLogger(uuid_)) { char buff[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = sizeof(buff); if (GetComputerName(buff, &size)) { diff --git a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp index 578da4e9f..714023acd 100644 --- a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp +++ b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp @@ -177,7 +177,7 @@ const core::Relationship ConsumeWindowsEventLog::Success("success", "Relationshi ConsumeWindowsEventLog::ConsumeWindowsEventLog(const std::string& name, const utils::Identifier& uuid) : core::Processor(name, uuid), - logger_(core::logging::LoggerFactory<ConsumeWindowsEventLog>::getLogger()) { + logger_(core::logging::LoggerFactory<ConsumeWindowsEventLog>::getLogger(uuid_)) { char buff[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = sizeof(buff); if (GetComputerName(buff, &size)) { diff --git a/libminifi/include/Funnel.h b/libminifi/include/Funnel.h index e17689f5c..02e8aaa8b 100644 --- a/libminifi/include/Funnel.h +++ b/libminifi/include/Funnel.h @@ -26,7 +26,7 @@ namespace org::apache::nifi::minifi { class Funnel final : public ForwardingNode { public: - Funnel(std::string name, const utils::Identifier& uuid) : ForwardingNode(std::move(name), uuid, core::logging::LoggerFactory<Funnel>::getLogger()) {} + Funnel(std::string name, const utils::Identifier& uuid) : ForwardingNode(std::move(name), uuid, core::logging::LoggerFactory<Funnel>::getLogger(uuid)) {} explicit Funnel(std::string name) : ForwardingNode(std::move(name), core::logging::LoggerFactory<Funnel>::getLogger()) {} MINIFIAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED; diff --git a/libminifi/include/Port.h b/libminifi/include/Port.h index 65c358b9c..1f17519fe 100644 --- a/libminifi/include/Port.h +++ b/libminifi/include/Port.h @@ -31,7 +31,7 @@ enum class PortType { class Port final : public ForwardingNode { public: - Port(std::string name, const utils::Identifier& uuid, PortType port_type) : ForwardingNode(std::move(name), uuid, core::logging::LoggerFactory<Port>::getLogger()), port_type_(port_type) {} + Port(std::string name, const utils::Identifier& uuid, PortType port_type) : ForwardingNode(std::move(name), uuid, core::logging::LoggerFactory<Port>::getLogger(uuid)), port_type_(port_type) {} Port(std::string name, PortType port_type) : ForwardingNode(std::move(name), core::logging::LoggerFactory<Port>::getLogger()), port_type_(port_type) {} PortType getPortType() const { return port_type_; diff --git a/libminifi/include/RemoteProcessorGroupPort.h b/libminifi/include/RemoteProcessorGroupPort.h index 8d5d4e5b1..6cf1778ce 100644 --- a/libminifi/include/RemoteProcessorGroupPort.h +++ b/libminifi/include/RemoteProcessorGroupPort.h @@ -81,7 +81,7 @@ class RemoteProcessorGroupPort : public core::Processor { timeout_(0), bypass_rest_api_(false), ssl_service(nullptr), - logger_(core::logging::LoggerFactory<RemoteProcessorGroupPort>::getLogger()) { + logger_(core::logging::LoggerFactory<RemoteProcessorGroupPort>::getLogger(uuid)) { client_type_ = sitetosite::CLIENT_TYPE::RAW; stream_factory_ = stream_factory; protocol_uuid_ = uuid; diff --git a/libminifi/include/controllers/LinuxPowerManagementService.h b/libminifi/include/controllers/LinuxPowerManagementService.h index ad27fd37e..01bff6f47 100644 --- a/libminifi/include/controllers/LinuxPowerManagementService.h +++ b/libminifi/include/controllers/LinuxPowerManagementService.h @@ -133,7 +133,7 @@ class LinuxPowerManagerService : public ThreadManagementService { std::string status_keyword_; private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LinuxPowerManagerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<LinuxPowerManagerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/controllers/NetworkPrioritizerService.h b/libminifi/include/controllers/NetworkPrioritizerService.h index b2d4db8a2..68519b836 100644 --- a/libminifi/include/controllers/NetworkPrioritizerService.h +++ b/libminifi/include/controllers/NetworkPrioritizerService.h @@ -134,7 +134,7 @@ class NetworkPrioritizerService : public core::controller::ControllerService, pu private: std::shared_ptr<utils::timeutils::Clock> clock_; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<NetworkPrioritizerService>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<NetworkPrioritizerService>::getLogger(uuid_); }; } // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/controllers/SSLContextService.h b/libminifi/include/controllers/SSLContextService.h index 19a492574..f61ecef2b 100644 --- a/libminifi/include/controllers/SSLContextService.h +++ b/libminifi/include/controllers/SSLContextService.h @@ -82,13 +82,13 @@ class SSLContextService : public core::controller::ControllerService { explicit SSLContextService(std::string name, const utils::Identifier &uuid = {}) : ControllerService(std::move(name), uuid), initialized_(false), - logger_(core::logging::LoggerFactory<SSLContextService>::getLogger()) { + logger_(core::logging::LoggerFactory<SSLContextService>::getLogger(uuid_)) { } explicit SSLContextService(std::string name, const std::shared_ptr<Configure> &configuration) : ControllerService(std::move(name)), initialized_(false), - logger_(core::logging::LoggerFactory<SSLContextService>::getLogger()) { + logger_(core::logging::LoggerFactory<SSLContextService>::getLogger(uuid_)) { setConfiguration(configuration); initialize(); @@ -256,6 +256,5 @@ class SSLContextService : public core::controller::ControllerService { std::shared_ptr<core::logging::Logger> logger_; }; -typedef int (SSLContextService::*ptr)(char *, int, int, void *); } // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/core/Processor.h b/libminifi/include/core/Processor.h index 81706134f..52a5f12da 100644 --- a/libminifi/include/core/Processor.h +++ b/libminifi/include/core/Processor.h @@ -247,7 +247,6 @@ class Processor : public Connectable, public ConfigurableComponent, public state mutable std::mutex mutex_; std::atomic<std::chrono::time_point<std::chrono::system_clock>> yield_expiration_{}; - private: static std::mutex& getGraphMutex() { static std::mutex mutex{}; return mutex; diff --git a/libminifi/include/core/logging/Logger.h b/libminifi/include/core/logging/Logger.h index 29c2a64d3..91b90686c 100644 --- a/libminifi/include/core/logging/Logger.h +++ b/libminifi/include/core/logging/Logger.h @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_LOGGING_LOGGER_H_ -#define LIBMINIFI_INCLUDE_CORE_LOGGING_LOGGER_H_ +#pragma once #include <string> #include <mutex> #include <memory> +#include <optional> #include <sstream> #include <utility> #include <iostream> @@ -33,14 +33,9 @@ #include "utils/SmallString.h" #include "utils/meta/detected.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { -namespace logging { +namespace org::apache::nifi::minifi::core::logging { -#define LOG_BUFFER_SIZE 1024 +inline constexpr size_t LOG_BUFFER_SIZE = 1024; class LoggerControl { public: @@ -83,29 +78,30 @@ std::string format_string(int max_size, char const* format_str, const Args& ...a if (result < 0) { return "Error while formatting log message"; } - if (result <= LOG_BUFFER_SIZE) { + const auto buf_size = gsl::narrow<size_t>(result); + if (buf_size <= LOG_BUFFER_SIZE) { // static buffer was large enough - return std::string(buf, gsl::narrow<size_t>(result)); + return {buf, buf_size}; } - if (max_size >= 0 && max_size <= LOG_BUFFER_SIZE) { + if (max_size >= 0 && gsl::narrow<size_t>(max_size) <= LOG_BUFFER_SIZE) { // static buffer was already larger than allowed, use the filled buffer - return std::string(buf, LOG_BUFFER_SIZE); + return {buf, LOG_BUFFER_SIZE}; } // try to use dynamic buffer - size_t dynamic_buffer_size = max_size < 0 ? gsl::narrow<size_t>(result) : gsl::narrow<size_t>(std::min(result, max_size)); + size_t dynamic_buffer_size = max_size < 0 ? buf_size : gsl::narrow<size_t>(std::min(result, max_size)); std::vector<char> buffer(dynamic_buffer_size + 1); // extra '\0' character result = std::snprintf(buffer.data(), buffer.size(), format_str, conditional_convert(args)...); if (result < 0) { return "Error while formatting log message"; } - return std::string(buffer.cbegin(), buffer.cend() - 1); // -1 to not include the terminating '\0' + return {buffer.cbegin(), buffer.cend() - 1}; // -1 to not include the terminating '\0' } inline std::string format_string(int /*max_size*/, char const* format_str) { return format_str; } -typedef enum { +enum LOG_LEVEL { trace = 0, debug = 1, info = 2, @@ -113,7 +109,7 @@ typedef enum { err = 4, critical = 5, off = 6 -} LOG_LEVEL; +}; class BaseLogger { public: @@ -153,6 +149,9 @@ class LogBuilder { class Logger : public BaseLogger { public: + Logger(Logger const&) = delete; + Logger& operator=(Logger const&) = delete; + /** * @brief Log error message * @param format format string ('man printf' for syntax) @@ -207,16 +206,17 @@ class Logger : public BaseLogger { max_log_size_ = size; } - bool should_log(const LOG_LEVEL &level); + bool should_log(const LOG_LEVEL &level) override; - virtual void log_string(LOG_LEVEL level, std::string str); + void log_string(LOG_LEVEL level, std::string str) override; + + virtual std::optional<std::string> get_id() = 0; protected: Logger(std::shared_ptr<spdlog::logger> delegate, std::shared_ptr<LoggerControl> controller); Logger(std::shared_ptr<spdlog::logger> delegate); // NOLINT - std::shared_ptr<spdlog::logger> delegate_; std::shared_ptr<LoggerControl> controller_; @@ -231,14 +231,14 @@ class Logger : public BaseLogger { if (!delegate_->should_log(level)) { return; } - const auto str = format_string(max_log_size_.load(), format, conditional_stringify(std::forward<Args>(args))...); + auto str = format_string(max_log_size_.load(), format, conditional_stringify(std::forward<Args>(args))...); + if (const auto id = get_id()) { + str = str + *id; + } delegate_->log(level, str); } std::atomic<int> max_log_size_{LOG_BUFFER_SIZE}; - - Logger(Logger const&); - Logger& operator=(Logger const&); }; #define LOG_DEBUG(x) LogBuilder((x).get(), org::apache::nifi::minifi::core::logging::LOG_LEVEL::debug) @@ -251,11 +251,4 @@ class Logger : public BaseLogger { #define LOG_WARN(x) LogBuilder((x).get(), org::apache::nifi::minifi::core::logging::LOG_LEVEL::warn) -} // namespace logging -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_LOGGING_LOGGER_H_ +} // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/include/core/logging/LoggerConfiguration.h b/libminifi/include/core/logging/LoggerConfiguration.h index eb79f9977..42f6d7a45 100644 --- a/libminifi/include/core/logging/LoggerConfiguration.h +++ b/libminifi/include/core/logging/LoggerConfiguration.h @@ -58,12 +58,11 @@ struct LoggerNamespace { std::map<std::string, std::shared_ptr<LoggerNamespace>> children; void forEachSink(const std::function<void(const std::shared_ptr<spdlog::sinks::sink>&)>& op) const; - - LoggerNamespace() - : sinks(std::vector<std::shared_ptr<spdlog::sinks::sink>>()), - children(std::map<std::string, std::shared_ptr<LoggerNamespace>>()) { - } }; + +inline std::optional<std::string> formatId(std::optional<utils::Identifier> opt_id) { + return opt_id | utils::map([](auto id) { return " (" + std::string(id.to_string()) + ")"; }); +} } // namespace internal class LoggerConfiguration { @@ -110,7 +109,7 @@ class LoggerConfiguration { /** * Can be used to get arbitrarily named Logger, LoggerFactory should be preferred within a class. */ - std::shared_ptr<Logger> getLogger(const std::string &name); + std::shared_ptr<Logger> getLogger(const std::string& name, const std::optional<utils::Identifier>& id = {}); static const char *spdlog_default_pattern; @@ -120,7 +119,7 @@ class LoggerConfiguration { const std::shared_ptr<spdlog::formatter>& formatter, bool remove_if_present = false); private: - std::shared_ptr<Logger> getLogger(const std::string& name, const std::lock_guard<std::mutex>& lock); + std::shared_ptr<Logger> getLogger(const std::string& name, const std::optional<utils::Identifier>& id, const std::lock_guard<std::mutex>& lock); void initializeCompression(const std::lock_guard<std::mutex>& lock, const std::shared_ptr<LoggerProperties>& properties); @@ -133,16 +132,21 @@ class LoggerConfiguration { class LoggerImpl : public Logger { public: - explicit LoggerImpl(std::string name, const std::shared_ptr<LoggerControl> &controller, const std::shared_ptr<spdlog::logger> &delegate) + explicit LoggerImpl(std::string name, std::optional<utils::Identifier> id, const std::shared_ptr<LoggerControl> &controller, const std::shared_ptr<spdlog::logger> &delegate) : Logger(delegate, controller), - name(std::move(name)) { + name(std::move(name)), + id(internal::formatId(id)) { } void set_delegate(std::shared_ptr<spdlog::logger> delegate) { std::lock_guard<std::mutex> lock(mutex_); delegate_ = std::move(delegate); } - const std::string name; + + std::optional<std::string> get_id() override { return id; } + + std::string name; + std::optional<std::string> id; }; static std::shared_ptr<spdlog::sinks::rotating_file_sink_mt> getRotatingFileSink(const std::string& appender_key, const std::shared_ptr<LoggerProperties>& properties); @@ -156,7 +160,8 @@ class LoggerConfiguration { std::shared_ptr<LoggerImpl> logger_ = nullptr; std::shared_ptr<LoggerControl> controller_; std::unordered_set<std::shared_ptr<AlertSink>> alert_sinks_; - bool shorten_names_; + bool shorten_names_ = false; + bool include_uuid_ = true; }; } // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/include/core/logging/LoggerFactory.h b/libminifi/include/core/logging/LoggerFactory.h index 104d9437a..86c9812ec 100644 --- a/libminifi/include/core/logging/LoggerFactory.h +++ b/libminifi/include/core/logging/LoggerFactory.h @@ -28,19 +28,20 @@ namespace org::apache::nifi::minifi::core::logging { class LoggerFactoryBase { public: - static std::shared_ptr<Logger> getAliasedLogger(const std::string &alias); + static std::shared_ptr<Logger> getAliasedLogger(const std::string& name, const std::optional<utils::Identifier>& id = {}); }; template<typename T> class LoggerFactory : public LoggerFactoryBase { public: - /** - * Gets an initialized logger for the template class. - */ static std::shared_ptr<Logger> getLogger() { static std::shared_ptr<Logger> logger = getAliasedLogger(core::getClassName<T>()); return logger; } + + static std::shared_ptr<Logger> getLogger(const utils::Identifier& uuid) { + return getAliasedLogger(core::getClassName<T>(), uuid); + } }; } // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/src/core/Connectable.cpp b/libminifi/src/core/Connectable.cpp index 00a8cef37..c3bc0803b 100644 --- a/libminifi/src/core/Connectable.cpp +++ b/libminifi/src/core/Connectable.cpp @@ -29,14 +29,14 @@ Connectable::Connectable(std::string name, const utils::Identifier &uuid) : CoreComponent(std::move(name), uuid), max_concurrent_tasks_(1), connectable_version_(nullptr), - logger_(logging::LoggerFactory<Connectable>::getLogger()) { + logger_(logging::LoggerFactory<Connectable>::getLogger(uuid_)) { } Connectable::Connectable(std::string name) : CoreComponent(std::move(name)), max_concurrent_tasks_(1), connectable_version_(nullptr), - logger_(logging::LoggerFactory<Connectable>::getLogger()) { + logger_(logging::LoggerFactory<Connectable>::getLogger(uuid_)) { } Connectable::~Connectable() = default; diff --git a/libminifi/src/core/Processor.cpp b/libminifi/src/core/Processor.cpp index 022941b24..ed40dc3b8 100644 --- a/libminifi/src/core/Processor.cpp +++ b/libminifi/src/core/Processor.cpp @@ -43,7 +43,7 @@ namespace org::apache::nifi::minifi::core { Processor::Processor(std::string name, std::shared_ptr<ProcessorMetrics> metrics) : Connectable(std::move(name)), - logger_(logging::LoggerFactory<Processor>::getLogger()), + logger_(logging::LoggerFactory<Processor>::getLogger(uuid_)), metrics_(metrics ? std::move(metrics) : std::make_shared<ProcessorMetrics>(*this)) { has_work_.store(false); // Setup the default values @@ -62,7 +62,7 @@ Processor::Processor(std::string name, std::shared_ptr<ProcessorMetrics> metrics Processor::Processor(std::string name, const utils::Identifier& uuid, std::shared_ptr<ProcessorMetrics> metrics) : Connectable(std::move(name), uuid), - logger_(logging::LoggerFactory<Processor>::getLogger()), + logger_(logging::LoggerFactory<Processor>::getLogger(uuid_)), metrics_(metrics ? std::move(metrics) : std::make_shared<ProcessorMetrics>(*this)) { has_work_.store(false); // Setup the default values diff --git a/libminifi/src/core/logging/LoggerConfiguration.cpp b/libminifi/src/core/logging/LoggerConfiguration.cpp index ff86eb690..07709dde7 100644 --- a/libminifi/src/core/logging/LoggerConfiguration.cpp +++ b/libminifi/src/core/logging/LoggerConfiguration.cpp @@ -91,10 +91,13 @@ std::vector<std::string> LoggerProperties::get_keys_of_type(const std::string &t LoggerConfiguration::LoggerConfiguration() : root_namespace_(create_default_root()), - formatter_(std::make_shared<spdlog::pattern_formatter>(spdlog_default_pattern)), - shorten_names_(false) { + formatter_(std::make_shared<spdlog::pattern_formatter>(spdlog_default_pattern)) { controller_ = std::make_shared<LoggerControl>(); - logger_ = std::make_shared<LoggerImpl>(core::getClassName<LoggerConfiguration>(), controller_, get_logger(nullptr, root_namespace_, core::getClassName<LoggerConfiguration>(), formatter_)); + logger_ = std::make_shared<LoggerImpl>( + core::getClassName<LoggerConfiguration>(), + std::nullopt, + controller_, + get_logger(nullptr, root_namespace_, core::getClassName<LoggerConfiguration>(), formatter_)); loggers.push_back(logger_); } @@ -121,9 +124,12 @@ void LoggerConfiguration::initialize(const std::shared_ptr<LoggerProperties> &lo /** * There is no need to shorten names per spdlog sink as this is a per log instance. */ - std::string shorten_names_str; - if (logger_properties->getString("spdlog.shorten_names", shorten_names_str)) { - shorten_names_ = utils::StringUtils::toBool(shorten_names_str).value_or(false); + if (const auto shorten_names_str = logger_properties->getString("spdlog.shorten_names")) { + shorten_names_ = utils::StringUtils::toBool(*shorten_names_str).value_or(false); + } + + if (const auto include_uuid_str = logger_properties->getString("logger.include.uuid")) { + include_uuid_ = utils::StringUtils::toBool(*include_uuid_str).value_or(true); } formatter_ = std::make_shared<spdlog::pattern_formatter>(spdlog_pattern); @@ -142,12 +148,12 @@ void LoggerConfiguration::initialize(const std::shared_ptr<LoggerProperties> &lo logger_->log_debug("Set following pattern on loggers: %s", spdlog_pattern); } -std::shared_ptr<Logger> LoggerConfiguration::getLogger(const std::string &name) { +std::shared_ptr<Logger> LoggerConfiguration::getLogger(const std::string& name, const std::optional<utils::Identifier>& id) { std::lock_guard<std::mutex> lock(mutex); - return getLogger(name, lock); + return getLogger(name, id, lock); } -std::shared_ptr<Logger> LoggerConfiguration::getLogger(const std::string &name, const std::lock_guard<std::mutex>& /*lock*/) { +std::shared_ptr<Logger> LoggerConfiguration::getLogger(const std::string& name, const std::optional<utils::Identifier>& id, const std::lock_guard<std::mutex>& /*lock*/) { std::string adjusted_name = name; const std::string clazz = "class "; auto haz_clazz = name.find(clazz); @@ -157,7 +163,9 @@ std::shared_ptr<Logger> LoggerConfiguration::getLogger(const std::string &name, utils::ClassUtils::shortenClassName(adjusted_name, adjusted_name); } - std::shared_ptr<LoggerImpl> result = std::make_shared<LoggerImpl>(adjusted_name, controller_, get_logger(logger_, root_namespace_, adjusted_name, formatter_)); + const auto id_if_enabled = include_uuid_ ? id : std::nullopt; + + std::shared_ptr<LoggerImpl> result = std::make_shared<LoggerImpl>(adjusted_name, id_if_enabled, controller_, get_logger(logger_, root_namespace_, adjusted_name, formatter_)); loggers.push_back(result); return result; } @@ -320,7 +328,7 @@ std::shared_ptr<internal::LoggerNamespace> LoggerConfiguration::create_default_r } void LoggerConfiguration::initializeCompression(const std::lock_guard<std::mutex>& lock, const std::shared_ptr<LoggerProperties>& properties) { - auto compression_sink = compression_manager_.initialize(properties, logger_, [&] (const std::string& name) {return getLogger(name, lock);}); + auto compression_sink = compression_manager_.initialize(properties, logger_, [&] (const std::string& name) {return getLogger(name, std::nullopt, lock);}); if (compression_sink) { root_namespace_->sinks.push_back(compression_sink); root_namespace_->exported_sinks.push_back(compression_sink); diff --git a/libminifi/src/core/logging/LoggerFactory.cpp b/libminifi/src/core/logging/LoggerFactory.cpp index b7b7f591b..99c0aaf26 100644 --- a/libminifi/src/core/logging/LoggerFactory.cpp +++ b/libminifi/src/core/logging/LoggerFactory.cpp @@ -21,8 +21,8 @@ namespace org::apache::nifi::minifi::core::logging { -std::shared_ptr<Logger> LoggerFactoryBase::getAliasedLogger(const std::string &alias) { - return LoggerConfiguration::getConfiguration().getLogger(alias); +std::shared_ptr<Logger> LoggerFactoryBase::getAliasedLogger(const std::string& name, const std::optional<utils::Identifier>& id) { + return LoggerConfiguration::getConfiguration().getLogger(name, id); } } // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/test/ReadFromFlowFileTestProcessor.h b/libminifi/test/ReadFromFlowFileTestProcessor.h index bb65aedc9..5e476bb3f 100644 --- a/libminifi/test/ReadFromFlowFileTestProcessor.h +++ b/libminifi/test/ReadFromFlowFileTestProcessor.h @@ -56,7 +56,6 @@ class ReadFromFlowFileTestProcessor : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS - public: void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory *sessionFactory) override; void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; void initialize() override; @@ -89,7 +88,7 @@ class ReadFromFlowFileTestProcessor : public core::Processor { std::map<std::string, std::string> attributes_; }; bool clear_on_trigger_ = true; - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ReadFromFlowFileTestProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ReadFromFlowFileTestProcessor>::getLogger(uuid_); std::vector<FlowFileData> flow_files_read_; }; diff --git a/libminifi/test/TestBase.cpp b/libminifi/test/TestBase.cpp index 715378dd0..11246b7df 100644 --- a/libminifi/test/TestBase.cpp +++ b/libminifi/test/TestBase.cpp @@ -70,8 +70,8 @@ void LogTestController::setLevel(const std::string& name, spdlog::level::level_e logging::LoggerConfiguration::getSpdlogLogger(adjusted_name)->set_level(level); } -std::shared_ptr<logging::Logger> LogTestController::getLoggerByClassName(const std::string& class_name) { - return config ? config->getLogger(class_name) : logging::LoggerConfiguration::getConfiguration().getLogger(class_name); +std::shared_ptr<logging::Logger> LogTestController::getLoggerByClassName(const std::string& class_name, const std::optional<utils::Identifier>& id) { + return config ? config->getLogger(class_name, id) : logging::LoggerConfiguration::getConfiguration().getLogger(class_name, id); } void LogTestController::setLevelByClassName(spdlog::level::level_enum level, const std::string& class_name) { diff --git a/libminifi/test/TestBase.h b/libminifi/test/TestBase.h index 2add4eba4..58530a772 100644 --- a/libminifi/test/TestBase.h +++ b/libminifi/test/TestBase.h @@ -118,9 +118,9 @@ class LogTestController { * of changeable test formats */ template<typename T> - std::shared_ptr<logging::Logger> getLogger() { return getLoggerByClassName(minifi::core::getClassName<T>()); } + std::shared_ptr<logging::Logger> getLogger(const std::optional<utils::Identifier>& id = {}) { return getLoggerByClassName(minifi::core::getClassName<T>(), id); } - std::shared_ptr<logging::Logger> getLoggerByClassName(const std::string& class_name); + std::shared_ptr<logging::Logger> getLoggerByClassName(const std::string& class_name, const std::optional<utils::Identifier>& id = {}); template<typename T> void setLevel(spdlog::level::level_enum level) { diff --git a/libminifi/test/WriteToFlowFileTestProcessor.h b/libminifi/test/WriteToFlowFileTestProcessor.h index 08dd520af..3e22c1289 100644 --- a/libminifi/test/WriteToFlowFileTestProcessor.h +++ b/libminifi/test/WriteToFlowFileTestProcessor.h @@ -51,7 +51,6 @@ class WriteToFlowFileTestProcessor : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS - public: void onSchedule(core::ProcessContext *context, core::ProcessSessionFactory *sessionFactory) override; void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; void initialize() override; @@ -66,7 +65,7 @@ class WriteToFlowFileTestProcessor : public core::Processor { } private: - std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<WriteToFlowFileTestProcessor>::getLogger(); + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<WriteToFlowFileTestProcessor>::getLogger(uuid_); std::string content_; }; diff --git a/libminifi/test/sql-tests/mocks/MockODBCService.h b/libminifi/test/sql-tests/mocks/MockODBCService.h index 056aa93f0..11956a474 100644 --- a/libminifi/test/sql-tests/mocks/MockODBCService.h +++ b/libminifi/test/sql-tests/mocks/MockODBCService.h @@ -32,7 +32,7 @@ class MockODBCService : public DatabaseService { public: explicit MockODBCService(std::string name, utils::Identifier uuid = utils::Identifier()) : DatabaseService(std::move(name), uuid), - logger_(logging::LoggerFactory<MockODBCService>::getLogger()) { + logger_(logging::LoggerFactory<MockODBCService>::getLogger(uuid)) { initialize(); } diff --git a/libminifi/test/unit/LoggerTests.cpp b/libminifi/test/unit/LoggerTests.cpp index f1d233adb..1fef27fa1 100644 --- a/libminifi/test/unit/LoggerTests.cpp +++ b/libminifi/test/unit/LoggerTests.cpp @@ -79,6 +79,41 @@ TEST_CASE("Test log Levels change", "[ttl5]") { LogTestController::getInstance().reset(); } +TEST_CASE("Logger configured with an ID prints this ID in every log line", "[logger][id]") { + LogTestController::getInstance().setTrace<logging::Logger>(); + const auto uuid = utils::IdGenerator::getIdGenerator()->generate(); + std::shared_ptr<logging::Logger> logger = logging::LoggerFactory<logging::Logger>::getLogger(uuid); + logger->log_error("hello %s", "world"); + + CHECK(LogTestController::getInstance().contains("[org::apache::nifi::minifi::core::logging::Logger] [error] hello world (" + uuid.to_string() + ")")); + LogTestController::getInstance().reset(); +} + +TEST_CASE("Printing of the ID can be disabled in the config", "[logger][id][configuration]") { + auto properties = std::make_shared<logging::LoggerProperties>(); + + bool id_is_present{}; + SECTION("Property not set") { + id_is_present = true; + } + SECTION("Property set to true") { + properties->set("logger.include.uuid", "true"); + id_is_present = true; + } + SECTION("Property set to false") { + properties->set("logger.include.uuid", "false"); + id_is_present = false; + } + + const auto uuid = utils::IdGenerator::getIdGenerator()->generate(); + std::shared_ptr<logging::Logger> logger = LogTestController::getInstance(properties)->getLogger<logging::Logger>(uuid); + logger->log_error("hello %s", "world"); + + CHECK(LogTestController::getInstance().contains("[org::apache::nifi::minifi::core::logging::Logger] [error] hello world")); + CHECK(id_is_present == LogTestController::getInstance().contains(uuid.to_string())); + LogTestController::getInstance().reset(); +} + struct CStringConvertible { [[nodiscard]] const char* c_str() const { return data.c_str(); diff --git a/nanofi/include/cxx/CallbackProcessor.h b/nanofi/include/cxx/CallbackProcessor.h index 5eeb96a75..8a78a1204 100644 --- a/nanofi/include/cxx/CallbackProcessor.h +++ b/nanofi/include/cxx/CallbackProcessor.h @@ -17,8 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __CALLBACK_PROCESSOR_H__ -#define __CALLBACK_PROCESSOR_H__ +#pragma once #include <stdio.h> #include <string> @@ -73,9 +72,7 @@ class CallbackProcessor : public core::Processor { std::function<void(core::ProcessSession*, core::ProcessContext *context)> ontrigger_callback_; std::function<void(core::ProcessContext *context)> onschedule_callback_; private: - std::shared_ptr<core::logging::Logger> logger_{ core::logging::LoggerFactory<CallbackProcessor>::getLogger() }; + std::shared_ptr<core::logging::Logger> logger_{ core::logging::LoggerFactory<CallbackProcessor>::getLogger(uuid_) }; }; } // namespace org::apache::nifi::minifi::processors - -#endif
