|
16 | 16 |
|
17 | 17 | #include <rcl/error_handling.h> |
18 | 18 | #include <rcl/rcl.h> |
| 19 | +#include <rcl_logging_interface/rcl_logging_interface.h> |
19 | 20 |
|
20 | 21 | #include <string> |
21 | 22 |
|
@@ -84,12 +85,33 @@ Napi::Value IsEnableFor(const Napi::CallbackInfo& info) { |
84 | 85 | return Napi::Boolean::New(env, enabled); |
85 | 86 | } |
86 | 87 |
|
| 88 | +Napi::Value GetLoggingDirectory(const Napi::CallbackInfo& info) { |
| 89 | + Napi::Env env = info.Env(); |
| 90 | + rcutils_allocator_t allocator = rcutils_get_default_allocator(); |
| 91 | + char* directory_path = nullptr; |
| 92 | + rcl_logging_ret_t ret = |
| 93 | + rcl_logging_get_logging_directory(allocator, &directory_path); |
| 94 | + |
| 95 | + if (ret != RCL_LOGGING_RET_OK) { |
| 96 | + Napi::Error::New(env, rcutils_get_error_string().str) |
| 97 | + .ThrowAsJavaScriptException(); |
| 98 | + rcutils_reset_error(); |
| 99 | + return env.Undefined(); |
| 100 | + } |
| 101 | + |
| 102 | + Napi::String result = Napi::String::New(env, directory_path); |
| 103 | + allocator.deallocate(directory_path, allocator.state); |
| 104 | + return result; |
| 105 | +} |
| 106 | + |
87 | 107 | Napi::Object InitLoggingBindings(Napi::Env env, Napi::Object exports) { |
88 | 108 | exports.Set("setLoggerLevel", Napi::Function::New(env, setLoggerLevel)); |
89 | 109 | exports.Set("getLoggerEffectiveLevel", |
90 | 110 | Napi::Function::New(env, GetLoggerEffectiveLevel)); |
91 | 111 | exports.Set("log", Napi::Function::New(env, Log)); |
92 | 112 | exports.Set("isEnableFor", Napi::Function::New(env, IsEnableFor)); |
| 113 | + exports.Set("getLoggingDirectory", |
| 114 | + Napi::Function::New(env, GetLoggingDirectory)); |
93 | 115 | return exports; |
94 | 116 | } |
95 | 117 |
|
|
0 commit comments