iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2023 by ekxide IO GmbH. All rights reserved.
3// Copyright (c) 2025 Contributors to the Eclipse Foundation
4//
5// See the NOTICE file(s) distributed with this work for additional
6// information regarding copyright ownership.
7//
8// This program and the accompanying materials are made available under the
9// terms of the Apache Software License 2.0 which is available at
10// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
11// which is available at https://opensource.org/licenses/MIT.
12//
13// SPDX-License-Identifier: Apache-2.0 OR MIT
14
15#ifndef IOX2_BB_REPORTING_LOGGING_HPP
16#define IOX2_BB_REPORTING_LOGGING_HPP
17
19
20namespace iox2 {
21namespace legacy {
22namespace log {
23namespace internal {
25inline auto is_log_level_active(LogLevel log_level) noexcept -> bool {
26 // AXIVION Next Construct FaultDetection-DeadBranches this is a configurable compile time option to be able to
27 // optimize the logger call away during compilation and intended
28 // AXIVION Next Construct AutosarC++19_03-M0.1.2 see justification for FaultDetection-DeadBranches
29 // AXIVION Next Construct AutosarC++19_03-M0.1.9 see justification for FaultDetection-DeadBranches
30 // AXIVION Next Construct AutosarC++19_03-M5.14.1 getLogLevel is a static method without side effects
31 return ((log_level) <= MINIMAL_LOG_LEVEL)
32 && (IGNORE_ACTIVE_LOG_LEVEL || ((log_level) <= log::Logger::getLogLevel()));
33}
34} // namespace internal
35} // namespace log
36} // namespace legacy
37} // namespace iox2
38
40// AXIVION Next Construct AutosarC++19_03-A16.0.1 cannot be realized with templates or constexpr functions due to the
41// intended lazy evaluation technique with the if statement
42// NOLINTBEGIN(cppcoreguidelines-macro-usage)
43// NOLINTBEGIN(bugprone-macro-parentheses) 'msg_stream' cannot be wrapped in parentheses due to the '<<' operator
44#define IOX2_LOG_INTERNAL(location, level, msg_stream) \
45 if (iox2::legacy::log::internal::is_log_level_active(level)) { \
46 iox2::legacy::log::LogStream(location, level).self() << msg_stream; \
47 } \
48 []() -> void { }() // the empty lambda forces a semicolon on the caller side
49 // NOLINTEND(bugprone-macro-parentheses)
50
57// AXIVION Next Construct AutosarC++19_03-A16.0.1 needed for source code location, safely wrapped in macro
58// AXIVION Next Construct AutosarC++19_03-M16.0.6 brackets around macro parameter would lead to compile time failures in this case
59// NOLINTJUSTIFICATION __PRETTY_FUNCTION__ would work better in lambdas but especially with
60// templates the resulting string is too large; we also get the file name and the line of the invocation which should be
61// sufficient for debugging
62// NOLINTBEGIN(bugprone-lambda-function-name)
63#define IOX2_LOG(level, msg_stream) \
64 IOX2_LOG_INTERNAL(iox2::bb::detail::SourceLocation::current(), iox2::legacy::log::LogLevel::level, msg_stream)
65// NOLINTEND(bugprone-lambda-function-name)
66
67// NOLINTEND(cppcoreguidelines-macro-usage)
68
69#endif // IOX2_BB_REPORTING_LOGGING_HPP
auto is_log_level_active(LogLevel log_level) noexcept -> bool
Convenience function for the IOX2_LOG_INTERNAL macro.
Definition logging.hpp:25
LogLevel
This enum defines the log levels used for logging.
Definition logger.hpp:30
static constexpr LogLevel MINIMAL_LOG_LEVEL
The minimal log level which will be compiled into the application. All log levels below this will be ...
Definition logger.hpp:47
static constexpr bool IGNORE_ACTIVE_LOG_LEVEL
If set to true, the IOX2_LOG macro will ignore the the configured log level and forward all messages ...
Definition logger.hpp:42
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
void log(LogLevel log_level, const char *origin, const char *message)
Adds a log message to the logger.