Skip to content

Commit 41f7bcf

Browse files
authored
core : Switch to spdlog for logging (#96)
* Add spdlog dependency * multibody/RobotScene : move `invalid_enum()` back to cpp file * [cmake] add spdlog dependency * Use spdlog instead of `SDL_Log(...)` Cleanup unused include of <SDL3/SDL_log.h> * Format RobotSpec in spdlog * runtime/main.cpp : process SPDLOG_LEVEL envar and set pattern * core/Texture : add getter for name * Remove deprecated header `core/Renderer.h` * Some logging adjustments * Update README * fixup
1 parent 975c939 commit 41f7bcf

34 files changed

+293
-137
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
### Changed
2525

26+
- multibody/RobotScene : move `invalid_enum()` back to cpp file
2627
- multibody/RobotScene : always render to G-buffer normal map
2728
- core: move header `LoadCoalGeometries.h` and its functions to library core
2829
- multibody/Visualizer : rename a data member in Config
@@ -34,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3435

3536
### Removed
3637

38+
- Remove deprecated header `candlewick/core/Renderer.h`
3739
- Remove deprecated header `candlewick/multibody/LoadCoalPrimitives.h`
3840

3941
## [0.9.0] - 2025-08-12

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,7 @@ ADD_PROJECT_DEPENDENCY(coal REQUIRED PKG_CONFIG_REQUIRES "coal >= 3.0.0")
9595
ADD_PROJECT_DEPENDENCY(nlohmann_json 3.11.3 REQUIRED)
9696
ADD_PROJECT_DEPENDENCY(EnTT REQUIRED)
9797
ADD_PROJECT_DEPENDENCY(magic_enum 0.9.7 CONFIG REQUIRED)
98-
if(BUILD_PINOCCHIO_VISUALIZER)
99-
ADD_PROJECT_DEPENDENCY(
100-
pinocchio
101-
REQUIRED
102-
PKG_CONFIG_REQUIRES "pinocchio >= 3.7.0"
103-
)
104-
endif()
98+
ADD_PROJECT_DEPENDENCY(spdlog 1.10 REQUIRED)
10599
ADD_PROJECT_DEPENDENCY(
106100
FFmpeg
107101
7.0.0
@@ -110,6 +104,14 @@ ADD_PROJECT_DEPENDENCY(
110104
avcodec
111105
swscale
112106
)
107+
if(BUILD_PINOCCHIO_VISUALIZER)
108+
ADD_PROJECT_DEPENDENCY(
109+
pinocchio
110+
REQUIRED
111+
PKG_CONFIG_REQUIRES "pinocchio >= 3.7.0"
112+
)
113+
endif()
114+
113115
set(CANDLEWICK_ASSETS_DIR ${PROJECT_SOURCE_DIR}/assets)
114116
set(CANDLEWICK_SHADER_SRC_DIR ${PROJECT_SOURCE_DIR}/shaders)
115117
set(

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ Candlewick depends mainly on:
9696
* [Eigen](https://gitlab.com/libeigen/eigen/) - Linear algebra
9797
* [Coal](https://github.com/coal-library/coal) - Collision detection, geometry primitives
9898
* [magic_enum](https://github.com/Neargye/magic_enum) - Enum reflection utilities
99+
* [spdlog](https://github.com/gabime/spdlog/) - Logging
99100

100101
These dependencies can be installed from Conda as follows:
101102
```bash
102-
conda install -c conda-forge sdl3 eigen coal magic_enum assimp entt nlohmann_json
103+
conda install -c conda-forge sdl3 eigen coal magic_enum assimp entt nlohmann_json spdlog
103104
```
104105

105106
Additionally, candlewick depends on the following bundled dependencies:

examples/Ur5WithSystems.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void eventLoop(const RenderContext &renderer) {
118118
ImGui_ImplSDL3_ProcessEvent(&event);
119119
ImGuiIO &io = ImGui::GetIO();
120120
if (event.type == SDL_EVENT_QUIT) {
121-
SDL_Log("Application exit requested.");
121+
spdlog::info("Application exit requested.");
122122
quitRequested = true;
123123
break;
124124
}
@@ -202,11 +202,11 @@ static void addTeapotGeometry(pin::GeometryModel &geom_model) {
202202

203203
static void screenshotButtonCallback(const RenderContext &renderer,
204204
media::TransferBufferPool &pool,
205-
const char *filename) {
205+
std::string_view filename) {
206206
const auto &device = renderer.device;
207207
CommandBuffer command_buffer{device};
208208

209-
SDL_Log("Saving screenshot at %s", filename);
209+
spdlog::info("Saving screenshot at {:s}", filename);
210210
media::saveTextureToFile(command_buffer, device, pool,
211211
renderer.resolvedColorTarget(),
212212
renderer.colorFormat(), wWidth, wHeight, filename);
@@ -319,7 +319,7 @@ int main(int argc, char **argv) {
319319
const size_t numRobotShapes =
320320
registry.view<const multibody::PinGeomObjComponent>().size();
321321
SDL_assert(numRobotShapes == geom_model.ngeoms);
322-
SDL_Log("Registered %zu robot geometry objects.", numRobotShapes);
322+
spdlog::info("Registered {:d} robot geometry objects.", numRobotShapes);
323323

324324
// DEBUG SYSTEM
325325

@@ -539,7 +539,7 @@ int main(int argc, char **argv) {
539539
}
540540
gui_system.render(command_buffer);
541541
} else {
542-
SDL_Log("Failed to acquire swapchain: %s", SDL_GetError());
542+
spdlog::info("Failed to acquire swapchain: {:s}", SDL_GetError());
543543
continue;
544544
}
545545

examples/Visualizer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <CLI/Formatter.hpp>
1010
#include <CLI/Config.hpp>
1111

12+
#include <spdlog/cfg/env.h>
13+
1214
using namespace candlewick::multibody;
1315
using candlewick::sdlSampleToValue;
1416
using pinocchio::visualizers::Vector3;
@@ -40,7 +42,7 @@ static void addBall(pin::GeometryModel &geom_model) {
4042
geom_model.addGeometryObject(object);
4143
}
4244

43-
int main(int argc, char **argv) {
45+
int main(int argc, char *argv[]) {
4446
CLI::App app{"Visualizer example"};
4547
argv = app.ensure_utf8(argv);
4648
std::array<Uint32, 2> window_dims{1920u, 1080u};
@@ -67,6 +69,9 @@ int main(int argc, char **argv) {
6769

6870
CLI11_PARSE(app, argc, argv);
6971

72+
spdlog::cfg::load_env_levels();
73+
spdlog::set_pattern(">>> [%T] [%^%l%$] %v");
74+
spdlog::info("Robot spec:\n{}", ur_robot_spec);
7075
pin::Model model;
7176
pin::GeometryModel geom_model;
7277
loadModels(ur_robot_spec, model, &geom_model, NULL);

examples/lib/Common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "Common.h"
66
#include <SDL3/SDL_init.h>
7-
#include <SDL3/SDL_log.h>
87

98
using namespace candlewick;
109

0 commit comments

Comments
 (0)