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