Skip to content

Commit

Permalink
Break log function execution ASAP if configured severity is too high (#…
Browse files Browse the repository at this point in the history
…776)

* Break log function execution ASAP if configure severity is too high

Signed-off-by: ksuszka <ksuszka@autonomous-systems.pl>

* Move log level severity check to the very beginning of log method

Signed-off-by: ksuszka <ksuszka@autonomous-systems.pl>

Co-authored-by: ksuszka <ksuszka@autonomous-systems.pl>
  • Loading branch information
ksuszka and ksuszka authored Apr 28, 2021
1 parent 0763473 commit b3cd14d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rclpy/rclpy/impl/rcutils_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ def log(self, message, severity, **kwargs):
:raises: ValueError on invalid parameters values.
:rtype: bool
"""
# Gather context info and check filters only if the severity is appropriate.
if not self.is_enabled_for(severity):
return False

from rclpy.logging import LoggingSeverity
severity = LoggingSeverity(severity)

Expand Down Expand Up @@ -306,10 +310,6 @@ def log(self, message, severity, **kwargs):
raise ValueError(
'Logging filter parameters cannot be changed between calls.')

# Only check filters if the severity is appropriate.
if not self.is_enabled_for(severity):
return False

# Check if any filter determines the message shouldn't be processed.
# Note(dhood): even if a message doesn't get logged, a filter might still update its state
# as if it had been. This matches the behavior of the C logging macros provided by rcutils.
Expand Down

0 comments on commit b3cd14d

Please sign in to comment.