This is an automated email from the ASF dual-hosted git repository. isapego pushed a commit to branch ignite-17424 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 04b98b5d7afb08e3a1b4b1cf1894df0a819fd8cc Author: Igor Sapego <[email protected]> AuthorDate: Wed Aug 31 12:36:00 2022 +0400 IGNITE-17424 Add logging support --- .../include/ignite/ignite_client_configuration.h | 31 +++++++++- .../cpp/client/include/ignite/ignite_logger.h | 72 ++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/modules/platforms/cpp/client/include/ignite/ignite_client_configuration.h b/modules/platforms/cpp/client/include/ignite/ignite_client_configuration.h index 3212a0e9cf..e0073b6641 100644 --- a/modules/platforms/cpp/client/include/ignite/ignite_client_configuration.h +++ b/modules/platforms/cpp/client/include/ignite/ignite_client_configuration.h @@ -21,6 +21,8 @@ #include <string> #include <vector> +#include <ignite/ignite_logger.h> + namespace ignite { @@ -49,7 +51,8 @@ public: * @param endpoint Endpoints list. */ IgniteClientConfiguration(std::initializer_list<std::string> endpoints) : - m_endpoints(endpoints) { } + m_endpoints(endpoints), + m_logger() { } /** * Get endpoints. @@ -83,9 +86,35 @@ public: IgniteClientConfiguration::m_endpoints = endpoints; } + /** + * Get logger. + * + * @return Current logger. + */ + [[nodiscard]] + std::shared_ptr<IgniteLogger> getLogger() const + { + return m_logger; + } + + /** + * Set logger to be used by client. + * + * The logger is @c nullptr by default, which means no logging is performed. + * + * @param logger Logger to use. + */ + void setLogger(std::shared_ptr<IgniteLogger> logger) + { + m_logger = std::move(logger); + } + private: /** Endpoints. */ std::vector<std::string> m_endpoints; + + /** Logger. */ + std::shared_ptr<IgniteLogger> m_logger; }; } // namespace ignite \ No newline at end of file diff --git a/modules/platforms/cpp/client/include/ignite/ignite_logger.h b/modules/platforms/cpp/client/include/ignite/ignite_logger.h new file mode 100644 index 0000000000..f274775ace --- /dev/null +++ b/modules/platforms/cpp/client/include/ignite/ignite_logger.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#pragma once + +#include <string_view> + +namespace ignite +{ + +/** + * Ignite logger interface. + * + * User can implement this class to use preferred logger with Ignite client. + */ +class IgniteLogger +{ +public: + // Default + IgniteLogger() = default; + ~IgniteLogger() = default; + IgniteLogger(IgniteLogger&&) = default; + IgniteLogger(const IgniteLogger&) = default; + IgniteLogger& operator=(IgniteLogger&&) = default; + IgniteLogger& operator=(const IgniteLogger&) = default; + + /** + * Used to log error messages. + * + * @param message Error message. + */ + virtual void logError(std::string_view message) = 0; + + /** + * Used to log warning messages. + * + * @param message Warning message. + */ + virtual void logWarning(std::string_view message) = 0; + + /** + * Used to log info messages. + * + * @param message Info message. + */ + virtual void logInfo(std::string_view message) = 0; + + /** + * Used to log debug messages. + * + * It is recommended to disable debug logging by default for the sake of performance. + * + * @param message Debug message. + */ + virtual void logDebug(std::string_view message) = 0; +}; + +} // namespace ignite \ No newline at end of file
