Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
LogEvent.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <string_view>
13
15
16namespace corium::logging {
17
20template <std::size_t MaxMessageLength = 256>
21struct LogEventT {
23 std::array<char, MaxMessageLength> message{};
24 std::size_t length = 0;
25 const char* category = "App";
26 uint64_t timestampNs = 0;
27
28 constexpr LogEventT() = default;
29
31 constexpr LogEventT(LogLevel lvl, std::string_view msg, const char* cat = "App", uint64_t ts = 0) noexcept
32 : level(lvl), category(cat ? cat : "App"), timestampNs(ts)
33 {
34 setMessage(msg);
35 }
36
38 constexpr void setMessage(std::string_view msg) noexcept
39 {
40 std::size_t copyLen = msg.length() < (MaxMessageLength - 1) ? msg.length() : (MaxMessageLength - 1);
41 for (std::size_t i = 0; i < copyLen; ++i) {
42 message[i] = msg[i];
43 }
44 message[copyLen] = '\0';
45 length = copyLen;
46 }
47
49 [[nodiscard]] constexpr std::string_view view() const noexcept
50 {
51 return std::string_view(message.data(), length);
52 }
53};
54
57
58} // namespace corium::logging
Log severity enumeration and ANSI color formatting utilities.
Definition LogBackgroundService.hpp:17
LogLevel
Logging severity levels.
Definition LogLevel.hpp:14
Zero-heap log event carrying fixed-size inline message buffer across MPSC event bus.
Definition LogEvent.hpp:21
std::array< char, MaxMessageLength > message
Definition LogEvent.hpp:23
std::size_t length
Definition LogEvent.hpp:24
constexpr void setMessage(std::string_view msg) noexcept
Set inline message buffer safely up to MaxMessageLength - 1.
Definition LogEvent.hpp:38
constexpr LogEventT(LogLevel lvl, std::string_view msg, const char *cat="App", uint64_t ts=0) noexcept
Create log event with inline formatted string.
Definition LogEvent.hpp:31
const char * category
Definition LogEvent.hpp:25
uint64_t timestampNs
Definition LogEvent.hpp:26
LogLevel level
Definition LogEvent.hpp:22
constexpr std::string_view view() const noexcept
Access message as std::string_view.
Definition LogEvent.hpp:49
constexpr LogEventT()=default