Skip to content

Commit e2f1628

Browse files
committed
Add logging details to README
1 parent 67a4a96 commit e2f1628

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,10 @@ following code:
9999
```python
100100
from py_trees_parser import BTParser
101101
import py_trees
102-
from rclpy import logging
103-
104-
logger = logging.get_logger('parser')
105-
logger.set_level(logging.LoggingSeverity.DEBUG)
106102

107103
# Parse the XML file and create the behavior tree:
108104
xml_file = "behavior_tree.xml"
109-
parser = BTParser(xml_file, logger)
105+
parser = BTParser(xml_file)
110106
behavior_tree = parser.parse()
111107
```
112108

@@ -222,4 +218,38 @@ and finally in subtree2
222218
<py_trees.composites.Sequence name="Cascading Arg Tutorial">
223219
<py_trees.behaviors.Success name="${baz}" />
224220
</py_trees.composites.Sequence>
225-
```
221+
```
222+
223+
### Logging
224+
225+
By default the parser uses `rclpy.logging` module to log messages. However, if this is not available
226+
it falls back to the python `logging` module. The user need not intervene to change the logger as the
227+
parser will determine which logger to use on its own.
228+
229+
#### Logging Level
230+
231+
If you would like to set the logging level you will need to know which logger is available. If you are
232+
using ROS2 then the logger will be `rclpy.logging` and the log level can be set in the following way
233+
234+
```python
235+
import rclpy
236+
237+
from py_trees_parser import BTParser
238+
239+
xml_file = "behavior_tree.xml"
240+
parser = BTParser(xml_file, log_level=rclpy.logging.LoggingSeverity.DEBUG)
241+
```
242+
243+
On the other hand if you are not using ROS2 then the log level can be set in the following way
244+
245+
```python
246+
import logging
247+
248+
from py_trees_parser import BTParser
249+
250+
xml_file = "behavior_tree.xml"
251+
parser = BTParser(xml_file, log_level=logging.DEBUG)
252+
```
253+
254+
- For details on ROS2 log levels see [here](https://docs.ros2.org/foxy/api/rclpy/api/logging.html).
255+
- For details on python log levels see [here](https://docs.python.org/3/library/logging.html#logging-levels)

0 commit comments

Comments
 (0)