Github user phrocker commented on a diff in the pull request: https://github.com/apache/nifi-minifi-cpp/pull/57#discussion_r103284475 --- Diff: libminifi/include/LogAppenders.h --- @@ -0,0 +1,292 @@ +/** + * + * 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 "Configure.h" + +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(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 --- End diff -- I did that in a few places apparently...
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---