livox_mid360_core
C++ driver library for the Livox Mid-360 LiDAR
Loading...
Searching...
No Matches
log.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
6#pragma once
7
8#include <cstdint>
9#include <expected>
10#include <filesystem>
11#include <functional>
12#include <string>
13#include <string_view>
14
17
18LIVOX_MID360_API_BEGIN
19
20namespace livox::mid360
21{
22
24enum class LogLevel : std::uint8_t
25{
27 kError,
29 kInfo,
32};
33
36{
38 std::int64_t time_ns = 0;
39 std::string_view serial_number;
40 std::string_view message;
41};
42
45using LogHandler = std::function<void(const LogRecord &)>;
46
49void set_log_level(LogLevel level) noexcept;
51[[nodiscard]] LogLevel log_level() noexcept;
52
57
60[[nodiscard]] std::string format_log_record(const LogRecord & record);
61
64
68[[nodiscard]] std::expected<LogHandler, DeviceError> file_log_handler(
69 const std::filesystem::path & path, bool append = true);
70
72[[nodiscard]] std::string_view to_string(LogLevel level) noexcept;
73
74} // namespace livox::mid360
75
76LIVOX_MID360_API_END
Public API (issue #9): notifications and errors of the device layer.
Symbol visibility helpers.
The livox_mid360_core library: everything declared by the public headers.
Definition bytes.hpp:14
void set_log_handler(LogHandler handler)
Process-wide; safe to call while a Context is running.
LogHandler stderr_log_handler()
Writes format_log_record() + ' ' to stderr.
LogLevel log_level() noexcept
Current process-wide level, see set_log_level().
std::expected< LogHandler, DeviceError > file_log_handler(const std::filesystem::path &path, bool append=true)
Opens (creates or, with append, extends) path and returns a handler that writes format_log_record() +...
std::string format_log_record(const LogRecord &record)
2026-09-26T12:34:56.789Z W [serial] message (UTC, millisecond precision, one-letter level E/W/I/D/T,...
std::function< void(const LogRecord &)> LogHandler
Called from the Context receive thread, the Device worker thread and caller threads,...
Definition log.hpp:45
void set_log_level(LogLevel level) noexcept
Process-wide.
LogLevel
Severity, ordered: a level is emitted when it is <= the level set with set_log_level().
Definition log.hpp:25
@ kInfo
state transitions, reconnect attempts, host-setup replay, open / close
Definition log.hpp:29
@ kWarn
disconnects, command timeouts
Definition log.hpp:28
@ kDebug
request retries, datagrams from unknown sources
Definition log.hpp:30
@ kOff
default: nothing is emitted
Definition log.hpp:26
@ kTrace
reserved
Definition log.hpp:31
std::string_view to_string(Event::Kind kind) noexcept
Name of an event kind, e.g. "state_changed".
Errors of Context / Device. Session-level failures are wrapped, not re-encoded.
Definition event.hpp:128
One diagnostic record. The views are valid only during the handler call.
Definition log.hpp:36
std::string_view message
one line, no trailing newline, at most 255 bytes
Definition log.hpp:40
std::int64_t time_ns
system clock, nanoseconds since the Unix epoch
Definition log.hpp:38
LogLevel level
severity
Definition log.hpp:37
std::string_view serial_number
empty when the record is not device-scoped
Definition log.hpp:39