Skip to content

Commit 0482560

Browse files
remove spdlog as dep
1 parent dd5e5d8 commit 0482560

11 files changed

Lines changed: 130 additions & 175 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ else()
4545
message(FATAL_ERROR "Could not find a LiveKit core target (expected LiveKit::livekit or livekit).")
4646
endif()
4747

48-
if(DEFINED _SPDLOG_ACTIVE_LEVEL AND NOT "${_SPDLOG_ACTIVE_LEVEL}" STREQUAL "")
49-
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${_SPDLOG_ACTIVE_LEVEL})
50-
else()
51-
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO)
52-
endif()
53-
5448
set(LIVEKIT_DATA_DIR "")
5549
if(DEFINED LIVEKIT_ROOT_DIR AND EXISTS "${LIVEKIT_ROOT_DIR}/data")
5650
set(LIVEKIT_DATA_DIR "${LIVEKIT_ROOT_DIR}/data")

hello_livekit_receiver/main.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <chrono>
3131
#include <csignal>
3232
#include <cstdlib>
33+
#include <iostream>
3334
#include <thread>
3435

3536
using namespace livekit;
@@ -58,10 +59,7 @@ int main(int argc, char *argv[]) {
5859
}
5960

6061
if (url.empty() || receiver_token.empty() || sender_identity.empty()) {
61-
LK_LOG_ERROR("Usage: HelloLivekitReceiver <ws-url> <receiver-token> "
62-
"<sender-identity>\n"
63-
" or set LIVEKIT_URL, LIVEKIT_RECEIVER_TOKEN, "
64-
"LIVEKIT_SENDER_IDENTITY");
62+
std::cerr << "[error] Usage: HelloLivekitReceiver <ws-url> <receiver-token> <sender-identity>\n or set LIVEKIT_URL, LIVEKIT_RECEIVER_TOKEN, LIVEKIT_SENDER_IDENTITY\n";
6563
return 1;
6664
}
6765

@@ -78,17 +76,15 @@ int main(int argc, char *argv[]) {
7876
options.dynacast = false;
7977

8078
if (!room->Connect(url, receiver_token, options)) {
81-
LK_LOG_ERROR("[receiver] Failed to connect");
79+
std::cerr << "[error] [receiver] Failed to connect\n";
8280
livekit::shutdown();
8381
return 1;
8482
}
8583

8684
LocalParticipant *lp = room->localParticipant();
8785
assert(lp);
8886

89-
LK_LOG_INFO("[receiver] Connected as identity='{}' room='{}'; subscribing "
90-
"to sender identity='{}'",
91-
lp->identity(), room->room_info().name, sender_identity);
87+
std::cout << "[info] [receiver] Connected as identity='" << lp->identity() << "' room='" << room->room_info().name << "'; subscribing to sender identity='" << sender_identity << "'\n";
9288

9389
int video_frame_count = 0;
9490
room->setOnVideoFrameCallback(
@@ -98,8 +94,7 @@ int main(int argc, char *argv[]) {
9894
std::chrono::duration<double, std::milli>(timestamp_us).count();
9995
const int n = video_frame_count++;
10096
if (n % 10 == 0) {
101-
LK_LOG_INFO("[receiver] Video frame #{} {}x{} ts_ms={}", n,
102-
frame.width(), frame.height(), ts_ms);
97+
std::cout << "[info] [receiver] Video frame #" << n << " " << frame.width() << "x" << frame.height() << " ts_ms=" << ts_ms << "\n";
10398
}
10499
});
105100

@@ -110,19 +105,17 @@ int main(int argc, char *argv[]) {
110105
std::optional<std::uint64_t> user_ts) {
111106
const int n = data_frame_count++;
112107
if (n % 10 == 0) {
113-
LK_LOG_INFO("[receiver] Data frame #{}", n);
108+
std::cout << "[info] [receiver] Data frame #" << n << "\n";
114109
}
115110
});
116111

117-
LK_LOG_INFO("[receiver] Listening for video track '{}' + data track '{}'; "
118-
"Ctrl-C to exit",
119-
kVideoTrackName, kDataTrackName);
112+
std::cout << "[info] [receiver] Listening for video track '" << kVideoTrackName << "' + data track '" << kDataTrackName << "'; Ctrl-C to exit\n";
120113

121114
while (g_running.load()) {
122115
std::this_thread::sleep_for(std::chrono::milliseconds(50));
123116
}
124117

125-
LK_LOG_INFO("[receiver] Shutting down");
118+
std::cout << "[info] [receiver] Shutting down\n";
126119
room.reset();
127120

128121
livekit::shutdown();

hello_livekit_sender/main.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <iomanip>
3333
#include <sstream>
3434
#include <thread>
35+
#include <iostream>
3536

3637
using namespace livekit;
3738

@@ -59,8 +60,7 @@ int main(int argc, char *argv[]) {
5960
}
6061

6162
if (url.empty() || sender_token.empty()) {
62-
LK_LOG_ERROR("Usage: HelloLivekitSender <ws-url> <sender-token>\n"
63-
" or set LIVEKIT_URL, LIVEKIT_SENDER_TOKEN");
63+
std::cerr << "[error] Usage: HelloLivekitSender <ws-url> <sender-token>\n or set LIVEKIT_URL, LIVEKIT_SENDER_TOKEN\n";
6464
return 1;
6565
}
6666

@@ -77,17 +77,15 @@ int main(int argc, char *argv[]) {
7777
options.dynacast = false;
7878

7979
if (!room->Connect(url, sender_token, options)) {
80-
LK_LOG_ERROR("[sender] Failed to connect");
80+
std::cerr << "[error] [sender] Failed to connect\n";
8181
livekit::shutdown();
8282
return 1;
8383
}
8484

8585
LocalParticipant *lp = room->localParticipant();
8686
assert(lp);
8787

88-
LK_LOG_INFO("[sender] Connected as identity='{}' room='{}' — pass this "
89-
"identity to HelloLivekitReceiver",
90-
lp->identity(), room->room_info().name);
88+
std::cout << "[info] [sender] Connected as identity='" << lp->identity() << "' room='" << room->room_info().name << "' — pass this identity to HelloLivekitReceiver\n";
9189

9290
auto video_source = std::make_shared<VideoSource>(kWidth, kHeight);
9391

@@ -97,8 +95,7 @@ int main(int argc, char *argv[]) {
9795
auto publish_result = lp->publishDataTrack(kDataTrackName);
9896
if (!publish_result) {
9997
const auto &error = publish_result.error();
100-
LK_LOG_ERROR("Failed to publish data track: code={} message={}",
101-
static_cast<std::uint32_t>(error.code), error.message);
98+
std::cerr << "[error] Failed to publish data track: code=" << static_cast<std::uint32_t>(error.code) << " message=" << error.message << "\n";
10299
room.reset();
103100
livekit::shutdown();
104101
return 1;
@@ -108,9 +105,7 @@ int main(int argc, char *argv[]) {
108105
const auto t0 = std::chrono::steady_clock::now();
109106
std::uint64_t count = 0;
110107

111-
LK_LOG_INFO(
112-
"[sender] Publishing synthetic video + data on '{}'; Ctrl-C to exit",
113-
kDataTrackName);
108+
std::cout << "[info] [sender] Publishing synthetic video + data on '" << kDataTrackName << "'; Ctrl-C to exit\n";
114109

115110
while (g_running.load()) {
116111
VideoFrame vf = VideoFrame::create(kWidth, kHeight, VideoBufferType::RGBA);
@@ -126,15 +121,14 @@ int main(int argc, char *argv[]) {
126121
data_track->tryPush(std::vector<std::uint8_t>(msg.begin(), msg.end()));
127122
if (!push_result) {
128123
const auto &error = push_result.error();
129-
LK_LOG_WARN("Failed to push data frame: code={} message={}",
130-
static_cast<std::uint32_t>(error.code), error.message);
124+
std::cerr << "[warn] Failed to push data frame: code=" << static_cast<std::uint32_t>(error.code) << " message=" << error.message << "\n";
131125
}
132126

133127
++count;
134128
std::this_thread::sleep_for(std::chrono::milliseconds(100));
135129
}
136130

137-
LK_LOG_INFO("[sender] Disconnecting");
131+
std::cout << "[info] [sender] Disconnecting\n";
138132
room.reset();
139133

140134
livekit::shutdown();

logging_levels_basic_usage/main.cpp

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,26 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// @file main.cpp
17+
/// @file basic_usage.cpp
1818
/// @brief Demonstrates LiveKit SDK log-level control and custom log callbacks.
1919
///
20-
/// Logging has two tiers of filtering:
20+
/// The SDK internally uses spdlog for its own logging. Client applications
21+
/// control SDK log output through two public APIs:
2122
///
22-
/// 1. **Compile-time** (LIVEKIT_LOG_LEVEL, set via CMake):
23-
/// Calls below this level are stripped from the binary entirely.
24-
/// Default is TRACE (nothing stripped). For a lean release build:
25-
/// cmake -DLIVEKIT_LOG_LEVEL=WARN ...
26-
///
27-
/// 2. **Runtime** (setLogLevel()):
28-
/// Among the levels that survived compilation, setLogLevel() controls
29-
/// which ones actually produce output. This is what this example demos.
23+
/// - livekit::setLogLevel() — filter SDK messages by severity.
24+
/// - livekit::setLogCallback() — redirect SDK log output to your own handler.
3025
///
3126
/// Usage:
32-
/// LoggingLevels [trace|debug|info|warn|error|critical|off]
27+
/// LoggingLevelsBasicUsage [trace|debug|info|warn|error|critical|off]
3328
///
34-
/// If no argument is given, the example cycles through every level so you can
35-
/// see which messages are filtered at each setting.
29+
/// If no argument is given, the example cycles through every level and then
30+
/// demonstrates the custom callback API.
3631

3732
#include "livekit/livekit.h"
38-
#include "livekit/lk_log.h"
3933

4034
#include <cstring>
4135
#include <iostream>
4236
#include <string>
43-
#include <thread>
4437

4538
namespace {
4639

@@ -84,16 +77,6 @@ livekit::LogLevel parseLevel(const char *arg) {
8477
return livekit::LogLevel::Info;
8578
}
8679

87-
/// Emit one message at every severity level using the LK_LOG_* macros.
88-
void emitAllLevels() {
89-
LK_LOG_TRACE("This is a TRACE message (very verbose internals)");
90-
LK_LOG_DEBUG("This is a DEBUG message (diagnostic detail)");
91-
LK_LOG_INFO("This is an INFO message (normal operation)");
92-
LK_LOG_WARN("This is a WARN message (something unexpected)");
93-
LK_LOG_ERROR("This is an ERROR message (something failed)");
94-
LK_LOG_CRITICAL("This is a CRITICAL message (unrecoverable)");
95-
}
96-
9780
/// Demonstrate cycling through every log level.
9881
void runLevelCycleDemo() {
9982
const livekit::LogLevel levels[] = {
@@ -108,7 +91,8 @@ void runLevelCycleDemo() {
10891
<< " Setting log level to: " << levelName(level) << "\n"
10992
<< "========================================\n";
11093
livekit::setLogLevel(level);
111-
emitAllLevels();
94+
std::cout << " Current SDK log level: "
95+
<< levelName(livekit::getLogLevel()) << "\n";
11296
}
11397
}
11498

@@ -120,40 +104,41 @@ void runCallbackDemo() {
120104

121105
livekit::setLogLevel(livekit::LogLevel::Trace);
122106

123-
// Install a user-defined callback that captures all log output.
124-
// In a real ROS2 node you would replace this with RCLCPP_* macros.
125107
livekit::setLogCallback([](livekit::LogLevel level,
126108
const std::string &logger_name,
127109
const std::string &message) {
128110
std::cout << "[CALLBACK] [" << levelName(level) << "] [" << logger_name
129111
<< "] " << message << "\n";
130112
});
131113

132-
LK_LOG_INFO("This message is routed through the custom callback");
133-
LK_LOG_WARN("Warnings also go through the callback");
134-
LK_LOG_ERROR("Errors too -- the callback sees everything >= the level");
114+
std::cout << "Installed custom callback. SDK log messages will now be "
115+
"routed through it.\n";
135116

136117
// Restore default stderr sink by passing an empty callback.
137118
livekit::setLogCallback(nullptr);
138119

139-
std::cout << "\n(Restored default stderr sink)\n";
140-
LK_LOG_INFO("This message goes to stderr again (default sink)");
120+
std::cout << "(Restored default stderr sink)\n";
141121
}
142122

143123
} // namespace
144124

145125
int main(int argc, char *argv[]) {
146-
// Initialize the LiveKit SDK (creates the spdlog logger).
147126
livekit::initialize();
148127

149128
if (argc > 1) {
150-
// Single-level mode: set the requested level and emit all messages.
129+
if (std::strcmp(argv[1], "-h") == 0 ||
130+
std::strcmp(argv[1], "--help") == 0) {
131+
std::cout << "Usage: LoggingLevelsBasicUsage "
132+
"[trace|debug|info|warn|error|critical|off]\n";
133+
livekit::shutdown();
134+
return 0;
135+
}
151136
livekit::LogLevel level = parseLevel(argv[1]);
152137
std::cout << "Setting log level to: " << levelName(level) << "\n\n";
153138
livekit::setLogLevel(level);
154-
emitAllLevels();
139+
std::cout << "Current SDK log level: "
140+
<< levelName(livekit::getLogLevel()) << "\n";
155141
} else {
156-
// Full demo: cycle through levels, then show the callback API.
157142
runLevelCycleDemo();
158143
runCallbackDemo();
159144
}

0 commit comments

Comments
 (0)