diff --git a/lib/client.js b/lib/client.js index 67e331b6..50b7b2e6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -157,6 +157,14 @@ class Client extends Entity { introspectionState ); } + + /** + * Get the logger name for this client. + * @returns {string} The logger name for this client. + */ + get loggerName() { + return rclnodejs.getNodeLoggerName(this._nodeHandle); + } } module.exports = Client; diff --git a/lib/publisher.js b/lib/publisher.js index b778b8b7..b4ae66f8 100644 --- a/lib/publisher.js +++ b/lib/publisher.js @@ -26,6 +26,7 @@ const Entity = require('./entity.js'); class Publisher extends Entity { constructor(handle, typeClass, topic, options, node, eventCallbacks) { super(handle, typeClass, options); + this._node = node; if (node && eventCallbacks) { this._events = eventCallbacks.createEventHandlers(this.handle); node._events.push(...this._events); @@ -126,6 +127,14 @@ class Publisher extends Entity { set events(events) { this._events = events; } + + /** + * Get the logger name for this publisher. + * @returns {string} The logger name for this publisher. + */ + get loggerName() { + return rclnodejs.getNodeLoggerName(this._node.handle); + } } module.exports = Publisher; diff --git a/lib/service.js b/lib/service.js index 10aa0c9b..bc70fc0c 100644 --- a/lib/service.js +++ b/lib/service.js @@ -149,6 +149,14 @@ class Service extends Entity { getOptions() { return rclnodejs.getOptions(this._handle); } + + /** + * Get the logger name for this service. + * @returns {string} The logger name for this service. + */ + get loggerName() { + return rclnodejs.getNodeLoggerName(this._nodeHandle); + } } module.exports = Service; diff --git a/lib/subscription.js b/lib/subscription.js index 5f07a58f..c73af1d3 100644 --- a/lib/subscription.js +++ b/lib/subscription.js @@ -42,6 +42,7 @@ class Subscription extends Entity { this._topic = topic; this._callback = callback; this._isRaw = options.isRaw || false; + this._node = node; if (node && eventCallbacks) { this._events = eventCallbacks.createEventHandlers(this.handle); @@ -168,6 +169,14 @@ class Subscription extends Entity { set events(events) { this._events = events; } + + /** + * Get the logger name for this subscription. + * @returns {string} The logger name for this subscription. + */ + get loggerName() { + return rclnodejs.getNodeLoggerName(this._node.handle); + } } module.exports = Subscription; diff --git a/test/test-publisher.js b/test/test-publisher.js index 1c65effb..5acbb50f 100644 --- a/test/test-publisher.js +++ b/test/test-publisher.js @@ -52,6 +52,13 @@ describe('rclnodejs publisher test suite', function () { assert.strictEqual(publisher.subscriptionCount, 1); }); + it('Test loggerName', function () { + const node = rclnodejs.createNode('publisher_node'); + const String = 'std_msgs/msg/String'; + const publisher = node.createPublisher(String, 'topic'); + assert.strictEqual(typeof publisher.loggerName, 'string'); + }); + it('Wait for all acked', function () { const node = rclnodejs.createNode('publisher_node'); const String = 'std_msgs/msg/String'; diff --git a/test/test-service.js b/test/test-service.js index 09c7d9ff..03dd5df9 100644 --- a/test/test-service.js +++ b/test/test-service.js @@ -93,4 +93,22 @@ describe('Test service class', function () { ); node.destroy(); }); + + it('Test loggerName', function () { + const node = rclnodejs.createNode('test_node'); + const AddTwoInts = 'example_interfaces/srv/AddTwoInts'; + const service = node.createService( + AddTwoInts, + 'add_two_ints', + { qos: rclnodejs.QoS.profileSystemDefault }, + (request, response) => { + let result = response.template; + result.sum = request.a + request.b; + } + ); + const client = node.createClient(AddTwoInts, 'single_ps_channel2'); + + assert.strictEqual(typeof service.loggerName, 'string'); + assert.strictEqual(typeof client.loggerName, 'string'); + }); }); diff --git a/test/test-subscription.js b/test/test-subscription.js index 3a2afad8..ac12d015 100644 --- a/test/test-subscription.js +++ b/test/test-subscription.js @@ -35,4 +35,11 @@ describe('rclnodejs subscription test suite', function () { const subscription = node.createSubscription(String, 'topic', (msg) => {}); assert.strictEqual(subscription.publisherCount, 1); }); + + it('Test loggerName', function () { + const node = rclnodejs.createNode('publisher_node'); + const String = 'std_msgs/msg/String'; + const subscription = node.createSubscription(String, 'topic', (msg) => {}); + assert.strictEqual(typeof subscription.loggerName, 'string'); + }); }); diff --git a/test/types/index.test-d.ts b/test/types/index.test-d.ts index 57d26924..b2e0a408 100644 --- a/test/types/index.test-d.ts +++ b/test/types/index.test-d.ts @@ -163,6 +163,7 @@ expectType(publisher.waitForAllAcked(BigInt(1000))); node.createPublisher(TYPE_CLASS, TOPIC, publisher.options, (event: object) => { const receivedEvent = event; }); +expectType(publisher.loggerName); // ---- LifecyclePublisher ---- const lifecyclePublisher = lifecycleNode.createLifecyclePublisher( @@ -221,6 +222,7 @@ expectType(subscription.isDestroyed()); expectType(subscription.setContentFilter(contentFilter)); expectType(subscription.clearContentFilter()); expectType(subscription.hasContentFilter()); +expectType(subscription.loggerName); // ---- Service ---- const service = node.createService( @@ -241,6 +243,7 @@ expectType( ); expectType(service.isDestroyed()); expectType(service.getOptions()); +expectType(service.loggerName); // ---- Client ---- const client = node.createClient( @@ -259,6 +262,7 @@ expectType( ) ); expectType(client.isDestroyed()); +expectType(client.loggerName); // ---- Timer ---- const timerCallback = () => {}; diff --git a/types/client.d.ts b/types/client.d.ts index 8c9c64e0..f884be2b 100644 --- a/types/client.d.ts +++ b/types/client.d.ts @@ -52,6 +52,11 @@ declare module 'rclnodejs' { serviceEventPubQOS: QoS, introspectionState: ServiceIntrospectionStates ): void; + + /** + * Get the logger name for this client. + */ + readonly loggerName: string; } namespace Client { diff --git a/types/publisher.d.ts b/types/publisher.d.ts index df15ce3e..160d403b 100644 --- a/types/publisher.d.ts +++ b/types/publisher.d.ts @@ -37,5 +37,10 @@ declare module 'rclnodejs' { * @return {boolean} `true` if all published message data is acknowledged before the timeout, otherwise `false`. */ waitForAllAcked(timeout: bigint): boolean; + + /** + * Get the logger name for this publisher. + */ + readonly loggerName: string; } } diff --git a/types/service.d.ts b/types/service.d.ts index 4ee2d946..75b9cc92 100644 --- a/types/service.d.ts +++ b/types/service.d.ts @@ -94,5 +94,10 @@ declare module 'rclnodejs' { * @return The options of this service. */ getOptions(): object; + + /** + * Get the logger name for this service. + */ + readonly loggerName: string; } } diff --git a/types/subscription.d.ts b/types/subscription.d.ts index 5e28c37a..77021c35 100644 --- a/types/subscription.d.ts +++ b/types/subscription.d.ts @@ -72,5 +72,10 @@ declare module 'rclnodejs' { * @returns The number of publishers */ publisherCount(): number; + + /** + * Get the logger name for this subscription. + */ + readonly loggerName: string; } }