Skip to content

Commit 249e6bd

Browse files
author
Minggang Wang
committed
Remove spdlog as dependency
Currently, we depend on spdlog to log for C++ codes when debug build. The reason is that there was no logging util in the early stage. This patch uses the logging util from rcutils to replace spdlog. Thus, we can remove the spdlog as a dependency and reduce the size of npm package also. Fix #634
1 parent 15193b0 commit 249e6bd

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ Open a terminal, and input:
5454
git clone https://github.com/RobotWebTools/rclnodejs.git
5555
```
5656

57-
then enter the folder `rclnodejs`, and get the submodule:
58-
59-
```bash
60-
git submodule update --init --recursive
61-
```
62-
6357
### Build Module
6458

6559
Before you build the module, you should make sure the ROS2 environments were loaded. You can check if the `AMENT_PREFIX_PATH` environment variable was set:

binding.gyp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'default_configuration': 'Release',
44
'configurations': {
55
'Debug': {
6-
'defines': ['SPDLOG_DEBUG_ON'],
6+
'defines': ['DEBUG_ON'],
77
},
88
}
99
},
@@ -22,7 +22,6 @@
2222
],
2323
'include_dirs': [
2424
'.',
25-
'src/third_party/spdlog/include/',
2625
"<!(node -e \"require('nan')\")",
2726
],
2827
'cflags!': [

src/addon.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414

1515
#include <nan.h>
1616

17+
#include "macros.hpp"
1718
#include "rcl_action_bindings.hpp"
1819
#include "rcl_bindings.hpp"
1920
#include "rcl_handle.hpp"
21+
#include "rcutils/logging.h"
22+
#include "rcutils/macros.h"
2023
#include "shadow_node.hpp"
21-
#include "spdlog/spdlog.h"
22-
23-
#ifdef SPDLOG_DEBUG_ON
24-
#include "spdlog/sinks/stdout_color_sinks.h"
25-
#endif
2624

2725
void InitModule(v8::Local<v8::Object> exports) {
2826
v8::Local<v8::Context> context = exports->GetIsolate()->GetCurrentContext();
@@ -51,9 +49,10 @@ void InitModule(v8::Local<v8::Object> exports) {
5149
rclnodejs::ShadowNode::Init(exports);
5250
rclnodejs::RclHandle::Init(exports);
5351

54-
#ifdef SPDLOG_DEBUG_ON
55-
auto console = spdlog::stdout_color_mt("rclnodejs");
56-
console->set_level(spdlog::level::debug);
52+
#ifdef DEBUG_ON
53+
int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
54+
RCUTILS_LOG_SEVERITY_DEBUG);
55+
RCUTILS_UNUSED(result);
5756
#endif
5857
}
5958

src/executor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <string>
2121

2222
#include "handle_manager.hpp"
23+
#include "macros.hpp"
2324
#include "rcl_bindings.hpp"
24-
#include "spdlog/spdlog.h"
2525

2626
#ifdef WIN32
2727
#define UNUSED
@@ -106,7 +106,7 @@ void Executor::Stop() {
106106
});
107107
while (!handle_closed) uv_run(uv_default_loop(), UV_RUN_ONCE);
108108

109-
SPDLOG_DEBUG(spdlog::get("rclnodejs"), "Background thread stopped.");
109+
RCLNODEJS_DEBUG("Background thread stopped.");
110110
}
111111
}
112112
}
@@ -117,7 +117,7 @@ void Executor::DoWork(uv_async_t* handle) {
117117
}
118118

119119
void Executor::Run(void* arg) {
120-
SPDLOG_DEBUG(spdlog::get("rclnodejs"), "Background thread started.");
120+
RCLNODEJS_DEBUG("Background thread started.");
121121
Executor* executor = reinterpret_cast<Executor*>(arg);
122122
HandleManager* handle_manager = executor->handle_manager_;
123123

src/handle_manager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <vector>
2020

21-
#include "spdlog/spdlog.h"
21+
#include "macros.hpp"
2222

2323
namespace rclnodejs {
2424

@@ -81,11 +81,11 @@ void HandleManager::CollectHandles(const v8::Local<v8::Object> node) {
8181
is_synchronizing_.store(false);
8282
uv_sem_post(&sem_);
8383

84-
SPDLOG_DEBUG(spdlog::get("rclnodejs"),
85-
"Add {0:d} timers, {1:d} subscriptions, {2:d} clients, " +
86-
"{3:d} services, {4:d} guards.",
87-
timers_.size(), subscriptions_.size(), clients_.size(),
88-
services_.size(), guard_conditions_.size());
84+
RCLNODEJS_DEBUG(
85+
"Add %lu timers, %lu subscriptions, %lu clients, %lu services, %lu "
86+
"guards.",
87+
timers_.size(), subscriptions_.size(), clients_.size(), services_.size(),
88+
guard_conditions_.size());
8989
}
9090

9191
bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {

src/macros.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef RCLNODEJS_MARCOS_HPP_
1616
#define RCLNODEJS_MARCOS_HPP_
1717

18+
#include "rcutils/logging_macros.h"
19+
1820
#define CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE(op, lhs, rhs, message) \
1921
{ \
2022
if (lhs op rhs) { \
@@ -31,4 +33,15 @@
3133
#define THROW_ERROR_IF_EQUAL(lhs, rhs, message) \
3234
CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE(==, lhs, rhs, message)
3335

36+
#define PACKAGE_NAME "rclnodejs"
37+
38+
#ifdef DEBUG_ON
39+
#define RCLNODEJS_DEBUG(...) \
40+
RCUTILS_LOG_COND_NAMED( \
41+
RCUTILS_LOG_SEVERITY_DEBUG, RCUTILS_LOG_CONDITION_EMPTY, \
42+
RCUTILS_LOG_CONDITION_EMPTY, PACKAGE_NAME, __VA_ARGS__)
43+
#else
44+
#define RCLNODEJS_DEBUG(...)
45+
#endif
46+
3447
#endif

src/third_party/spdlog

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)