[ https://issues.apache.org/jira/browse/MINIFI-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15886329#comment-15886329 ]
ASF GitHub Bot commented on MINIFI-83: -------------------------------------- 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... > Externalize configuration of logs > --------------------------------- > > Key: MINIFI-83 > URL: https://issues.apache.org/jira/browse/MINIFI-83 > Project: Apache NiFi MiNiFi > Issue Type: Improvement > Components: C++, Core Framework > Reporter: Aldrin Piri > Assignee: marco polo > Attachments: callgrind.out.11807 > > > spdlog has a number of options that provide configuration similar to logback > in terms of rotating by date and size. These are not inherently configurable > through an existing file however. It would be a nice improvement to expose > these options in a friendly way such that a user can dictate what their > preferences are in terms of size vs time as well as the amount of disk > resources they are willing to allocate to such logs. > https://github.com/gabime/spdlog/wiki/2.-Creating-loggers -- This message was sent by Atlassian JIRA (v6.3.15#6346)