http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/Core.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/Core.h b/libminifi/include/core/Core.h index 3864882..a9fb435 100644 --- a/libminifi/include/core/Core.h +++ b/libminifi/include/core/Core.h @@ -18,9 +18,11 @@ #ifndef LIBMINIFI_INCLUDE_CORE_CORE_H_ #define LIBMINIFI_INCLUDE_CORE_CORE_H_ +#include <cstdlib> +#include <memory> +#include <string> #include <uuid/uuid.h> #include <cxxabi.h> -#include "core/logging/Logger.h" /** * namespace aliasing */ @@ -93,8 +95,7 @@ class CoreComponent { * Constructor that sets the name and uuid. */ explicit CoreComponent(const std::string name, uuid_t uuid = 0) - : logger_(logging::Logger::getLogger()), - name_(name) { + : name_(name) { if (!uuid) // Generate the global UUID for the flow record uuid_generate(uuid_); @@ -111,8 +112,7 @@ class CoreComponent { * Move Constructor. */ explicit CoreComponent(const CoreComponent &&other) - : name_(std::move(other.name_)), - logger_(logging::Logger::getLogger()) { + : name_(std::move(other.name_)) { uuid_copy(uuid_, other.uuid_); } @@ -156,9 +156,6 @@ class CoreComponent { // UUID string std::string uuidStr_; - // logger shared ptr - std::shared_ptr<org::apache::nifi::minifi::core::logging::Logger> logger_; - // Connectable's name std::string name_; };
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/FlowConfiguration.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/FlowConfiguration.h b/libminifi/include/core/FlowConfiguration.h index b918aac..1fee8c5 100644 --- a/libminifi/include/core/FlowConfiguration.h +++ b/libminifi/include/core/FlowConfiguration.h @@ -36,7 +36,7 @@ #include "processors/ExecuteProcess.h" #include "processors/AppendHostInfo.h" #include "core/Processor.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" #include "core/ProcessGroup.h" @@ -66,7 +66,8 @@ class FlowConfiguration : public CoreComponent { : CoreComponent(core::getClassName<FlowConfiguration>()), flow_file_repo_(flow_file_repo), config_path_(path), - stream_factory_(stream_factory) { + stream_factory_(stream_factory), + logger_(logging::LoggerFactory<FlowConfiguration>::getLogger()) { controller_services_ = std::make_shared< core::controller::ControllerServiceMap>(); service_provider_ = std::make_shared< @@ -133,6 +134,9 @@ class FlowConfiguration : public CoreComponent { std::shared_ptr<core::Repository> flow_file_repo_; // stream factory std::shared_ptr<io::StreamFactory> stream_factory_; + + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace core */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/FlowFile.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/FlowFile.h b/libminifi/include/core/FlowFile.h index 394b9d4..050d15f 100644 --- a/libminifi/include/core/FlowFile.h +++ b/libminifi/include/core/FlowFile.h @@ -263,14 +263,14 @@ class FlowFile { // UUID string for all parents std::set<std::string> lineage_Identifiers_; - // Logger - std::shared_ptr<logging::Logger> logger_; - // Connection queue that this flow file will be transfer or current in std::shared_ptr<core::Connectable> connection_; // Orginal connection queue that this flow file was dequeued from std::shared_ptr<core::Connectable> original_connection_; + private: + // Logger + std::shared_ptr<logging::Logger> logger_; }; } /* namespace core */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/ProcessContext.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/ProcessContext.h b/libminifi/include/core/ProcessContext.h index 79b7704..8094e05 100644 --- a/libminifi/include/core/ProcessContext.h +++ b/libminifi/include/core/ProcessContext.h @@ -29,7 +29,7 @@ #include "Property.h" #include "core/controller/ControllerServiceProvider.h" #include "core/controller/ControllerServiceLookup.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "ProcessorNode.h" #include "core/Repository.h" @@ -51,8 +51,7 @@ class ProcessContext : public controller::ControllerServiceLookup { std::shared_ptr<controller::ControllerServiceProvider> &controller_service_provider, std::shared_ptr<core::Repository> repo) : processor_node_(processor), - controller_service_provider_(controller_service_provider) { - logger_ = logging::Logger::getLogger(); + controller_service_provider_(controller_service_provider), logger_(logging::LoggerFactory<ProcessContext>::getLogger()) { repo_ = repo; } // Destructor http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/ProcessSession.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/ProcessSession.h b/libminifi/include/core/ProcessSession.h index 70805e9..1f6f234 100644 --- a/libminifi/include/core/ProcessSession.h +++ b/libminifi/include/core/ProcessSession.h @@ -30,7 +30,7 @@ #include "ProcessContext.h" #include "FlowFileRecord.h" #include "Exception.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "FlowFile.h" #include "provenance/Provenance.h" @@ -48,8 +48,7 @@ class ProcessSession { * Create a new process session */ ProcessSession(ProcessContext *processContext = NULL) - : process_context_(processContext) { - logger_ = logging::Logger::getLogger(); + : process_context_(processContext), logger_(logging::LoggerFactory<ProcessSession>::getLogger()) { logger_->log_trace("ProcessSession created for %s", process_context_->getProcessorNode().getName().c_str()); auto repo = processContext->getProvenanceRepository(); http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/Processor.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/Processor.h b/libminifi/include/core/Processor.h index 1a18e77..9a19072 100644 --- a/libminifi/include/core/Processor.h +++ b/libminifi/include/core/Processor.h @@ -257,6 +257,8 @@ class Processor : public Connectable, public ConfigurableComponent, Processor(const Processor &parent); Processor &operator=(const Processor &parent); + private: + std::shared_ptr<logging::Logger> logger_; }; } http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/Repository.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/Repository.h b/libminifi/include/core/Repository.h index 94517d8..debdc01 100644 --- a/libminifi/include/core/Repository.h +++ b/libminifi/include/core/Repository.h @@ -33,7 +33,7 @@ #include <vector> #include "properties/Configure.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "core/Property.h" #include "ResourceClaim.h" #include "io/Serializable.h" @@ -63,7 +63,8 @@ class Repository : public CoreComponent { int64_t maxPartitionBytes = MAX_REPOSITORY_STORAGE_SIZE, uint64_t purgePeriod = REPOSITORY_PURGE_PERIOD) : CoreComponent(repo_name), - thread_() { + thread_(), + logger_(logging::LoggerFactory<Repository>::getLogger()) { directory_ = directory; max_partition_millis_ = maxPartitionMillis; max_partition_bytes_ = maxPartitionBytes; @@ -145,6 +146,9 @@ class Repository : public CoreComponent { void threadExecutor() { run(); } + + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace core */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/controller/ControllerService.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/controller/ControllerService.h b/libminifi/include/core/controller/ControllerService.h index 86c8f7a..7fcc338 100644 --- a/libminifi/include/core/controller/ControllerService.h +++ b/libminifi/include/core/controller/ControllerService.h @@ -64,7 +64,6 @@ class ControllerService : public ConfigurableComponent, public Connectable { */ explicit ControllerService() : Connectable(core::getClassName<ControllerService>(), 0), - ConfigurableComponent(logging::Logger::getLogger()), configuration_(std::make_shared<Configure>()) { current_state_ = DISABLED; } @@ -74,7 +73,6 @@ class ControllerService : public ConfigurableComponent, public Connectable { */ explicit ControllerService(const std::string &name, const std::string &id) : Connectable(name, 0), - ConfigurableComponent(logging::Logger::getLogger()), configuration_(std::make_shared<Configure>()) { current_state_ = DISABLED; uuid_parse(id.c_str(), uuid_); @@ -88,7 +86,6 @@ class ControllerService : public ConfigurableComponent, public Connectable { */ explicit ControllerService(const std::string &name, uuid_t uuid) : Connectable(name, uuid), - ConfigurableComponent(logging::Logger::getLogger()), configuration_(std::make_shared<Configure>()) { current_state_ = DISABLED; } http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/controller/ControllerServiceNode.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/controller/ControllerServiceNode.h b/libminifi/include/core/controller/ControllerServiceNode.h index 55913cb..54015be 100644 --- a/libminifi/include/core/controller/ControllerServiceNode.h +++ b/libminifi/include/core/controller/ControllerServiceNode.h @@ -45,7 +45,7 @@ class ControllerServiceNode : public CoreComponent, public ConfigurableComponent explicit ControllerServiceNode(std::shared_ptr<ControllerService> service, const std::string &id, std::shared_ptr<Configure> configuration) : CoreComponent(id), - ConfigurableComponent(logging::Logger::getLogger()), + ConfigurableComponent(), controller_service_(service), configuration_(configuration), active(false) { http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/controller/ControllerServiceProvider.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/controller/ControllerServiceProvider.h b/libminifi/include/core/controller/ControllerServiceProvider.h index a749475..978352b 100644 --- a/libminifi/include/core/controller/ControllerServiceProvider.h +++ b/libminifi/include/core/controller/ControllerServiceProvider.h @@ -39,21 +39,21 @@ class ControllerServiceProvider : public CoreComponent, explicit ControllerServiceProvider(const std::string &name) : CoreComponent(name), - ConfigurableComponent(logging::Logger::getLogger()) { + ConfigurableComponent() { controller_map_ = std::make_shared<ControllerServiceMap>(); } explicit ControllerServiceProvider( std::shared_ptr<ControllerServiceMap> services) : CoreComponent(core::getClassName<ControllerServiceProvider>()), - ConfigurableComponent(logging::Logger::getLogger()), + ConfigurableComponent(), controller_map_(services) { } explicit ControllerServiceProvider( const std::string &name, std::shared_ptr<ControllerServiceMap> services) : CoreComponent(name), - ConfigurableComponent(logging::Logger::getLogger()), + ConfigurableComponent(), controller_map_(services) { } http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/controller/StandardControllerServiceNode.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/controller/StandardControllerServiceNode.h b/libminifi/include/core/controller/StandardControllerServiceNode.h index f599217..563c0f5 100644 --- a/libminifi/include/core/controller/StandardControllerServiceNode.h +++ b/libminifi/include/core/controller/StandardControllerServiceNode.h @@ -20,7 +20,7 @@ #include "core/Core.h" #include "ControllerServiceNode.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "core/ProcessGroup.h" namespace org { @@ -38,14 +38,16 @@ class StandardControllerServiceNode : public ControllerServiceNode { std::shared_ptr<ControllerServiceProvider> provider, const std::string &id, std::shared_ptr<Configure> configuration) : ControllerServiceNode(service, id, configuration), - provider(provider) { + provider(provider), + logger_(logging::LoggerFactory<StandardControllerServiceNode>::getLogger()) { } explicit StandardControllerServiceNode( std::shared_ptr<ControllerService> service, const std::string &id, std::shared_ptr<Configure> configuration) : ControllerServiceNode(service, id, configuration), - provider(nullptr) { + provider(nullptr), + logger_(logging::LoggerFactory<StandardControllerServiceNode>::getLogger()) { } std::shared_ptr<core::ProcessGroup> &getProcessGroup(); @@ -95,6 +97,8 @@ class StandardControllerServiceNode : public ControllerServiceNode { std::mutex mutex_; + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace controller */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/controller/StandardControllerServiceProvider.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/controller/StandardControllerServiceProvider.h b/libminifi/include/core/controller/StandardControllerServiceProvider.h index ba8af56..1e94ab7 100644 --- a/libminifi/include/core/controller/StandardControllerServiceProvider.h +++ b/libminifi/include/core/controller/StandardControllerServiceProvider.h @@ -29,6 +29,7 @@ #include "ControllerServiceNode.h" #include "StandardControllerServiceNode.h" #include "ControllerServiceProvider.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -50,7 +51,8 @@ class StandardControllerServiceProvider : public ControllerServiceProvider, root_group_(root_group), agent_(agent), extension_loader_(loader), - configuration_(configuration) { + configuration_(configuration), + logger_(logging::LoggerFactory<StandardControllerServiceProvider>::getLogger()) { } explicit StandardControllerServiceProvider( @@ -61,7 +63,8 @@ class StandardControllerServiceProvider : public ControllerServiceProvider, root_group_(root_group), agent_(0), extension_loader_(loader), - configuration_(configuration) { + configuration_(configuration), + logger_(logging::LoggerFactory<StandardControllerServiceProvider>::getLogger()) { } explicit StandardControllerServiceProvider( @@ -70,7 +73,8 @@ class StandardControllerServiceProvider : public ControllerServiceProvider, root_group_(std::move(other.root_group_)), agent_(std::move(other.agent_)), extension_loader_(other.extension_loader_), - configuration_(other.configuration_) { + configuration_(other.configuration_), + logger_(logging::LoggerFactory<StandardControllerServiceProvider>::getLogger()) { } @@ -217,6 +221,8 @@ class StandardControllerServiceProvider : public ControllerServiceProvider, std::shared_ptr<ProcessGroup> root_group_; + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace controller */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/logging/BaseLogger.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/logging/BaseLogger.h b/libminifi/include/core/logging/BaseLogger.h deleted file mode 100644 index 904bac2..0000000 --- a/libminifi/include/core/logging/BaseLogger.h +++ /dev/null @@ -1,305 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef LIBMINIFI_INCLUDE_BASELOGGER_H_ -#define LIBMINIFI_INCLUDE_BASELOGGER_H_ - -#include <string> -#include <memory> -#include "spdlog/spdlog.h" -#include <iostream> - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { -namespace logging { - -// 5M default log file size -#define DEFAULT_LOG_FILE_SIZE (5*1024*1024) -// 3 log files rotation -#define DEFAULT_LOG_FILE_NUMBER 3 -#define LOG_NAME "minifi log" -#define LOG_FILE_NAME "minifi-app.log" - -/** - * Log level enumeration. - */ -typedef enum { - trace = 0, - debug = 1, - info = 2, - warn = 3, - err = 4, - critical = 5, - off = 6 -} LOG_LEVEL_E; - -#define LOG_BUFFER_SIZE 1024 - -template<typename ... Args> -inline std::string format_string(char const* format_str, Args&&... args) { - char buf[LOG_BUFFER_SIZE+1] = {0}; - - std::snprintf(buf, LOG_BUFFER_SIZE, format_str, args...); - return std::string(buf); -} - -inline std::string format_string(char const* format_str) { - return format_str; -} -inline char const* conditional_conversion(std::string const& str) { - return str.c_str(); -} - -template<typename T> -inline T conditional_conversion(T const& t) { - return t; -} - -/** - * Base class that represents a logger configuration. - */ -class BaseLogger { - - public: - static const char *nifi_log_level; - static const char *nifi_log_appender; - - /** - * Base Constructor - */ - BaseLogger() { - setLogLevel("info"); - logger_ = nullptr; - stderr_ = nullptr; - } - - /** - * Logger configuration constructorthat will set the base log level. - * @param config incoming configuration. - */ - BaseLogger(std::string log_level, std::shared_ptr<spdlog::logger> logger) - : logger_(logger) { - setLogLevel(log_level); - - } - - virtual ~BaseLogger() { - - } - - /** - * Move constructor that will atomically swap configuration - * shared pointers. - */ - BaseLogger(const BaseLogger &&other) - : configured_level_(other.configured_level_.load()) { - // must atomically exchange the pointers - logger_ = std::move(other.logger_); - set_error_logger(other.stderr_); - - } - - /** - * Returns the log level for this instance. - */ - virtual LOG_LEVEL_E getLogLevel() const { - return configured_level_; - } - - /** - * @brief Log error message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - template<typename ... Args> - void log_error(const char * const format, Args ... args); - /** - * @brief Log warn message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - template<typename ... Args> - void log_warn(const char * const format, Args ... args); - /** - * @brief Log info message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - template<typename ... Args> - void log_info(const char * const format, Args ... args); - /** - * @brief Log debug message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - template<typename ... Args> - void log_debug(const char * const format, Args ... args); - /** - * @brief Log trace message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - template<typename ... Args> - void log_trace(const char * const format, Args ... args); - - /** - * @brief Log error message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - virtual void log_str(LOG_LEVEL_E level, const std::string &buffer); - - /** - * Sets the log level for this instance based on the string - * @param level desired log leve. - * @param defaultLevel default level if we cannot match level. - */ - virtual void setLogLevel(const std::string &level, LOG_LEVEL_E defaultLevel = - info); - - /** - * Sets the log level atomic and sets it - * within logger if it can - * @param level desired log level. - */ - virtual void setLogLevel(LOG_LEVEL_E level) { - configured_level_ = level; - setLogLevel(); - } - - bool shouldLog(LOG_LEVEL_E level) { - return level >= configured_level_.load(std::memory_order_relaxed); - } - - /** - * Move operator overload - */ - BaseLogger &operator=(const BaseLogger &&other) { - configured_level_ = (other.configured_level_.load()); - // must atomically exchange the pointers - logger_ = std::move(other.logger_); - set_error_logger(other.stderr_); - return *this; - } - - protected: - - /** - * Logger configuration constructorthat will set the base log level. - * @param config incoming configuration. - */ - BaseLogger(std::string log_level) - : logger_(nullptr) { - setLogLevel(log_level); - } - - void setLogger(std::shared_ptr<spdlog::logger> logger) { - logger_ = logger; - } - - /** - * Since a thread may be using stderr and it can be null, - * we must atomically exchange the shared pointers. - * @param other other shared pointer. can be null ptr - */ - void set_error_logger(std::shared_ptr<spdlog::logger> other); - - /** - * Sets the log level on the spdlogger if it is not null. - */ - void setLogLevel() { - if (logger_ != nullptr) - logger_->set_level((spdlog::level::level_enum) configured_level_.load()); - - } - - std::atomic<LOG_LEVEL_E> configured_level_; - std::shared_ptr<spdlog::logger> logger_; - std::shared_ptr<spdlog::logger> stderr_; -}; - -/** - * @brief Log error message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ -template<typename ... Args> -void BaseLogger::log_error(const char * const format, Args ... args) { - if (logger_ == NULL || !logger_->should_log(spdlog::level::level_enum::err)) - return; - - log_str(err, format_string(format, conditional_conversion(args)...)); -} -/** - * @brief Log warn message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ -template<typename ... Args> -void BaseLogger::log_warn(const char * const format, Args ... args) { - if (logger_ == NULL || !logger_->should_log(spdlog::level::level_enum::warn)) - return; - - log_str(warn, format_string(format, conditional_conversion(args)...)); -} -/** - * @brief Log info message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ -template<typename ... Args> -void BaseLogger::log_info(const char * const format, Args ... args) { - if (logger_ == NULL || !logger_->should_log(spdlog::level::level_enum::info)) - return; - - log_str(info, format_string(format, conditional_conversion(args)...)); -} -/** - * @brief Log debug message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ -template<typename ... Args> -void BaseLogger::log_debug(const char * const format, Args ... args) { - if (logger_ == NULL || !logger_->should_log(spdlog::level::level_enum::debug)) - return; - - log_str(debug, format_string(format, conditional_conversion(args)...)); -} -/** - * @brief Log trace message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ -template<typename ... Args> -void BaseLogger::log_trace(const char * const format, Args ... args) { - if (logger_ == NULL || !logger_->should_log(spdlog::level::level_enum::trace)) - return; - - log_str(debug, format_string(format, conditional_conversion(args)...)); -} - -} /* namespace logging */ -} /* namespace core */ -} /* namespace minifi */ -} /* namespace nifi */ -} /* namespace apache */ -} /* namespace org */ -#endif /* LIBMINIFI_INCLUDE_BASELOGGER_H_ */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/logging/LogAppenders.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/logging/LogAppenders.h b/libminifi/include/core/logging/LogAppenders.h deleted file mode 100644 index cf11238..0000000 --- a/libminifi/include/core/logging/LogAppenders.h +++ /dev/null @@ -1,301 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef LIBMINIFI_INCLUDE_LOGAPPENDERS_H_ -#define LIBMINIFI_INCLUDE_LOGAPPENDERS_H_ - -#include "BaseLogger.h" -#include "spdlog/sinks/null_sink.h" -#include "spdlog/sinks/ostream_sink.h" -#include <cxxabi.h> -#include "properties/Configure.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { -namespace logging { - -template<typename T> -static std::string getUniqueName() { - std::string name = LOG_NAME; - name += " -- "; - name += abi::__cxa_demangle(typeid(T).name(), 0, 0, 0); - spdlog::drop(name); - return name; -} - -/** - * Null appender sets a null sink, thereby performing no logging. - */ -class NullAppender : public BaseLogger { - public: - /** - * Base constructor that creates the null sink. - */ - explicit NullAppender() - : BaseLogger("off") { - auto null_sink = std::make_shared<spdlog::sinks::null_sink_st>(); - std::string unique_name = getUniqueName<NullAppender>(); - logger_ = std::make_shared<spdlog::logger>(unique_name, null_sink); - configured_level_ = off; - setLogLevel(); - } - - /** - * Move constructor for the null appender. - */ - explicit NullAppender(const NullAppender &&other) - : BaseLogger(std::move(other)) { - - } - -}; - -/** - * Basic output stream configuration that uses a supplied ostream - * - * Design : extends LoggerConfiguration using the logger and log level - * encapsulated within the base configuration class. - */ -class OutputStreamAppender : public BaseLogger { - - public: - - static const char *nifi_log_output_stream_error_stderr; - - /** - * Output stream move constructor. - */ - explicit OutputStreamAppender(const OutputStreamAppender &&other) - : BaseLogger(std::move(other)) { - - } - - /** - * Base constructor. Creates a ostream sink. - * @param stream incoming stream reference. - * @param config configuration. - */ - explicit OutputStreamAppender(const std::shared_ptr<Configure> &config) - : BaseLogger("info") { - auto ostream_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>( - std::cout); - - std::string unique_name = getUniqueName<OutputStreamAppender>(); - logger_ = std::make_shared<spdlog::logger>(unique_name, ostream_sink); - - std::string use_std_err; - - if (NULL != config - && config->get(nifi_log_output_stream_error_stderr, use_std_err)) { - - std::transform(use_std_err.begin(), use_std_err.end(), - use_std_err.begin(), ::tolower); - - if (use_std_err == "true") { - std::string err_unique_name = getUniqueName<OutputStreamAppender>(); - auto error_ostream_sink = std::make_shared< - spdlog::sinks::ostream_sink_mt>(std::cerr); - stderr_ = std::make_shared<spdlog::logger>(err_unique_name, - error_ostream_sink); - } - } else { - stderr_ = nullptr; - } - - std::string log_level; - if (NULL != config && config->get(BaseLogger::nifi_log_level, log_level)) { - setLogLevel(log_level); - } else { - setLogLevel("info"); - } - - } - - /** - * Base constructor. Creates a ostream sink. - * @param stream incoming stream reference. - * @param config configuration. - */ - OutputStreamAppender(std::ostream &stream, const std::shared_ptr<Configure> &config) - : BaseLogger("info") { - auto ostream_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>( - stream); - std::string unique_name = getUniqueName<OutputStreamAppender>(); - logger_ = std::make_shared<spdlog::logger>(unique_name, ostream_sink); - - stderr_ = nullptr; - - std::string log_level; - if (NULL != config && config->get(BaseLogger::nifi_log_level, log_level)) { - setLogLevel(log_level); - } else { - setLogLevel("info"); - } - - } - - protected: - -}; - -/** - * Rolling configuration - * Design : extends LoggerConfiguration using the logger and log level - * encapsulated within the base configuration class. - */ -class RollingAppender : public BaseLogger { - public: - static const char *nifi_log_rolling_apender_file; - static const char *nifi_log_rolling_appender_max_files; - static const char *nifi_log_rolling_appender_max_file_size; - - /** - * RollingAppenderConfiguration move constructor. - */ - explicit RollingAppender(const RollingAppender&& other) - : BaseLogger(std::move(other)), - max_files_(std::move(other.max_files_)), - file_name_(std::move(other.file_name_)), - max_file_size_(std::move(other.max_file_size_)) { - } - /** - * Base Constructor. - * @param config pointer to the configuration for this instance. - */ - explicit RollingAppender(const std::shared_ptr<Configure> &config = 0) - : BaseLogger("info") { - std::string file_name = ""; - if (NULL != config - && config->get(nifi_log_rolling_apender_file, file_name)) { - file_name_ = file_name; - } else { - file_name_ = LOG_FILE_NAME; - } - - std::string max_files = ""; - if (NULL != config - && config->get(nifi_log_rolling_appender_max_files, max_files)) { - try { - max_files_ = std::stoi(max_files); - } catch (const std::invalid_argument &ia) { - max_files_ = DEFAULT_LOG_FILE_NUMBER; - } catch (const std::out_of_range &oor) { - max_files_ = DEFAULT_LOG_FILE_NUMBER; - } - } else { - max_files_ = DEFAULT_LOG_FILE_NUMBER; - } - - std::string max_file_size = ""; - if (NULL != config - && config->get(nifi_log_rolling_appender_max_file_size, - max_file_size)) { - try { - max_file_size_ = std::stoi(max_file_size); - } catch (const std::invalid_argument &ia) { - max_file_size_ = DEFAULT_LOG_FILE_SIZE; - } catch (const std::out_of_range &oor) { - max_file_size_ = DEFAULT_LOG_FILE_SIZE; - } - } else { - max_file_size_ = DEFAULT_LOG_FILE_SIZE; - } - - std::string unique_name = getUniqueName<OutputStreamAppender>(); - logger_ = spdlog::rotating_logger_mt(unique_name, file_name_, - max_file_size_, max_files_); - - std::string log_level; - if (NULL != config && config->get(BaseLogger::nifi_log_level, log_level)) { - setLogLevel(log_level); - } - } - - /** - * To maintain current functionality we will flush on write. - */ - void log_str(LOG_LEVEL_E level, const std::string &buffer) { - BaseLogger::log_str(level, buffer); - logger_->flush(); - } - - protected: - - /** - * file name. - */ - std::string file_name_; - /** - * maximum number of files to keep in the rotation. - */ - size_t max_files_; - /** - * Maximum file size per rotated file. - */ - size_t max_file_size_; - -}; - -class LogInstance { - public: - /** - * Returns a logger configuration based on - * the configuration within this instance. - * @param config configuration for this instance. - */ - static std::unique_ptr<BaseLogger> getConfiguredLogger(const std::shared_ptr<Configure> &config) { - std::string appender = ""; - - if (config->get(BaseLogger::nifi_log_appender, appender)) { - std::transform(appender.begin(), appender.end(), appender.begin(), - ::tolower); - - if ("nullappender" == appender || "null appender" == appender - || "null" == appender) { - - return std::move(std::unique_ptr<BaseLogger>(new NullAppender())); - - } else if ("rollingappender" == appender || "rolling appender" == appender - || "rolling" == appender) { - - return std::move( - std::unique_ptr<BaseLogger>(new RollingAppender(config))); - - } else if ("outputstream" == appender - || "outputstreamappender" == appender - || "outputstream appender" == appender) { - - return std::move( - std::unique_ptr<BaseLogger>(new OutputStreamAppender(config))); - - } - } - return nullptr; - - } -}; - -} /* namespace logging */ -} /* namespace core */ -} /* namespace minifi */ -} /* namespace nifi */ -} /* namespace apache */ -} /* namespace org */ -#endif /* LIBMINIFI_INCLUDE_LOGAPPENDERS_H_ */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/logging/Logger.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/logging/Logger.h b/libminifi/include/core/logging/Logger.h index 995c96f..6b71763 100644 --- a/libminifi/include/core/logging/Logger.h +++ b/libminifi/include/core/logging/Logger.h @@ -21,15 +21,9 @@ #ifndef __LOGGER_H__ #define __LOGGER_H__ -#include <string> -#include <atomic> +#include <mutex> #include <memory> -#include <utility> -#include <algorithm> -#include <cstdio> -#include <iostream> -#include "BaseLogger.h" #include "spdlog/spdlog.h" namespace org { @@ -39,179 +33,98 @@ namespace minifi { namespace core { namespace logging { -/** - * Logger class - * Design: Extends BaseLogger, leaving this class to be the facade to the underlying - * logging mechanism. Is a facade to BaseLogger's underlying log stream. This allows - * the underlying implementation to be replaced real time. - */ -class Logger : public BaseLogger { - protected: - struct singleton; - public: +#define LOG_BUFFER_SIZE 1024 - /** - * Returns a shared pointer to the logger instance. - * Note that while there is no synchronization this is expected - * to be called and initialized first - * @returns shared pointer to the base logger. - */ - static std::shared_ptr<Logger> getLogger() { +template<typename ... Args> +inline std::string format_string(char const* format_str, Args&&... args) { + char buf[LOG_BUFFER_SIZE]; + std::snprintf(buf, LOG_BUFFER_SIZE, format_str, args...); + return std::string(buf); +} - if (singleton_logger_ == nullptr) - singleton_logger_ = std::make_shared<Logger>(singleton { 0 }); - return singleton_logger_; - } +inline std::string format_string(char const* format_str) { + return format_str; +} - /** - * Returns the log level for this instance. - */ - LOG_LEVEL_E getLogLevel() const { - return current_logger_.load()->getLogLevel(); - } +inline char const* conditional_conversion(std::string const& str) { + return str.c_str(); +} - /** - * Sets the log level atomic and sets it - * within logger if it can - * @param level desired log level. - */ - void setLogLevel(LOG_LEVEL_E level) { - current_logger_.load()->setLogLevel(level); - } - - /** - * Sets the log level for this instance based on the string - * @param level desired log leve. - * @param defaultLevel default level if we cannot match level. - */ - void setLogLevel(const std::string &level, LOG_LEVEL_E defaultLevel = info) { - current_logger_.load()->setLogLevel(level, info); - } - - void updateLogger(std::unique_ptr<BaseLogger> logger) { - - if (logger == nullptr) - return; - current_logger_.store(logger.release()); - } +template<typename T> +inline T conditional_conversion(T const& t) { + return t; +} +class Logger { + public: /** * @brief Log error message * @param format format string ('man printf' for syntax) * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match */ template<typename ... Args> - void log_error(const char * const format, Args ... args) { - if (!current_logger_.load()->shouldLog(err)) - return; - - current_logger_.load()->log_str( - err, format_string(format, conditional_conversion(args)...)); + void log_error(const char * const format, const Args& ... args) { + log(spdlog::level::err, format, args...); } + /** * @brief Log warn message * @param format format string ('man printf' for syntax) * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match */ template<typename ... Args> - void log_warn(const char * const format, Args ... args) { - if (!current_logger_.load()->shouldLog(warn)) - return; - - current_logger_.load()->log_str( - warn, format_string(format, conditional_conversion(args)...)); + void log_warn(const char * const format, const Args& ... args) { + log(spdlog::level::warn, format, args...); } + /** * @brief Log info message * @param format format string ('man printf' for syntax) * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match */ template<typename ... Args> - void log_info(const char * const format, Args ... args) { - if (!current_logger_.load()->shouldLog(info)) - return; - - current_logger_.load()->log_str( - info, format_string(format, conditional_conversion(args)...)); + void log_info(const char * const format, const Args& ... args) { + log(spdlog::level::info, format, args...); } + /** * @brief Log debug message * @param format format string ('man printf' for syntax) * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match */ template<typename ... Args> - void log_debug(const char * const format, Args ... args) { - - if (!current_logger_.load()->shouldLog(debug)) - return; - - current_logger_.load()->log_str( - debug, format_string(format, conditional_conversion(args)...)); + void log_debug(const char * const format, const Args& ... args) { + log(spdlog::level::debug, format, args...); } + /** * @brief Log trace message * @param format format string ('man printf' for syntax) * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match */ template<typename ... Args> - void log_trace(const char * const format, Args ... args) { - - if (!current_logger_.load()->shouldLog(trace)) - return; - - current_logger_.load()->log_str( - trace, format_string(format, conditional_conversion(args)...)); - } - - /** - * @brief Log message - * @param format format string ('man printf' for syntax) - * @warning does not check @p log or @p format for null. Caller must ensure parameters and format string lengths match - */ - virtual void log_str(LOG_LEVEL_E level, const std::string &buffer) { - current_logger_.load()->log_str(level, buffer); - } - - // Destructor - ~Logger() { - } - - explicit Logger(const singleton &a) { - - /** - * flush on info to maintain current functionality - */ - std::shared_ptr<spdlog::logger> defaultsink = spdlog::rotating_logger_mt( - LOG_NAME, - LOG_FILE_NAME, - DEFAULT_LOG_FILE_SIZE, DEFAULT_LOG_FILE_NUMBER); - defaultsink->flush_on(spdlog::level::level_enum::info); - - std::unique_ptr<BaseLogger> new_logger_ = std::unique_ptr<BaseLogger>( - new BaseLogger("info", defaultsink)); - - new_logger_->setLogLevel(info); - current_logger_.store(new_logger_.release()); + void log_trace(const char * const format, const Args& ... args) { + log(spdlog::level::trace, format, args...); } - - Logger(const Logger &parent) = delete; - Logger &operator=(const Logger &parent) = delete; - + protected: + Logger(std::shared_ptr<spdlog::logger> delegate) : delegate_(delegate) {} + + std::shared_ptr<spdlog::logger> delegate_; - /** - * Allows for a null constructor above so that we can have a public constructor that - * effectively limits us to being a singleton by having a protected argument in the constructor - */ - struct singleton { - explicit singleton(int) { - } - }; - - std::atomic<BaseLogger*> current_logger_; - -// Singleton logger instance - static std::shared_ptr<Logger> singleton_logger_; + std::mutex mutex_; + private: + template<typename ... Args> + inline void log(spdlog::level::level_enum level, const char * const format, const Args& ... args) { + std::lock_guard<std::mutex> lock(mutex_); + if (!delegate_->should_log(level)) { + return; + } + delegate_->log(level, format_string(format, conditional_conversion(args)...)); + } + + Logger(Logger const&); + Logger& operator=(Logger const&); }; } /* namespace logging */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/logging/LoggerConfiguration.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/logging/LoggerConfiguration.h b/libminifi/include/core/logging/LoggerConfiguration.h new file mode 100644 index 0000000..53f1403 --- /dev/null +++ b/libminifi/include/core/logging/LoggerConfiguration.h @@ -0,0 +1,140 @@ +/** + * @file LoggerConfiguration.h + * Logger class declaration + * This is a C++ wrapper for spdlog, a lightweight C++ logging library + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __LOGGER_CONFIGURATION_H__ +#define __LOGGER_CONFIGURATION_H__ + +#include <map> +#include <mutex> +#include <string> +#include "core/logging/Logger.h" +#include "properties/Properties.h" + +#include "spdlog/spdlog.h" +#include "spdlog/formatter.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace core { +namespace logging { + +namespace internal { + struct LoggerNamespace { + spdlog::level::level_enum level; + bool has_level; + std::vector<std::shared_ptr<spdlog::sinks::sink>> sinks; + std::map<std::string, std::shared_ptr<LoggerNamespace>> children; + + LoggerNamespace() : level(spdlog::level::off), has_level(false), sinks(std::vector<std::shared_ptr<spdlog::sinks::sink>>()), children(std::map<std::string, std::shared_ptr<LoggerNamespace>>()) {} + }; +}; + +class LoggerProperties : public Properties { + public: + /** + * Gets all keys that start with the given prefix and do not have a "." after the prefix and "." separator. + * + * Ex: with type argument "appender" + * you would get back a property of "appender.rolling" but not "appender.rolling.file_name" + */ + std::vector<std::string> get_keys_of_type(const std::string &type); + + /** + * Registers a sink witht the given name. This allows for programmatic definition of sinks. + */ + void add_sink(const std::string &name, std::shared_ptr<spdlog::sinks::sink> sink) { + sinks_[name] = sink; + } + std::map<std::string, std::shared_ptr<spdlog::sinks::sink>> initial_sinks() { + return sinks_; + } + + static const char* appender_prefix; + static const char* logger_prefix; + private: + std::map<std::string, std::shared_ptr<spdlog::sinks::sink>> sinks_; +}; + +class LoggerConfiguration { + public: + /** + * Gets the current log configuration + */ + static LoggerConfiguration& getConfiguration() { + static LoggerConfiguration logger_configuration; + return logger_configuration; + } + + /** + * (Re)initializes the logging configuation with the given logger properties. + */ + void initialize(const std::shared_ptr<LoggerProperties> &logger_properties); + + /** + * Can be used to get arbitrarily named Logger, LoggerFactory should be preferred within a class. + */ + std::shared_ptr<Logger> getLogger(const std::string &name); + static const char *spdlog_default_pattern; + protected: + static std::shared_ptr<internal::LoggerNamespace> initialize_namespaces(const std::shared_ptr<LoggerProperties> &logger_properties); + static std::shared_ptr<spdlog::logger> get_logger(std::shared_ptr<Logger> logger, const std::shared_ptr<internal::LoggerNamespace> &root_namespace, const std::string &name, std::shared_ptr<spdlog::formatter> formatter, bool remove_if_present = false); + private: + static std::shared_ptr<internal::LoggerNamespace> create_default_root(); + + class LoggerImpl : public Logger { + public: + LoggerImpl(std::string name, std::shared_ptr<spdlog::logger> delegate):Logger(delegate), name(name) {} + void set_delegate(std::shared_ptr<spdlog::logger> delegate) { + std::lock_guard<std::mutex> lock(mutex_); + delegate_ = delegate; + } + const std::string name; + }; + + LoggerConfiguration(); + std::shared_ptr<internal::LoggerNamespace> root_namespace_; + std::vector<std::shared_ptr<LoggerImpl>> loggers; + std::shared_ptr<spdlog::formatter> formatter_; + std::mutex mutex; + std::shared_ptr<LoggerImpl> logger_ = nullptr; +}; + +template<typename T> +class LoggerFactory { + public: + /** + * Gets an initialized logger for the template class. + */ + static std::shared_ptr<Logger> getLogger() { + static std::shared_ptr<Logger> logger = LoggerConfiguration::getConfiguration().getLogger(core::getClassName<T>()); + return logger; + } +}; + +} /* namespace logging */ +} /* namespace core */ +} /* namespace minifi */ +} /* namespace nifi */ +} /* namespace apache */ +} /* namespace org */ + +#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/reporting/SiteToSiteProvenanceReportingTask.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/reporting/SiteToSiteProvenanceReportingTask.h b/libminifi/include/core/reporting/SiteToSiteProvenanceReportingTask.h index f69690c..b191499 100644 --- a/libminifi/include/core/reporting/SiteToSiteProvenanceReportingTask.h +++ b/libminifi/include/core/reporting/SiteToSiteProvenanceReportingTask.h @@ -29,6 +29,7 @@ #include "RemoteProcessorGroupPort.h" #include "Site2SiteClientProtocol.h" #include "io/StreamFactory.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -47,8 +48,8 @@ class SiteToSiteProvenanceReportingTask : */ SiteToSiteProvenanceReportingTask( const std::shared_ptr<io::StreamFactory> &stream_factory) - : minifi::RemoteProcessorGroupPort(stream_factory, ReportTaskName) { - logger_ = logging::Logger::getLogger(); + : minifi::RemoteProcessorGroupPort(stream_factory, ReportTaskName), + logger_(logging::LoggerFactory<SiteToSiteProvenanceReportingTask>::getLogger()) { this->setTriggerWhenEmpty(true); port_ = 0; batch_size_ = 100; @@ -112,7 +113,7 @@ class SiteToSiteProvenanceReportingTask : private: int batch_size_; - //! Logger + std::shared_ptr<logging::Logger> logger_; }; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/repository/FlowFileRepository.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/repository/FlowFileRepository.h b/libminifi/include/core/repository/FlowFileRepository.h index 051dfb0..330a3d0 100644 --- a/libminifi/include/core/repository/FlowFileRepository.h +++ b/libminifi/include/core/repository/FlowFileRepository.h @@ -25,6 +25,7 @@ #include "core/Repository.h" #include "core/Core.h" #include "Connection.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -50,7 +51,8 @@ class FlowFileRepository : public core::Repository, FlowFileRepository(const std::string repo_name = "", std::string directory=FLOWFILE_REPOSITORY_DIRECTORY, int64_t maxPartitionMillis=MAX_FLOWFILE_REPOSITORY_ENTRY_LIFE_TIME, int64_t maxPartitionBytes=MAX_FLOWFILE_REPOSITORY_STORAGE_SIZE, uint64_t purgePeriod=FLOWFILE_REPOSITORY_PURGE_PERIOD) : Repository(repo_name.length() > 0 ? repo_name : core::getClassName<FlowFileRepository>(), directory, - maxPartitionMillis, maxPartitionBytes, purgePeriod) + maxPartitionMillis, maxPartitionBytes, purgePeriod), + logger_(logging::LoggerFactory<FlowFileRepository>::getLogger()) { db_ = NULL; @@ -163,6 +165,7 @@ class FlowFileRepository : public core::Repository, private: std::map<std::string, std::shared_ptr<minifi::Connection>> connectionMap; leveldb::DB* db_; + std::shared_ptr<logging::Logger> logger_; }; } /* namespace repository */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/repository/VolatileRepository.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/repository/VolatileRepository.h b/libminifi/include/core/repository/VolatileRepository.h index 1e07e28..37c1a0c 100644 --- a/libminifi/include/core/repository/VolatileRepository.h +++ b/libminifi/include/core/repository/VolatileRepository.h @@ -192,7 +192,8 @@ class VolatileRepository : public core::Repository, "", maxPartitionMillis, maxPartitionBytes, purgePeriod), max_size_(maxPartitionBytes * 0.75), current_index_(0), - max_count_(10000) + max_count_(10000), + logger_(logging::LoggerFactory<VolatileRepository>::getLogger()) { @@ -358,7 +359,7 @@ class VolatileRepository : public core::Repository, std::vector<AtomicEntry*> value_vector_; uint32_t max_count_; uint32_t max_size_; - + std::shared_ptr<logging::Logger> logger_; } ; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/core/yaml/YamlConfiguration.h ---------------------------------------------------------------------- diff --git a/libminifi/include/core/yaml/YamlConfiguration.h b/libminifi/include/core/yaml/YamlConfiguration.h index 8d6239c..a63412c 100644 --- a/libminifi/include/core/yaml/YamlConfiguration.h +++ b/libminifi/include/core/yaml/YamlConfiguration.h @@ -26,6 +26,7 @@ #include <string> #include "io/validation.h" #include "io/StreamFactory.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -50,7 +51,8 @@ class YamlConfiguration : public FlowConfiguration { std::shared_ptr<Configure> configuration, const std::string path = DEFAULT_FLOW_YAML_FILE_NAME) : FlowConfiguration(repo, flow_file_repo, stream_factory, configuration, - path) { + path), + logger_(logging::LoggerFactory<YamlConfiguration>::getLogger()) { stream_factory_ = stream_factory; if (IsNullOrEmpty(config_path_)) { config_path_ = DEFAULT_FLOW_YAML_FILE_NAME; @@ -275,6 +277,8 @@ class YamlConfiguration : public FlowConfiguration { protected: std::shared_ptr<io::StreamFactory> stream_factory_; + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace core */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/io/ClientSocket.h ---------------------------------------------------------------------- diff --git a/libminifi/include/io/ClientSocket.h b/libminifi/include/io/ClientSocket.h index 124055d..ea2312f 100644 --- a/libminifi/include/io/ClientSocket.h +++ b/libminifi/include/io/ClientSocket.h @@ -80,21 +80,12 @@ class Socket : public BaseStream { */ explicit Socket(const Socket &&); - static char *HOSTNAME; - /** * Static function to return the current machine's host name */ - static std::string getMyHostName(const char *str = HOSTNAME) { - if (__builtin_expect(!IsNullOrEmpty(str), 0)) - return str; - else { - char hostname[1024]; - gethostname(hostname, 1024); - Socket mySock(nullptr, hostname, 0); - mySock.initialize(); - return mySock.getHostname(); - } + static std::string getMyHostName() { + static char *HOSTNAME = init_hostname(); + return HOSTNAME; } /** @@ -236,8 +227,6 @@ class Socket : public BaseStream { */ virtual int16_t select_descriptor(const uint16_t msec); - std::shared_ptr<logging::Logger> logger_; - addrinfo *addr_info_; std::recursive_mutex selection_mutex_; @@ -254,6 +243,15 @@ class Socket : public BaseStream { std::atomic<uint16_t> socket_max_; uint16_t listeners_; + private: + std::shared_ptr<logging::Logger> logger_; + static char* init_hostname() { + char hostname[1024]; + gethostname(hostname, 1024); + Socket mySock(nullptr, hostname, 0); + mySock.initialize(); + return const_cast<char*>(mySock.getHostname().c_str()); + } }; } /* namespace io */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/io/tls/TLSSocket.h ---------------------------------------------------------------------- diff --git a/libminifi/include/io/tls/TLSSocket.h b/libminifi/include/io/tls/TLSSocket.h index 1185045..c56f6c8 100644 --- a/libminifi/include/io/tls/TLSSocket.h +++ b/libminifi/include/io/tls/TLSSocket.h @@ -191,6 +191,8 @@ class TLSSocket : public Socket { std::shared_ptr<TLSContext> context_; SSL* ssl; + private: + std::shared_ptr<logging::Logger> logger_; }; } /* namespace io */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/AppendHostInfo.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/AppendHostInfo.h b/libminifi/include/processors/AppendHostInfo.h index d33c717..610251f 100644 --- a/libminifi/include/processors/AppendHostInfo.h +++ b/libminifi/include/processors/AppendHostInfo.h @@ -26,6 +26,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -41,8 +42,8 @@ class AppendHostInfo : public core::Processor { * Create a new processor */ AppendHostInfo(std::string name, uuid_t uuid = NULL) - : core::Processor(name, uuid) { - logger_ = logging::Logger::getLogger(); + : core::Processor(name, uuid), + logger_(logging::LoggerFactory<AppendHostInfo>::getLogger()){ } // Destructor virtual ~AppendHostInfo() { http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/ExecuteProcess.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/ExecuteProcess.h b/libminifi/include/processors/ExecuteProcess.h index dbf2d15..c719405 100644 --- a/libminifi/include/processors/ExecuteProcess.h +++ b/libminifi/include/processors/ExecuteProcess.h @@ -36,6 +36,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -51,8 +52,8 @@ class ExecuteProcess : public core::Processor { * Create a new processor */ ExecuteProcess(std::string name, uuid_t uuid = NULL) - : Processor(name, uuid) { - logger_ = logging::Logger::getLogger(); + : Processor(name, uuid), + logger_(logging::LoggerFactory<ExecuteProcess>::getLogger()){ _redirectErrorStream = false; _batchDuration = 0; _workingDir = "."; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/GetFile.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/GetFile.h b/libminifi/include/processors/GetFile.h index e25e7db..8864601 100644 --- a/libminifi/include/processors/GetFile.h +++ b/libminifi/include/processors/GetFile.h @@ -24,6 +24,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -53,7 +54,7 @@ class GetFile : public core::Processor { * Create a new processor */ explicit GetFile(std::string name, uuid_t uuid = NULL) - : Processor(name, uuid) { + : Processor(name, uuid), logger_(logging::LoggerFactory<GetFile>::getLogger()) { } // Destructor @@ -133,6 +134,7 @@ class GetFile : public core::Processor { // as the top level time. std::atomic<uint64_t> last_listing_time_; + std::shared_ptr<logging::Logger> logger_; }; REGISTER_RESOURCE(GetFile); http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/InvokeHTTP.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/InvokeHTTP.h b/libminifi/include/processors/InvokeHTTP.h index ca4fef6..59bc2bd 100644 --- a/libminifi/include/processors/InvokeHTTP.h +++ b/libminifi/include/processors/InvokeHTTP.h @@ -31,6 +31,7 @@ #include "core/Resource.h" #include "controllers/SSLContextService.h" #include "utils/ByteInputCallBack.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -112,7 +113,8 @@ class InvokeHTTP : public core::Processor { penalize_no_retry_(false), read_timeout_(20000), always_output_response_(false), - ssl_context_service_(nullptr) { + ssl_context_service_(nullptr), + logger_(logging::LoggerFactory<InvokeHTTP>::getLogger()) { curl_global_init(CURL_GLOBAL_DEFAULT); } // Destructor @@ -241,6 +243,9 @@ class InvokeHTTP : public core::Processor { bool always_output_response_; // penalize on no retry bool penalize_no_retry_; + + private: + std::shared_ptr<logging::Logger> logger_; }; REGISTER_RESOURCE(InvokeHTTP) http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/ListenHTTP.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/ListenHTTP.h b/libminifi/include/processors/ListenHTTP.h index 586a699..03fe03d 100644 --- a/libminifi/include/processors/ListenHTTP.h +++ b/libminifi/include/processors/ListenHTTP.h @@ -30,6 +30,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -46,8 +47,8 @@ class ListenHTTP : public core::Processor { * Create a new processor */ ListenHTTP(std::string name, uuid_t uuid = NULL) - : Processor(name, uuid) { - _logger = logging::Logger::getLogger(); + : Processor(name, uuid), + logger_(logging::LoggerFactory<ListenHTTP>::getLogger()) { } // Destructor virtual ~ListenHTTP(); @@ -83,7 +84,7 @@ class ListenHTTP : public core::Processor { // Send HTTP 500 error response to client void sendErrorResponse(struct mg_connection *conn); // Logger - std::shared_ptr<logging::Logger> _logger; + std::shared_ptr<logging::Logger> logger_; std::regex _authDNRegex; std::regex _headersAsAttributesRegex; @@ -100,7 +101,7 @@ class ListenHTTP : public core::Processor { private: // Logger - std::shared_ptr<logging::Logger> _logger; + std::shared_ptr<logging::Logger> logger_; struct mg_connection *_conn; const struct mg_request_info *_reqInfo; @@ -108,7 +109,7 @@ class ListenHTTP : public core::Processor { private: // Logger - std::shared_ptr<logging::Logger> _logger; + std::shared_ptr<logging::Logger> logger_; std::unique_ptr<CivetServer> _server; std::unique_ptr<Handler> _handler; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/ListenSyslog.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/ListenSyslog.h b/libminifi/include/processors/ListenSyslog.h index 4e642e8..f0380db 100644 --- a/libminifi/include/processors/ListenSyslog.h +++ b/libminifi/include/processors/ListenSyslog.h @@ -37,6 +37,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -58,8 +59,8 @@ class ListenSyslog : public core::Processor { * Create a new processor */ ListenSyslog(std::string name, uuid_t uuid = NULL) - : Processor(name, uuid) { - logger_ = logging::Logger::getLogger(); + : Processor(name, uuid), + logger_(logging::LoggerFactory<ListenSyslog>::getLogger()) { _eventQueueByteSize = 0; _serverSocket = 0; _recvBufSize = 65507; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/LogAttribute.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/LogAttribute.h b/libminifi/include/processors/LogAttribute.h index 56864c7..cbb8f1a 100644 --- a/libminifi/include/processors/LogAttribute.h +++ b/libminifi/include/processors/LogAttribute.h @@ -25,6 +25,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -40,8 +41,8 @@ class LogAttribute : public core::Processor { * Create a new processor */ LogAttribute(std::string name, uuid_t uuid = NULL) - : Processor(name, uuid) { - logger_ = logging::Logger::getLogger(); + : Processor(name, uuid), + logger_(logging::LoggerFactory<LogAttribute>::getLogger()) { } // Destructor virtual ~LogAttribute() { http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/PutFile.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/PutFile.h b/libminifi/include/processors/PutFile.h index a51f6b5..3918d0a 100644 --- a/libminifi/include/processors/PutFile.h +++ b/libminifi/include/processors/PutFile.h @@ -25,6 +25,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -47,7 +48,7 @@ class PutFile : public core::Processor { * Create a new processor */ PutFile(std::string name, uuid_t uuid = NULL) - : core::Processor(name, uuid) { + : core::Processor(name, uuid), logger_(logging::LoggerFactory<PutFile>::getLogger()) { } // Destructor virtual ~PutFile() { @@ -102,6 +103,7 @@ class PutFile : public core::Processor { bool putFile(core::ProcessSession *session, std::shared_ptr<FlowFileRecord> flowFile, const std::string &tmpFile, const std::string &destFile); + std::shared_ptr<logging::Logger> logger_; }; REGISTER_RESOURCE(PutFile); http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/processors/TailFile.h ---------------------------------------------------------------------- diff --git a/libminifi/include/processors/TailFile.h b/libminifi/include/processors/TailFile.h index ac7db5a..47ec3fb 100644 --- a/libminifi/include/processors/TailFile.h +++ b/libminifi/include/processors/TailFile.h @@ -25,6 +25,7 @@ #include "core/ProcessSession.h" #include "core/Core.h" #include "core/Resource.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -40,7 +41,7 @@ class TailFile : public core::Processor { * Create a new processor */ explicit TailFile(std::string name, uuid_t uuid = NULL) - : core::Processor(name, uuid) { + : core::Processor(name, uuid), logger_(logging::LoggerFactory<TailFile>::getLogger()) { _stateRecovered = false; } // Destructor @@ -88,7 +89,7 @@ class TailFile : public core::Processor { * Check roll over for the provided file. */ void checkRollOver(const std::string &, const std::string&); - + std::shared_ptr<logging::Logger> logger_; }; REGISTER_RESOURCE(TailFile); http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/properties/Configure.h ---------------------------------------------------------------------- diff --git a/libminifi/include/properties/Configure.h b/libminifi/include/properties/Configure.h index 2d5f293..58f6679 100644 --- a/libminifi/include/properties/Configure.h +++ b/libminifi/include/properties/Configure.h @@ -20,23 +20,14 @@ #ifndef __CONFIGURE_H__ #define __CONFIGURE_H__ -#include <stdio.h> -#include <string> -#include <map> -#include <stdlib.h> -#include <errno.h> -#include <iostream> -#include <fstream> -#include "core/Core.h" -#include "utils/StringUtils.h" -#include "core/logging/Logger.h" +#include "properties/Properties.h" namespace org { namespace apache { namespace nifi { namespace minifi { -class Configure { +class Configure : public Properties { public: // nifi.flow.configuration.file static const char *nifi_default_directory; @@ -67,64 +58,6 @@ class Configure { static const char *nifi_security_client_private_key; static const char *nifi_security_client_pass_phrase; static const char *nifi_security_client_ca_certificate; - - Configure() { - logger_ = logging::Logger::getLogger(); - } - - virtual ~Configure() { - - } - - // Clear the load config - void clear() { - std::lock_guard<std::mutex> lock(mutex_); - properties_.clear(); - } - // Set the config value - void set(std::string key, std::string value) { - std::lock_guard<std::mutex> lock(mutex_); - properties_[key] = std::string(value.c_str()); - } - // Check whether the config value existed - bool has(std::string key) { - std::lock_guard<std::mutex> lock(mutex_); - return (properties_.find(key) != properties_.end()); - } - // Get the config value - bool get(std::string key, std::string &value); - - /** - * Returns the configuration value or an empty string. - * @return value corresponding to key or empty value. - */ - int getInt(const std::string &key, int default_value); - // Parse one line in configure file like key=value - void parseConfigureFileLine(char *buf); - // Load Configure File - void loadConfigureFile(const char *fileName); - // Set the determined MINIFI_HOME - void setHome(std::string minifiHome) { - minifi_home_ = minifiHome; - } - - // Get the determined MINIFI_HOME - std::string getHome() { - return minifi_home_; - } - // Parse Command Line - void parseCommandLine(int argc, char **argv); - - private: - // Mutex for protection - std::mutex mutex_; - // Logger - std::shared_ptr<logging::Logger> logger_; - // Home location for this executable - std::string minifi_home_; - - protected: - std::map<std::string, std::string> properties_; }; } /* namespace minifi */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/properties/Properties.h ---------------------------------------------------------------------- diff --git a/libminifi/include/properties/Properties.h b/libminifi/include/properties/Properties.h new file mode 100644 index 0000000..8d08e8d --- /dev/null +++ b/libminifi/include/properties/Properties.h @@ -0,0 +1,102 @@ +/** + * @file Configure.h + * Configure class declaration + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PROPERTIES_H__ +#define __PROPERTIES_H__ + +#include <stdio.h> +#include <string> +#include <map> +#include <stdlib.h> +#include <errno.h> +#include <iostream> +#include <fstream> +#include "core/Core.h" +#include "core/logging/Logger.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { + +class Properties { + public: + Properties(); + + virtual ~Properties() { + + } + + // Clear the load config + void clear() { + std::lock_guard<std::mutex> lock(mutex_); + properties_.clear(); + } + // Set the config value + void set(std::string key, std::string value) { + std::lock_guard<std::mutex> lock(mutex_); + properties_[key] = value; + } + // Check whether the config value existed + bool has(std::string key) { + std::lock_guard<std::mutex> lock(mutex_); + return (properties_.find(key) != properties_.end()); + } + // Get the config value + bool get(std::string key, std::string &value); + + /** + * Returns the configuration value or an empty string. + * @return value corresponding to key or empty value. + */ + int getInt(const std::string &key, int default_value); + + // Parse one line in configure file like key=value + void parseConfigureFileLine(char *buf); + // Load Configure File + void loadConfigureFile(const char *fileName); + // Set the determined MINIFI_HOME + void setHome(std::string minifiHome) { + minifi_home_ = minifiHome; + } + + // Get the determined MINIFI_HOME + std::string getHome() { + return minifi_home_; + } + // Parse Command Line + void parseCommandLine(int argc, char **argv); + + protected: + std::map<std::string, std::string> properties_; + + private: + // Mutex for protection + std::mutex mutex_; + // Logger + std::shared_ptr<logging::Logger> logger_; + // Home location for this executable + std::string minifi_home_; +}; + +} /* namespace minifi */ +} /* namespace nifi */ +} /* namespace apache */ +} /* namespace org */ +#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/provenance/Provenance.h ---------------------------------------------------------------------- diff --git a/libminifi/include/provenance/Provenance.h b/libminifi/include/provenance/Provenance.h index 2977f28..86ee713 100644 --- a/libminifi/include/provenance/Provenance.h +++ b/libminifi/include/provenance/Provenance.h @@ -35,7 +35,7 @@ #include "properties/Configure.h" #include "Connection.h" #include "FlowFileRecord.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "ResourceClaim.h" #include "io/Serializable.h" #include "utils/TimeUtil.h" @@ -162,7 +162,7 @@ class ProvenanceEventRecord : * Create a new provenance event record */ ProvenanceEventRecord(ProvenanceEventType event, std::string componentId, - std::string componentType) { + std::string componentType): logger_(logging::LoggerFactory<ProvenanceEventRecord>::getLogger()) { _eventType = event; _componentId = componentId; _componentType = componentType; @@ -172,12 +172,10 @@ class ProvenanceEventRecord : uuid_generate(_eventId); uuid_unparse_lower(_eventId, eventIdStr); _eventIdStr = eventIdStr; - logger_ = logging::Logger::getLogger(); } - ProvenanceEventRecord() { + ProvenanceEventRecord(): logger_(logging::LoggerFactory<ProvenanceEventRecord>::getLogger()) { _eventTime = getTimeMillis(); - logger_ = logging::Logger::getLogger(); } // Destructor @@ -443,8 +441,7 @@ class ProvenanceReporter { * Create a new provenance reporter associated with the process session */ ProvenanceReporter(std::shared_ptr<core::Repository> repo, - std::string componentId, std::string componentType) { - logger_ = logging::Logger::getLogger(); + std::string componentId, std::string componentType) : logger_(logging::LoggerFactory<ProvenanceReporter>::getLogger()) { _componentId = componentId; _componentType = componentType; repo_ = repo; http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/provenance/ProvenanceRepository.h ---------------------------------------------------------------------- diff --git a/libminifi/include/provenance/ProvenanceRepository.h b/libminifi/include/provenance/ProvenanceRepository.h index 9e055f9..8bcc316 100644 --- a/libminifi/include/provenance/ProvenanceRepository.h +++ b/libminifi/include/provenance/ProvenanceRepository.h @@ -24,6 +24,7 @@ #include "core/Repository.h" #include "core/Core.h" #include "provenance/Provenance.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { namespace nifi { @@ -48,7 +49,8 @@ class ProvenanceRepository : public core::Repository, int64_t maxPartitionBytes = MAX_PROVENANCE_STORAGE_SIZE, uint64_t purgePeriod = PROVENANCE_PURGE_PERIOD) : Repository(repo_name.length() > 0 ? repo_name : core::getClassName<ProvenanceRepository>(), directory, - maxPartitionMillis, maxPartitionBytes, purgePeriod) { + maxPartitionMillis, maxPartitionBytes, purgePeriod), + logger_(logging::LoggerFactory<ProvenanceRepository>::getLogger()) { db_ = NULL; } @@ -197,7 +199,7 @@ class ProvenanceRepository : public core::Repository, private: leveldb::DB* db_; - + std::shared_ptr<logging::Logger> logger_; }; } /* namespace provenance */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/include/utils/StringUtils.h ---------------------------------------------------------------------- diff --git a/libminifi/include/utils/StringUtils.h b/libminifi/include/utils/StringUtils.h index bf802e2..0fc1996 100644 --- a/libminifi/include/utils/StringUtils.h +++ b/libminifi/include/utils/StringUtils.h @@ -89,6 +89,18 @@ class StringUtils { s.end()); return s; } + + static std::vector<std::string> split(const std::string &str, const std::string &delimiter) { + std::vector<std::string> result; + int last = 0; + int next = 0; + while ((next = str.find(delimiter, last)) != std::string::npos) { + result.push_back(str.substr(last, next - last)); + last = next + delimiter.length(); + } + result.push_back(str.substr(last, next - last)); + return result; + } /** * Converts a string to a float http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/src/Configure.cpp ---------------------------------------------------------------------- diff --git a/libminifi/src/Configure.cpp b/libminifi/src/Configure.cpp index c1524a2..5c62a8d 100644 --- a/libminifi/src/Configure.cpp +++ b/libminifi/src/Configure.cpp @@ -16,10 +16,6 @@ * limitations under the License. */ #include "properties/Configure.h" -#include <cstdlib> -#include <string> -#include "utils/StringUtils.h" -#include "core/Core.h" namespace org { namespace apache { @@ -72,119 +68,6 @@ const char *Configure::nifi_security_client_pass_phrase = const char *Configure::nifi_security_client_ca_certificate = "nifi.security.client.ca.certificate"; -#define BUFFER_SIZE 512 - -// Get the config value -bool Configure::get(std::string key, std::string &value) { - std::lock_guard<std::mutex> lock(mutex_); - auto it = properties_.find(key); - - if (it != properties_.end()) { - value = it->second; - return true; - } else { - return false; - } -} - -int Configure::getInt(const std::string &key, int default_value) { - std::lock_guard<std::mutex> lock(mutex_); - auto it = properties_.find(key); - - if (it != properties_.end()) { - return std::atol(it->second.c_str()); - } else { - return default_value; - } -} - -// Parse one line in configure file like key=value -void Configure::parseConfigureFileLine(char *buf) { - char *line = buf; - - while ((line[0] == ' ') || (line[0] == '\t')) - ++line; - - char first = line[0]; - if ((first == '\0') || (first == '#') || (first == '\r') || (first == '\n') - || (first == '=')) { - return; - } - - char *equal = strchr(line, '='); - if (equal == NULL) { - return; - } - - equal[0] = '\0'; - std::string key = line; - - equal++; - while ((equal[0] == ' ') || (equal[0] == '\t')) - ++equal; - - first = equal[0]; - if ((first == '\0') || (first == '\r') || (first == '\n')) { - return; - } - - std::string value = equal; - key = org::apache::nifi::minifi::utils::StringUtils::trimRight(key); - value = org::apache::nifi::minifi::utils::StringUtils::trimRight(value); - set(key, value); -} - -// Load Configure File -void Configure::loadConfigureFile(const char *fileName) { - std::string adjustedFilename; - if (fileName) { - // perform a naive determination if this is a relative path - if (fileName[0] != '/') { - adjustedFilename = adjustedFilename + getHome() + "/" + fileName; - } else { - adjustedFilename += fileName; - } - } - char *path = NULL; - char full_path[PATH_MAX]; - path = realpath(adjustedFilename.c_str(), full_path); - logger_->log_info("Using configuration file located at %s", path); - - std::ifstream file(path, std::ifstream::in); - if (!file.good()) { - logger_->log_error("load configure file failed %s", path); - return; - } - this->clear(); - - char buf[BUFFER_SIZE]; - for (file.getline(buf, BUFFER_SIZE); file.good(); - file.getline(buf, BUFFER_SIZE)) { - parseConfigureFileLine(buf); - } -} - -// Parse Command Line -void Configure::parseCommandLine(int argc, char **argv) { - int i; - bool keyFound = false; - std::string key, value; - - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-' && argv[i][1] != '\0') { - keyFound = true; - key = &argv[i][1]; - continue; - } - if (keyFound) { - value = argv[i]; - set(key, value); - keyFound = false; - } - } - return; -} - } /* namespace minifi */ } /* namespace nifi */ } /* namespace apache */ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/src/Connection.cpp ---------------------------------------------------------------------- diff --git a/libminifi/src/Connection.cpp b/libminifi/src/Connection.cpp index ab300ba..bc76044 100644 --- a/libminifi/src/Connection.cpp +++ b/libminifi/src/Connection.cpp @@ -32,6 +32,7 @@ #include "core/FlowFile.h" #include "Connection.h" #include "core/Processor.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -42,7 +43,8 @@ Connection::Connection(std::shared_ptr<core::Repository> flow_repository, std::string name, uuid_t uuid, uuid_t srcUUID, uuid_t destUUID) : core::Connectable(name, uuid), - flow_repository_(flow_repository) { + flow_repository_(flow_repository), + logger_(logging::LoggerFactory<Connection>::getLogger()) { if (srcUUID) uuid_copy(src_uuid_, srcUUID); @@ -56,8 +58,6 @@ Connection::Connection(std::shared_ptr<core::Repository> flow_repository, expired_duration_ = 0; queued_data_size_ = 0; - logger_ = logging::Logger::getLogger(); - logger_->log_info("Connection %s created", name_.c_str()); } http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/src/FlowController.cpp ---------------------------------------------------------------------- diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp index c87875d..c7df2e7 100644 --- a/libminifi/src/FlowController.cpp +++ b/libminifi/src/FlowController.cpp @@ -39,6 +39,7 @@ #include "core/Core.h" #include "core/controller/ControllerServiceProvider.h" #include "core/repository/FlowFileRepository.h" +#include "core/logging/LoggerConfiguration.h" namespace org { namespace apache { @@ -69,7 +70,8 @@ FlowController::FlowController( event_scheduler_(nullptr), controller_service_provider_(nullptr), flow_configuration_(std::move(flow_configuration)), - configuration_(configure) { + configuration_(configure), + logger_(logging::LoggerFactory<FlowController>::getLogger()) { if (provenance_repo == nullptr) throw std::runtime_error("Provenance Repo should not be null"); if (flow_file_repo == nullptr) http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/73ecc667/libminifi/src/FlowFileRecord.cpp ---------------------------------------------------------------------- diff --git a/libminifi/src/FlowFileRecord.cpp b/libminifi/src/FlowFileRecord.cpp index de682b0..614ee28 100644 --- a/libminifi/src/FlowFileRecord.cpp +++ b/libminifi/src/FlowFileRecord.cpp @@ -28,7 +28,7 @@ #include <string> #include <iostream> #include <fstream> -#include "core/logging/Logger.h" +#include "core/logging/LoggerConfiguration.h" #include "core/Relationship.h" #include "core/Repository.h" @@ -44,7 +44,8 @@ FlowFileRecord::FlowFileRecord( std::map<std::string, std::string> attributes, std::shared_ptr<ResourceClaim> claim) : FlowFile(), - flow_repository_(flow_repository) { + flow_repository_(flow_repository), + logger_(logging::LoggerFactory<FlowFileRecord>::getLogger()) { id_ = local_flow_seq_number_.load(); claim_ = claim; @@ -65,7 +66,6 @@ FlowFileRecord::FlowFileRecord( if (claim_ != nullptr) // Increase the flow file record owned count for the resource claim claim_->increaseFlowFileRecordOwnedCount(); - logger_ = logging::Logger::getLogger(); } FlowFileRecord::FlowFileRecord( @@ -73,7 +73,8 @@ FlowFileRecord::FlowFileRecord( std::shared_ptr<core::FlowFile> &event, const std::string &uuidConnection) : FlowFile(), snapshot_(""), - flow_repository_(flow_repository) { + flow_repository_(flow_repository), + logger_(logging::LoggerFactory<FlowFileRecord>::getLogger()) { entry_date_ = event->getEntryDate(); lineage_start_date_ = event->getlineageStartDate(); lineage_Identifiers_ = event->getlineageIdentifiers(); @@ -94,7 +95,8 @@ FlowFileRecord::FlowFileRecord( : FlowFile(), uuid_connection_(""), snapshot_(""), - flow_repository_(flow_repository) { + flow_repository_(flow_repository), + logger_(logging::LoggerFactory<FlowFileRecord>::getLogger()) { } FlowFileRecord::~FlowFileRecord() {
