olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
FilterGroup.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 <istream>
23#include <string>
24#include <unordered_map>
25#include <utility>
26
27#include <olp/core/CoreApi.h>
28#include <olp/core/logging/Level.h>
29#include <olp/core/porting/optional.h>
30
31namespace olp {
32namespace logging {
38class CORE_API FilterGroup {
39 public:
40 inline FilterGroup();
41
43 FilterGroup(const FilterGroup&) = default;
44
46 FilterGroup& operator=(const FilterGroup&) = default;
47
49 inline FilterGroup(FilterGroup&& other) noexcept;
50
52 inline FilterGroup& operator=(FilterGroup&& other) noexcept;
53
60 inline porting::optional<Level> getLevel() const;
61
67 inline FilterGroup& setLevel(Level level);
68
75 inline FilterGroup& clearLevel();
76
85 inline porting::optional<Level> getLevel(const std::string& tag) const;
86
93 inline FilterGroup& setLevel(Level level, const std::string& tag);
94
101 inline FilterGroup& clearLevel(const std::string& tag);
102
106 inline FilterGroup& clear();
107
116 bool load(const std::string& fileName);
117
142 bool load(std::istream& stream);
143
151 static porting::optional<Level> stringToLevel(const std::string& levelStr);
152
153 private:
154 friend class Log;
155
156 porting::optional<Level> m_defaultLevel;
157 std::unordered_map<std::string, Level> m_tagLevels;
158};
159
160inline FilterGroup::FilterGroup() : m_defaultLevel(porting::none) {}
161
162inline FilterGroup::FilterGroup(FilterGroup&& other) noexcept
163 : m_defaultLevel(std::move(other.m_defaultLevel)),
164 m_tagLevels(std::move(other.m_tagLevels)) {}
165
167 m_defaultLevel = std::move(other.m_defaultLevel);
168 m_tagLevels = std::move(other.m_tagLevels);
169 return *this;
170}
171
172inline porting::optional<Level> FilterGroup::getLevel() const {
173 return m_defaultLevel;
174}
175
176inline FilterGroup& FilterGroup::setLevel(Level level) {
177 m_defaultLevel = level;
178 return *this;
179}
180
182 m_defaultLevel = porting::none;
183 return *this;
184}
185
186inline porting::optional<Level> FilterGroup::getLevel(
187 const std::string& tag) const {
188 auto foundIter = m_tagLevels.find(tag);
189 if (foundIter == m_tagLevels.end())
190 return porting::none;
191 return foundIter->second;
192}
193
194inline FilterGroup& FilterGroup::setLevel(Level level, const std::string& tag) {
195 m_tagLevels[tag] = level;
196 return *this;
197}
198
199inline FilterGroup& FilterGroup::clearLevel(const std::string& tag) {
200 m_tagLevels.erase(tag);
201 return *this;
202}
203
205 m_defaultLevel = porting::none;
206 m_tagLevels.clear();
207 return *this;
208}
209
210} // namespace logging
211} // namespace olp
Groups together log levels for different tags.
Definition FilterGroup.h:38
porting::optional< Level > getLevel() const
Gets the default log level.
Definition FilterGroup.h:172
FilterGroup & clearLevel()
Clears the default log level.
Definition FilterGroup.h:181
bool load(const std::string &fileName)
Loads the filter group from a file.
static porting::optional< Level > stringToLevel(const std::string &levelStr)
Converts the string log level to the enum level format.
bool load(std::istream &stream)
Loads the filter group from a stream.
FilterGroup(const FilterGroup &)=default
The default copy constructor.
FilterGroup & setLevel(Level level)
Sets the default log level.
Definition FilterGroup.h:176
FilterGroup & operator=(const FilterGroup &)=default
The default copy assignment operator.
FilterGroup & clear()
Clears the filter group.
Definition FilterGroup.h:204
A primary interface for log messages.
Definition Log.h:431
Rules all the other namespaces.
Definition AppleSignInProperties.h:24