@@ -35,12 +35,12 @@ robotic manipulators.
35
35
[ boost] ( https://github.com/UniversalRobots/Universal_Robots_Client_Library/tree/boost ) branch
36
36
instead that requires the boost library.
37
37
For the C++17 features, please use those minimum compiler versions:
38
-
38
+
39
39
| Compiler | min. version |
40
40
| -----------| --------------|
41
41
| ** GCC** | 7 |
42
42
| ** Clang** | 7 |
43
-
43
+
44
44
45
45
## Build instructions
46
46
### Plain cmake
@@ -301,11 +301,87 @@ As this library was originally designed to be included into a ROS driver but als
301
301
standalone library, it uses custom logging macros instead of direct `printf` or `std::cout`
302
302
statements.
303
303
304
- These logging macros will either be translated into `printf` statements or logging commands of
305
- [`console_bridge`](https://github.com/ros/console_bridge) if `console_bridge` is found on the system
306
- during the cmake run. In this case, the define `ROS_BUILD` will be set. When built inside a catkin
307
- workspace, logging commands are automatically translated into ROS logging commands.
304
+ The macro based interface is by default using the [`DefaultLogHandler`](include/ur_client_library/default_log_handler.h)
305
+ to print the logging messages as `printf` statements. It is possible to define your own log handler
306
+ to change the behavior, [see create new log handler](#Create-new-log-handler) on how to.
307
+
308
+ ### Change logging level
309
+ Make sure to set the logging level in your application, as by default only messages of level
310
+ WARNING or higher will be printed. See below for an example:
311
+ ```c++
312
+ #include "ur_client_library/log.h"
313
+
314
+ int main(int argc, char* argv[])
315
+ {
316
+ urcl::setLogLevel(urcl::LogLevel::DEBUG);
317
+
318
+ URCL_LOG_DEBUG("Logging debug message");
319
+ return 0;
320
+ }
321
+ ```
322
+
323
+ ### Create new log handler
324
+ The logger comes with an interface [ ` LogHandler ` ] ( include/ur_client_library/log.h ) , which can be
325
+ used to implement your own log handler for messages logged with this library. This can be done by
326
+ inheriting from the ` LogHandler class ` .
327
+
328
+ If you want to create a new log handler in your application, you can use below example as
329
+ inspiration:
330
+
331
+ ``` c++
332
+ #include " ur_client_library/log.h"
333
+ #include < iostream>
334
+
335
+ class MyLogHandler : public urcl :: LogHandler
336
+ {
337
+ public:
338
+ MyLogHandler () = default;
339
+
340
+ void log(const char* file, int line, urcl::LogLevel loglevel, const char* log) override
341
+ {
342
+ switch (loglevel)
343
+ {
344
+ case urcl::LogLevel::INFO:
345
+ std::cout << "INFO " << file << " " << line << ": " << log << std::endl;
346
+ break;
347
+ case urcl::LogLevel::DEBUG:
348
+ std::cout << "DEBUG " << file << " " << line << ": " << log << std::endl;
349
+ break;
350
+ case urcl::LogLevel::WARN:
351
+ std::cout << "WARN " << file << " " << line << ": " << log << std::endl;
352
+ break;
353
+ case urcl::LogLevel::ERROR:
354
+ std::cout << "ERROR " << file << " " << line << ": " << log << std::endl;
355
+ break;
356
+ case urcl::LogLevel::FATAL:
357
+ std::cout << "ERROR " << file << " " << line << ": " << log << std::endl;
358
+ break;
359
+ default:
360
+ break;
361
+ }
362
+ }
363
+ };
364
+
365
+ int main (int argc, char* argv[ ] )
366
+ {
367
+ urcl::setLogLevel(urcl::LogLevel::DEBUG);
368
+ std::unique_ptr<MyLogHandler > log_handler(new MyLogHandler);
369
+ urcl::registerLogHandler(std::move(log_handler));
370
+
371
+ URCL_LOG_DEBUG("logging debug message");
372
+ URCL_LOG_INFO("logging info message");
373
+ return 0;
374
+ }
375
+ ```
376
+
377
+ ### Console_bridge
378
+ If [`console_bridge`](https://github.com/ros/console_bridge) is found on the system during the
379
+ cmake run, logging commands will be done by `console_bridge`. In this case, the define `ROS_BUILD`
380
+ will be set. When built inside a catkin workspace, logging commands are automatically translated
381
+ into ROS logging commands.
382
+
383
+ If you compile this library against `console_bridge`, make sure to set the logging level in your
384
+ application, as by default `console_bridge` will only print messages of level WARNING or higher.
385
+ See [`examples/primary_pipeline.cpp`](examples/primary_pipeline.cpp) as an example.
308
386
309
- Whenever you compile this library against `console_bridge`, make sure to set the logging level in
310
- your application, as by default `console_bridge` will only print messages of level WARNING or
311
- higher. See [`examples/primary_pipeline.cpp`](examples/primary_pipeline.cpp) as an example.
387
+ The ROS logger will be moved to the ROS driver in a future release.
0 commit comments