iceoryx_hoofs 2.0.5
Loading...
Searching...
No Matches
logger.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_LOGGER_HPP
18#define IOX_HOOFS_LOG_LOGGER_HPP
19
20#include "iceoryx_hoofs/cxx/generic_raii.hpp"
21#include "iceoryx_hoofs/log/logcommon.hpp"
22#include "iceoryx_hoofs/log/logstream.hpp"
23
24#include <atomic>
25#include <chrono>
26#include <functional>
27#include <string>
28
29namespace iox
30{
31namespace log
32{
35
36class Logger
37{
38 friend class LogManager;
40 friend class LogStream;
41
42 public:
43 Logger(Logger&& other) noexcept;
44 Logger& operator=(Logger&& rhs) noexcept;
45
46 Logger(const Logger& other) = delete;
47 Logger& operator=(const Logger& rhs) = delete;
48
51 // NOLINTNEXTLINE(readability-identifier-naming)
52 LogLevel GetLogLevel() const noexcept;
53
56 // NOLINTNEXTLINE(readability-identifier-naming)
57 void SetLogLevel(const LogLevel logLevel) noexcept;
58
63 // NOLINTNEXTLINE(readability-identifier-naming)
64 cxx::GenericRAII SetLogLevelForScope(const LogLevel logLevel) noexcept;
65
66 // NOLINTNEXTLINE(readability-identifier-naming)
67 void SetLogMode(const LogMode logMode) noexcept;
68 // NOLINTNEXTLINE(readability-identifier-naming)
69 bool IsEnabled(const LogLevel logLevel) const noexcept;
70
71 // NOLINTNEXTLINE(readability-identifier-naming)
72 LogStream LogFatal() noexcept;
73 // NOLINTNEXTLINE(readability-identifier-naming)
74 LogStream LogError() noexcept;
75 // NOLINTNEXTLINE(readability-identifier-naming)
76 LogStream LogWarn() noexcept;
77 // NOLINTNEXTLINE(readability-identifier-naming)
78 LogStream LogInfo() noexcept;
79 // NOLINTNEXTLINE(readability-identifier-naming)
80 LogStream LogDebug() noexcept;
81 // NOLINTNEXTLINE(readability-identifier-naming)
82 LogStream LogVerbose() noexcept;
83
84 protected:
85 Logger(const std::string& ctxId, const std::string& ctxDescription, const LogLevel appLogLevel) noexcept;
86
87 // virtual because of Logger_Mock
88 // NOLINTNEXTLINE(readability-identifier-naming)
89 virtual void Log(const LogEntry& entry) const noexcept;
90
91 private:
92 // NOLINTNEXTLINE(readability-identifier-naming)
93 static void Print(const LogEntry& entry) noexcept;
94
95 std::atomic<LogLevel> m_logLevel{LogLevel::kVerbose};
96 std::atomic<LogLevel> m_logLevelPredecessor{LogLevel::kVerbose};
97 std::atomic<LogMode> m_logMode{LogMode::kConsole};
98};
99
100} // namespace log
101} // namespace iox
102
103#endif // IOX_HOOFS_LOG_LOGGER_HPP
Definition logmanager.hpp:38
Definition logstream.hpp:118
Definition logger.hpp:37
cxx::GenericRAII SetLogLevelForScope(const LogLevel logLevel) noexcept
Sets the LogLevel to the given level for the lifetime of the GenericRAII object and then sets it back...
LogLevel GetLogLevel() const noexcept
Getter method for the current LogLevel.
void SetLogLevel(const LogLevel logLevel) noexcept
Sets the LogLevel for the Logger.
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29
Definition logcommon.hpp:71