iceoryx_doc  1.0.1
logging.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_LOGGING_HPP
17 #define IOX_UTILS_LOG_LOGGING_HPP
18 
19 #include "iceoryx_utils/log/logcommon.hpp"
20 #include "iceoryx_utils/log/logger.hpp"
21 #include "iceoryx_utils/log/logstream.hpp"
22 
23 #include <chrono>
24 #include <string>
25 
26 namespace iox
27 {
28 namespace log
29 {
30 Logger& CreateLogger(std::string ctxId, std::string ctxDescription, LogLevel appDefLogLevel = LogLevel::kWarn) noexcept;
31 
32 inline constexpr LogHex8 HexFormat(uint8_t value)
33 {
34  return LogHex8(value);
35 }
36 inline constexpr LogHex8 HexFormat(int8_t value)
37 {
38  return LogHex8(static_cast<uint8_t>(value));
39 }
40 inline constexpr LogHex16 HexFormat(uint16_t value)
41 {
42  return LogHex16(value);
43 }
44 inline constexpr LogHex16 HexFormat(int16_t value)
45 {
46  return LogHex16(static_cast<uint16_t>(value));
47 }
48 inline constexpr LogHex32 HexFormat(uint32_t value)
49 {
50  return LogHex32(value);
51 }
52 inline constexpr LogHex32 HexFormat(int32_t value)
53 {
54  return LogHex32(static_cast<uint32_t>(value));
55 }
56 inline constexpr LogHex64 HexFormat(uint64_t value)
57 {
58  return LogHex64(value);
59 }
60 inline constexpr LogHex64 HexFormat(int64_t value)
61 {
62  return LogHex64(static_cast<uint64_t>(value));
63 }
64 
65 inline constexpr LogBin8 BinFormat(uint8_t value)
66 {
67  return LogBin8(value);
68 }
69 inline constexpr LogBin8 BinFormat(int8_t value)
70 {
71  return LogBin8(static_cast<uint8_t>(value));
72 }
73 inline constexpr LogBin16 BinFormat(uint16_t value)
74 {
75  return LogBin16(value);
76 }
77 inline constexpr LogBin16 BinFormat(int16_t value)
78 {
79  return LogBin16(static_cast<uint16_t>(value));
80 }
81 inline constexpr LogBin32 BinFormat(uint32_t value)
82 {
83  return LogBin32(value);
84 }
85 inline constexpr LogBin32 BinFormat(int32_t value)
86 {
87  return LogBin32(static_cast<uint32_t>(value));
88 }
89 inline constexpr LogBin64 BinFormat(uint64_t value)
90 {
91  return LogBin64(value);
92 }
93 inline constexpr LogBin64 BinFormat(int64_t value)
94 {
95  return LogBin64(static_cast<uint64_t>(value));
96 }
97 
98 template <typename T, typename std::enable_if<!std::is_pointer<T>::value, std::nullptr_t>::type = nullptr>
99 inline constexpr LogRawBuffer RawBuffer(const T& value) noexcept
100 {
101  // LogRawBuffer is used with the streaming operator which converts the data into a string,
102  // therefore we shouldn't get lifetime issues
103  return LogRawBuffer{reinterpret_cast<const uint8_t*>(&value), sizeof(T)};
104 }
105 
106 } // namespace log
107 } // namespace iox
108 
109 #endif // IOX_UTILS_LOG_LOGGING_HPP
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28