iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
logstream.hpp
Go to the documentation of this file.
1// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
3// Copyright (c) 2023 by ekxide IO GmbH. All rights reserved.
4// Copyright (c) 2025 Contributors to the Eclipse Foundation
5//
6// See the NOTICE file(s) distributed with this work for additional
7// information regarding copyright ownership.
8//
9// This program and the accompanying materials are made available under the
10// terms of the Apache Software License 2.0 which is available at
11// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
12// which is available at https://opensource.org/licenses/MIT.
13//
14// SPDX-License-Identifier: Apache-2.0 OR MIT
15
16#ifndef IOX2_BB_REPORTING_LOG_LOGSTREAM_HPP
17#define IOX2_BB_REPORTING_LOG_LOGSTREAM_HPP
18
20
23
24#include <cstdint>
25#include <string>
26
27namespace iox2 {
28namespace legacy {
29namespace log {
30class LogStream;
31
33template <typename T>
34class LogHex {
35 public:
36 friend class LogStream;
37
38 template <typename TT, typename>
39 friend constexpr LogHex<TT> hex(const TT) noexcept;
40 friend constexpr LogHex<const void* const> hex(const void* const) noexcept;
41
42 ~LogHex() = default;
43
44 LogHex(const LogHex&) = delete;
45 LogHex& operator=(const LogHex&) = delete;
47
48 private:
49 template <typename = std::enable_if_t<std::is_arithmetic<T>::value || std::is_pointer<T>::value>>
51
53
54 // NOLINTJUSTIFICATION intentionally used since the class does not need to be assignable and the data is not supposed to be changed
55 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
56 T m_value;
57};
58
63// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
64template <typename T, typename = std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value>>
66
70// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
72
76 public:
77 friend class LogStream;
78
79 template <typename TT, typename>
80 friend constexpr LogOct<TT> oct(const TT) noexcept;
81
82 ~LogOct() = default;
83
84 LogOct(const LogOct&) = delete;
85 LogOct& operator=(const LogOct&) = delete;
87
88 private:
89 template <typename = std::enable_if_t<std::is_integral<T>::value>>
91
93
94 T m_value;
95};
96
101// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
102template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
104
108 public:
109 friend class LogStream;
110
111 template <typename TT, typename>
112 friend constexpr LogBin<TT> bin(const TT) noexcept;
113
114 ~LogBin() = default;
115
116 LogBin(const LogBin&) = delete;
117 LogBin& operator=(const LogBin&) = delete;
119
120 private:
121 template <typename = std::enable_if_t<std::is_integral<T>::value>>
123
125
126 T m_value;
127};
128
133// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
134template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
136
139 public:
140 friend class LogStream;
141
142 // for some reasons the default template argument SFINEA results in the error
143 // 'redeclaration of friend ... may not have default template arguments' on GCC but return type SFINEA seams to work
144 template <typename T>
145 friend constexpr typename std::enable_if<!std::is_pointer<T>::value, LogRaw>::type raw(const T&) noexcept;
146 friend constexpr LogRaw raw(const void* const, const uint64_t) noexcept;
147
148 ~LogRaw() = default;
149
150 LogRaw(const LogRaw&) = delete;
151 LogRaw& operator=(const LogRaw&) = delete;
153
154 private:
156
158
159 // NOLINTJUSTIFICATION intentionally used since the class does not need to be assignable and the data is not supposed to be changed
160 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
161 const void* const m_data;
162 uint64_t m_size;
163};
164
169// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
171constexpr typename std::enable_if<!std::is_pointer<T>::value, LogRaw>::type raw(const T& object) noexcept;
172
177// AXIVION Next Construct AutosarC++19_03-M17.0.3 : The function is in the iox2::legacy::log namespace which prevents easy misuse
179
190 public:
196 LogStream(Logger& logger, const bb::detail::SourceLocation location, const LogLevel logLevel) noexcept;
197
202 LogStream(const bb::detail::SourceLocation location, const LogLevel logLevel) noexcept;
203
205
208
211
217
221 // AXIVION Next Construct AutosarC++19_03-A3.9.1 : Logging support for C-style strings
223
230
235
236 // AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1 : Basic numeric types are used in order to cover als basic numeric types, independent of the type alias
237
242
247
252
257
261 LogStream& operator<<(const unsigned short val) noexcept;
262
267
272
277
282
287
291 LogStream& operator<<(const unsigned long long val) noexcept;
292
297
302
307
308 // AXIVION ENABLE STYLE AutosarC++19_03-A3.9.1
309
314 template <typename T, typename std::enable_if_t<std::is_integral<T>::value, bool> = 0>
316
321 template <typename T, typename std::enable_if_t<std::is_floating_point<T>::value, bool> = 0>
323
328
333 template <typename T, typename std::enable_if_t<std::is_integral<T>::value, bool> = 0>
335
340 template <typename T, typename std::enable_if_t<std::is_integral<T>::value, bool> = 0>
342
347
362
367
368 private:
369 void flush() noexcept;
370
371 // JUSTIFICATION it is fine to use a reference since the LogStream object is intentionally not movable
372 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
373 Logger& m_logger;
374 bool m_isFlushed { false };
375
377 bool m_doFlush { true };
378};
379
380} // namespace log
381} // namespace legacy
382} // namespace iox2
383
384#include "iox2/legacy/detail/log/logstream.inl"
385
386#endif // IOX2_BB_REPORTING_LOG_LOGSTREAM_HPP
Helper struct to log in binary format.
LogBin(const LogBin &)=delete
LogBin & operator=(LogBin &&) noexcept=delete
friend constexpr LogBin< TT > bin(const TT) noexcept
LogBin & operator=(const LogBin &)=delete
Helper struct to log in hexadecimal format.
Definition logstream.hpp:34
LogHex & operator=(const LogHex &)=delete
LogHex & operator=(LogHex &&) noexcept=delete
friend constexpr LogHex< const void *const > hex(const void *const) noexcept
Log a pointer in hexadecimal format.
LogHex(const LogHex &)=delete
friend constexpr LogHex< TT > hex(const TT) noexcept
Helper struct to log in octal format.
Definition logstream.hpp:75
friend constexpr LogOct< TT > oct(const TT) noexcept
LogOct(const LogOct &)=delete
LogOct & operator=(const LogOct &)=delete
LogOct & operator=(LogOct &&) noexcept=delete
Helper struct to log in raw bytes.
friend constexpr std::enable_if<!std::is_pointer< T >::value, LogRaw >::type raw(const T &) noexcept
Log an object in raw bytes.
LogRaw & operator=(LogRaw &&) noexcept=delete
friend constexpr LogRaw raw(const void *const, const uint64_t) noexcept
Log data in raw bytes.
LogRaw & operator=(const LogRaw &)=delete
LogRaw(const LogRaw &)=delete
This class provides the public interface to the logger and is used with the 'IOX2_LOG' macro....
virtual ~LogStream() noexcept
LogStream(Logger &logger, const bb::detail::SourceLocation location, const LogLevel logLevel) noexcept
Constructor for a LogStream object with an externally provided logger.
LogStream(const bb::detail::SourceLocation location, const LogLevel logLevel) noexcept
Constructor for a LogStream object with the logger from iox2::legacy::log::Logger::get.
This class acts as common interface for the Logger. It provides the common functionality and inherits...
Definition logger.hpp:71
LogLevel
This enum defines the log levels used for logging.
Definition logger.hpp:30
constexpr std::enable_if<!std::is_pointer< T >::value, LogRaw >::type raw(const T &object) noexcept
Log an object in raw bytes.
constexpr LogOct< T > oct(const T value) noexcept
Log a number in octal format.
constexpr LogBin< T > bin(const T value) noexcept
Log a number in binary format.
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
constexpr uint64_t size(const UninitializedArray< T, N, Buffer > &) noexcept
Returns N.
void log(LogLevel log_level, const char *origin, const char *message)
Adds a log message to the logger.
Verifies whether the passed Callable type is in fact invocable with the given arguments and the resul...