iceoryx_doc  1.0.1
logmanager.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_LOG_LOGMANAGER_HPP
17 #define IOX_UTILS_LOG_LOGMANAGER_HPP
18 
19 #include "iceoryx_utils/log/logcommon.hpp"
20 #include "iceoryx_utils/log/logger.hpp"
21 
22 #include <atomic>
23 #include <map>
24 #include <string>
25 
26 namespace iox
27 {
28 namespace log
29 {
30 enum class LogLevelOutput : uint8_t
31 {
32  kDisplayLogLevel = 0,
33  kHideLogLevel
34 };
35 
37 {
38  public:
39  static LogManager& GetLogManager();
40  static Logger& CreateLogContext(std::string ctxId, std::string ctxDescription, LogLevel appDefLogLevel) noexcept;
41 
42  ~LogManager() = default;
43 
44  LogManager(const LogManager&) = delete;
45  LogManager(LogManager&&) = delete;
46  LogManager& operator=(const LogManager&) = delete;
47  LogManager& operator=(LogManager&&) = delete;
48 
49  LogLevel DefaultLogLevel() const noexcept;
50  void SetDefaultLogLevel(const LogLevel logLevel,
51  const LogLevelOutput logLevelOutput = LogLevelOutput::kDisplayLogLevel) noexcept;
52 
53  LogMode DefaultLogMode() const noexcept;
54  void SetDefaultLogMode(const LogMode logMode) noexcept;
55 
56  protected:
57  LogManager() = default;
58 
59  private:
60  std::atomic<LogLevel> m_defaultLogLevel{LogLevel::kVerbose};
61  std::atomic<LogMode> m_defaultLogMode{LogMode::kConsole};
62 
63  std::map<std::string, Logger> m_loggers;
64 };
65 
66 } // namespace log
67 } // namespace iox
68 
69 #endif // IOX_UTILS_LOG_LOGMANAGER_HPP
Definition: logmanager.hpp:37
Definition: logger.hpp:35
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28