Rerun C++ SDK
Loading...
Searching...
No Matches
log_sink.hpp
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <string_view>
6#include <utility>
7#include <vector>
8
9struct rr_log_sink;
10
11namespace rerun {
12 /// What happens when a client connects to a gRPC server.
13 enum class PlaybackBehavior {
14 /// Start by playing back all old data, then send data that arrived during playback.
16
17 /// Prioritize newly arriving messages, then replay history from newest to oldest.
19 };
20
21 struct LogSink;
22
23 /// Log sink which streams messages to an existing Rerun gRPC server.
24 ///
25 /// This is a gRPC client: it connects to a server but does not host one.
26 /// Use `GrpcServerSink` to host a server that SDKs and Viewers can connect to.
27 ///
28 /// The behavior of this sink is the same as the one set by `RecordingStream::connect_grpc`.
29 struct GrpcSink {
30 /// A Rerun gRPC URL.
31 ///
32 /// The scheme must be one of `rerun://`, `rerun+http://`, or `rerun+https://`,
33 /// and the pathname must be `/proxy`.
34 ///
35 /// The default is `rerun+http://127.0.0.1:9876/proxy`.
36 std::string_view url = "rerun+http://127.0.0.1:9876/proxy";
37
38 /// How long a flush waits for the connection to be established.
39 ///
40 /// If the sink has not connected by then, the flush fails, and dropping the sink discards
41 /// the data that has not been sent.
42 /// Must be finite and non-negative.
43 std::chrono::duration<float> flush_timeout = std::chrono::seconds(5);
44
45 inline operator LogSink() const;
46 };
47
48 /// Log sink which hosts a Rerun gRPC server.
49 ///
50 /// This is a gRPC server: SDKs and Viewers connect to it.
51 /// Use `GrpcSink` to connect as a client to an existing server.
52 ///
53 /// `RecordingStream::set_sinks` copies this configuration into a native sink.
54 /// Destroying this descriptor has no effect on the server.
55 /// Replacing the sinks or destroying the recording shuts the server down.
57 std::string_view bind_ip = "0.0.0.0";
58 uint16_t port = 9876;
59 std::string_view server_memory_limit = "1GiB";
61 std::vector<std::string_view> cors_allow_origins;
62
63 GrpcServerSink() = default;
64
66 std::string_view bind_ip_, uint16_t port_ = 9876,
67 std::string_view server_memory_limit_ = "1GiB",
69 std::vector<std::string_view> cors_allow_origins_ = {}
70 )
71 : bind_ip(bind_ip_),
72 port(port_),
73 server_memory_limit(server_memory_limit_),
74 playback_behavior(playback_behavior_),
75 cors_allow_origins(std::move(cors_allow_origins_)) {}
76
77 inline operator LogSink() const;
78 };
79
80 /// Log sink which writes messages to a file.
81 struct FileSink {
82 /// Path to the output file.
83 std::string_view path;
84
85 inline operator LogSink() const;
86 };
87
88 /// A sink for log messages.
89 ///
90 /// See specific log sink types for more information:
91 /// * `GrpcSink`
92 /// * `GrpcServerSink`
93 /// * `FileSink`
94 struct LogSink {
95 enum class Kind {
96 Grpc = 0,
97 File = 1,
98 GrpcServer = 2,
99 };
100
101 Kind kind;
102
103 union {
104 GrpcSink grpc;
105 FileSink file;
106
107 /// Borrowed only during `RecordingStream::set_sinks`.
108 ///
109 /// `GrpcServerSink` contains a non-trivial `std::vector`, so storing it directly in
110 /// this tagged union would require custom construction and destruction.
111 /// The C bridge copies every field and does not retain this pointer.
113 };
114 };
115
116 inline GrpcSink::operator LogSink() const {
117 LogSink sink{};
118 sink.kind = LogSink::Kind::Grpc;
119 sink.grpc = *this;
120 return sink;
121 }
122
123 inline FileSink::operator LogSink() const {
124 LogSink sink{};
125 sink.kind = LogSink::Kind::File;
126 sink.file = *this;
127 return sink;
128 }
129
130 inline GrpcServerSink::operator LogSink() const {
131 LogSink sink{};
132 sink.kind = LogSink::Kind::GrpcServer;
133 sink.grpc_server = this;
134 return sink;
135 }
136
137 namespace detail {
138 rr_log_sink to_rr_log_sink(LogSink sink);
139 }
140} // namespace rerun
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
PlaybackBehavior
What happens when a client connects to a gRPC server.
Definition log_sink.hpp:13
@ OldestFirst
Start by playing back all old data, then send data that arrived during playback.
@ NewestFirst
Prioritize newly arriving messages, then replay history from newest to oldest.
Log sink which writes messages to a file.
Definition log_sink.hpp:81
std::string_view path
Path to the output file.
Definition log_sink.hpp:83
Log sink which hosts a Rerun gRPC server.
Definition log_sink.hpp:56
Log sink which streams messages to an existing Rerun gRPC server.
Definition log_sink.hpp:29
std::string_view url
A Rerun gRPC URL.
Definition log_sink.hpp:36
std::chrono::duration< float > flush_timeout
How long a flush waits for the connection to be established.
Definition log_sink.hpp:43
A sink for log messages.
Definition log_sink.hpp:94
const GrpcServerSink * grpc_server
Borrowed only during RecordingStream::set_sinks.
Definition log_sink.hpp:112