RaidZeroLib
Coroutine robot framework for VEX V5
Toggle main menu visibility
Loading...
Searching...
No Matches
Log.hpp
1
#pragma once
2
#include <cstdint>
3
#include <format>
4
#include <functional>
5
#include <string>
6
#include <string_view>
7
#include <utility>
8
9
#include "RaidZeroLib/ThirdParty/au/au.hpp"
10
#include "RaidZeroLib/api/Units/Units.hpp"
11
14
template
<
typename
Unit,
typename
Rep>
15
struct
std::formatter<::au::Quantity<Unit, Rep>> : ::au::QuantityFormatter<Unit, Rep, ::std::formatter> {};
16
17
namespace
rz
{
18
22
class
Log
{
23
public
:
24
Log
() =
delete
;
25
26
enum class
Level
{ Debug, Info, Warn, Error };
27
28
struct
Record
{
29
Level
level
;
30
Time
time
;
31
std::uint64_t
tick
;
32
std::string_view
message
;
33
};
34
35
using
Output
= std::function<void(
const
Record
&)>;
36
37
template
<
class
... Args>
38
static
void
debug
(std::format_string<Args...>
format
, Args&&... args) {
39
log(
Level::Debug
,
format
, std::forward<Args>(args)...);
40
}
41
42
template
<
class
... Args>
43
static
void
info
(std::format_string<Args...>
format
, Args&&... args) {
44
log(
Level::Info
,
format
, std::forward<Args>(args)...);
45
}
46
47
template
<
class
... Args>
48
static
void
warn
(std::format_string<Args...>
format
, Args&&... args) {
49
log(
Level::Warn
,
format
, std::forward<Args>(args)...);
50
}
51
52
template
<
class
... Args>
53
static
void
error
(std::format_string<Args...>
format
, Args&&... args) {
54
log(
Level::Error
,
format
, std::forward<Args>(args)...);
55
}
56
58
static
void
setMinimumLevel
(
Level
level)
noexcept
;
59
[[nodiscard]]
static
Level
minimumLevel
() noexcept;
60
62
static
void
setOutput
(
Output
output);
63
65
static
void
toStdout
(const
Record
& record);
66
68
[[nodiscard]] static std::
string
format
(const
Record
& record);
69
70
private:
71
template <class... Args>
72
static
void
log(
Level
level, std::format_string<Args...>
format
, Args&&... args) {
73
if
(level <
minimumLevel
()) {
74
return
;
75
}
76
write(level, std::format(
format
, std::forward<Args>(args)...));
77
}
78
80
static
void
write(
Level
level, std::string_view message);
81
};
82
83
}
// namespace rz
rz::Log::debug
static void debug(std::format_string< Args... > format, Args &&... args)
Definition
Log.hpp:38
rz::Log::setMinimumLevel
static void setMinimumLevel(Level level) noexcept
Messages below this level are dropped before they are formatted. Defaults to Info.
rz::Log::Log
Log()=delete
rz::Log::format
static std::string format(const Record &record)
The standard line for a record, e.g. "[12.340s #1234] warn: message".
rz::Log::info
static void info(std::format_string< Args... > format, Args &&... args)
Definition
Log.hpp:43
rz::Log::toStdout
static void toStdout(const Record &record)
The default output: prints format(record) to stdout.
rz::Log::minimumLevel
static Level minimumLevel() noexcept
rz::Log::error
static void error(std::format_string< Args... > format, Args &&... args)
Definition
Log.hpp:53
rz::Log::Output
std::function< void(const Record &)> Output
Definition
Log.hpp:35
rz::Log::setOutput
static void setOutput(Output output)
Where records go. Defaults to toStdout; pass [](const Log::Record&) {} to discard.
rz::Log::Level
Level
Definition
Log.hpp:26
rz::Log::Level::Info
@ Info
Definition
Log.hpp:26
rz::Log::Level::Warn
@ Warn
Definition
Log.hpp:26
rz::Log::Level::Error
@ Error
Definition
Log.hpp:26
rz::Log::Level::Debug
@ Debug
Definition
Log.hpp:26
rz::Log::warn
static void warn(std::format_string< Args... > format, Args &&... args)
Definition
Log.hpp:48
rz::Time
au::QuantityPointD< au::Seconds > Time
Definition
Units.hpp:17
rz
Definition
DriverControl.hpp:11
rz::Log::Record
Definition
Log.hpp:28
rz::Log::Record::time
Time time
start of the tick it was logged in (0 before the runtime exists)
Definition
Log.hpp:30
rz::Log::Record::level
Level level
Definition
Log.hpp:29
rz::Log::Record::message
std::string_view message
Definition
Log.hpp:32
rz::Log::Record::tick
std::uint64_t tick
Runtime::tickCount() when it was logged (0 before the first tick)
Definition
Log.hpp:31
RaidZeroLib
api
Logging
Log.hpp
Generated by
1.18.0