iceoryx_hoofs 2.0.3
logmanager.hpp
1// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
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#ifndef IOX_HOOFS_LOG_LOGMANAGER_HPP
18#define IOX_HOOFS_LOG_LOGMANAGER_HPP
19
20#include "iceoryx_hoofs/log/logcommon.hpp"
21#include "iceoryx_hoofs/log/logger.hpp"
22
23#include <atomic>
24#include <map>
25#include <string>
26
27namespace iox
28{
29namespace log
30{
31enum class LogLevelOutput : uint8_t
32{
33 kDisplayLogLevel = 0,
34 kHideLogLevel
35};
36
38{
39 public:
40 // NOLINTNEXTLINE(readability-identifier-naming)
41 static LogManager& GetLogManager() noexcept;
42 static Logger&
43 // NOLINTNEXTLINE(readability-identifier-naming)
44 CreateLogContext(const std::string& ctxId,
45 const std::string& ctxDescription,
46 const LogLevel appDefLogLevel) noexcept;
47
48 ~LogManager() noexcept = default;
49
50 LogManager(const LogManager&) = delete;
51 LogManager(LogManager&&) = delete;
52 LogManager& operator=(const LogManager&) = delete;
53 LogManager& operator=(LogManager&&) = delete;
54
55 // NOLINTNEXTLINE(readability-identifier-naming)
56 LogLevel DefaultLogLevel() const noexcept;
57 // NOLINTNEXTLINE(readability-identifier-naming)
58 void SetDefaultLogLevel(const LogLevel logLevel,
59 const LogLevelOutput logLevelOutput = LogLevelOutput::kDisplayLogLevel) noexcept;
60
61 // NOLINTNEXTLINE(readability-identifier-naming)
62 LogMode DefaultLogMode() const noexcept;
63 // NOLINTNEXTLINE(readability-identifier-naming)
64 void SetDefaultLogMode(const LogMode logMode) noexcept;
65
66 protected:
67 LogManager() noexcept = default;
68
69 private:
70 std::atomic<LogLevel> m_defaultLogLevel{LogLevel::kVerbose};
71 std::atomic<LogMode> m_defaultLogMode{LogMode::kConsole};
72
73 std::map<std::string, Logger> m_loggers;
74};
75
76} // namespace log
77} // namespace iox
78
79#endif // IOX_HOOFS_LOG_LOGMANAGER_HPP
Definition: logmanager.hpp:38
Definition: logger.hpp:37
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29