You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by phrocker <gi...@git.apache.org> on 2017/02/24 20:46:04 UTC
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
GitHub user phrocker opened a pull request:
https://github.com/apache/nifi-minifi-cpp/pull/57
MINIFI-83: Allow appenders to be specified and auto configured.
This PR will modify logging so that we can have configurable
appenders and have them be modified via custom configuration
for that appender. Eventually these can be modified real time.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/phrocker/nifi-minifi-cpp MINIFI-83
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi-minifi-cpp/pull/57.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #57
----
commit e1b05ccc68ca4084b4ac861bd5de0eb21e5d44e5
Author: Marc Parisi <ph...@apache.org>
Date: 2017-02-24T15:06:19Z
MINIFI-83: Allow appenders to be specified and auto configured.
This PR will modify logging so that we can have configurable
appenders and have them be modified via custom configuration
for that appender. Eventually these can be modified real time.
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
Posted by phrocker <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp issue #57: MINIFI-83: Allow appenders to be specified and au...
Posted by apiri <gi...@git.apache.org>.
Github user apiri commented on the issue:
https://github.com/apache/nifi-minifi-cpp/pull/57
Looks great, thanks. Will get this merged.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/nifi-minifi-cpp/pull/57
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
Posted by phrocker <gi...@git.apache.org>.
Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/57#discussion_r103284177
--- 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 --
Good catch, thanks. I'll update this when you're finished commenting so I don't make your life harder.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
Posted by apiri <gi...@git.apache.org>.
Github user apiri commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/57#discussion_r103283648
--- 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
+ 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, 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");
--- End diff --
minor: believe we should make use of braces around else clause as well
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp pull request #57: MINIFI-83: Allow appenders to be specified...
Posted by apiri <gi...@git.apache.org>.
Github user apiri commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/57#discussion_r103283615
--- 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 --
minor: believe we should make use of braces around else clause as well
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi-minifi-cpp issue #57: MINIFI-83: Allow appenders to be specified and au...
Posted by apiri <gi...@git.apache.org>.
Github user apiri commented on the issue:
https://github.com/apache/nifi-minifi-cpp/pull/57
reviewing
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---