olp-cpp-sdk  1.22.0
Configuration.h
1 /*
2  * Copyright (C) 2019-2021 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <memory>
23 #include <utility>
24 #include <vector>
25 
26 #include <olp/core/CoreApi.h>
27 #include <olp/core/logging/Appender.h>
28 #include <olp/core/logging/MessageFormatter.h>
29 
30 namespace olp {
31 namespace logging {
36 class CORE_API Configuration {
37  public:
47  logging::Level logLevel;
48 
52  std::shared_ptr<IAppender> appender;
53 
59  bool isEnabled(logging::Level level) const {
60  return appender && static_cast<int>(level) >= static_cast<int>(logLevel);
61  }
62  };
63 
67  using AppenderList = std::vector<AppenderWithLogLevel>;
68 
76 
82  inline bool isValid() const;
83 
90  inline Configuration& addAppender(
91  std::shared_ptr<IAppender> appender,
92  logging::Level level = logging::Level::Trace);
93 
97  inline Configuration& clear();
98 
104  inline const AppenderList& getAppenders() const;
105 
106  private:
107  AppenderList m_appenders;
108 };
109 
110 inline bool Configuration::isValid() const { return !m_appenders.empty(); }
111 
113  std::shared_ptr<IAppender> appender, logging::Level level) {
114  if (appender) {
115  AppenderWithLogLevel appenderWithLogLevel = {level, std::move(appender)};
116  m_appenders.emplace_back(std::move(appenderWithLogLevel));
117  }
118  return *this;
119 }
120 
122  m_appenders.clear();
123  return *this;
124 }
125 
126 inline auto Configuration::getAppenders() const -> const AppenderList& {
127  return m_appenders;
128 }
129 
130 } // namespace logging
131 } // namespace olp
Configures appenders and loggers available in the logging system.
Definition: Configuration.h:36
std::vector< AppenderWithLogLevel > AppenderList
A typedef for a list of appenders.
Definition: Configuration.h:67
static Configuration createDefault()
Creates a default configuration by adding an instance of DebugAppender and ConsoleAppender as appende...
const AppenderList & getAppenders() const
Gets the appenders from the configuration.
Definition: Configuration.h:126
Configuration & addAppender(std::shared_ptr< IAppender > appender, logging::Level level=logging::Level::Trace)
Adds the appender along with its log level to the configuration.
Definition: Configuration.h:112
bool isValid() const
Checks whether the configuration is valid.
Definition: Configuration.h:110
Configuration & clear()
Clears the list of appenders.
Definition: Configuration.h:121
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Contains an appender and its log level.
Definition: Configuration.h:41
std::shared_ptr< IAppender > appender
The appender.
Definition: Configuration.h:52
logging::Level logLevel
The log level of the appender.
Definition: Configuration.h:47
bool isEnabled(logging::Level level) const
Checks whether the appender is enabled for the log level.
Definition: Configuration.h:59